how to alter database link name created from dblink? - postgresql

I have a connection created via dblink in Postgresql as follows:
SELECT dblink_connect('conn_db_link', 'server_target');
Here I used the name conn_db_link to represent the connection. Now I would like to change the name to something new. I have tried ALTER DATABASE LINK conn_db_link RENAME TO new_name, and it gives me the error.
Is there a way to alter the link name?
Thanks in advance.

Related

CREATE TABLE LIKE in DB2 10 for z/OS throwing an error

Using DB2 for z/OS v.10, I'm getting an error when I specify a tablespace when using CREATE TABLE ... LIKE.
I can successfully use CREATE TABLE ... LIKE if I don't specify a new tablespace, but it throws an error when I specify a tablespace. The manual seems to say that this should work, but I must have an error in the syntax.
Create Table MySchema.Deleteme2
Like MySchema.Deleteme;
Table MYSCHEMA.DELETEME2 created.
Create Table MySchema.Deleteme2
Like MySchema.Deleteme
in MYDB.SOMETS
;
THE STATEMENT COULD NOT BE PROCESSED BECAUSE ONE OR MORE IMPLICITLY CREATED OBJECTS ARE INVOLVED 1.
Any ideas?
Thank you for your help!
Dave
Resolved by ensuring that the target tablespace was first created with the correct attributes and permissions, before running the create table .... like ... in ...

PostgreSQL Create Table command not working, checked access privileges and all default privileges are there

I'm extremely new to PostgreSQL and I just installed it using Homebrew.
I ran through creating and connecting to a database and now I'm trying to create a table with the standard command CREATE TABLE users(name string, age smallint, birthday date) and the command completes. However as soon as I run the command to list all tables I get the following Did not find any relations.
I checked all users and privileges and it looks like my profiles roles include Superuser, Create Role, Create DB, Replication, Bypass RLS and I'm a member of {}.
I'm not sure if there's something more I need to do in order to create tables under a certain database or not, but I've looked all over and can't seem to find an answer to this.
I'm not really sure what you're intending to do, be more explicit.
But it seems to me you've juste created tables and did not create any relations.
Try using a key and defining mother tables ?

Can't select from database without specifying schema name

I am new to databases and I was trying to set up PostreSQL and trying to query
tables in pgAdmin 4, but I always have to specify schema name as such:
SELECT * FROM infection_database.country
The database name is the same as the schema name. This is probably not good but I didn't know better.
I tried looking up some solutions and found and tried this, but it didn't fix the issue:
ALTER DATABASE infection_database SET search_path="infection_database";
Tried both with and without quotation marks if it matters. Where am I making a mistake?
Given solution works, but you need to restart the session for the changes to take effect.
Credit to #jjanes

SignalR hub not working with existing tables

In the begining I have given service broker enable status to database on MSSQL 2008. I have two tables with same fields. First one is existing table. Other is created new by me. Hub is not working with first existing table, but works fine with other table which we create new.
Our select statement is basic and we have used only select field like 'select field1,field2 from Table1 where field2=1'.
I am using C#.
What kind of problem can be in this issue, how can we solve?
I have found solution. SignalR wants table scheame name in sql statement. Default scheme name is dbo and our sql or stored procedure include dbo. Like:
'Select field1,field2 from dbo.Table1 where field2=1'.

how can I rename a table / move to a different schema in sql DB2?

I am trying to rename a table in db2 like so
rename table schema1.mytable to schema2.mytable
but getting the following error message:
the name "mytable" has the wrong number of qualifiers.. SQLCODE=-108,SQLSTATE=42601
what is the problem here.... I am using the exact syntax from IBM publib documentation.
You cannot change the schema of a given object. You have to recreate it.
There are severals ways to do that:
If you have only one table, you can export and import/load the table. If you use the IDX format, the DDL will be included in the generated file. If using another format, the table has be created.
You can recreate the table by using:
Create table schema2.mytable like schema1.mytable
You can extract the DDL with the db2look tool
If you are changing the schema name for a schema given, you can use ADMIN_COPY_SCHEMA
These last two options only create the table structure, and you still need to import the data. After having create the table, you insert the data by different ways:
Inserting directly
insert into schema2.mytable select * from schema1.mytable
Via load from cursor
Via a Load or import from file (The file exported in the previous step)
The problem is the foreign relations, because they have to be recreated.
Finally, you can create an alias. It is easier, and you do not have to deal with relations.
You can easily rename a table with this statement:
RENAME TABLE SCHEMA.TABLENAME TO NEWTABLENAME;
You're not renaming table in provided example, you're trying to move to different schema, it's not the same thing. Look into db2move tool for this.
if you want to rename a table in the same schema, you can use like this.
RENAME TABLE schema.table_name TO "new_table_name";
Otherwise, you can use tools like DBeaver to rename or copy tables in a db2 db.
What if you leave it as is and create an alias with the new name and schema.
Renaming a table means to rename a table within same schema .To rename in other schema ,db2 call its ALIAS:
db2 create alias for