Re: [GENERAL] How to access a second database - Mailing list pgsql-general

From Stanislav Ganin
Subject Re: [GENERAL] How to access a second database
Date
Msg-id BN3PR0501MB1378F14B38925AC75F3062DDB35E0@BN3PR0501MB1378.namprd05.prod.outlook.com
Whole thread Raw
In response to [GENERAL] How to access a second database  (Sherman Willden <operasopranos@gmail.com>)
List pgsql-general

Hello Sherman,

 

You cannot cross reference databases like this in PG. You should re-think the schema you are going to use.

Check this line from the documentation (https://www.postgresql.org/docs/current/static/ddl-schemas.html):

PostgreSQL database cluster contains one or more named databases. Users and groups of users are shared across the entire cluster, but no other data is shared across databases. Any given client connection to the server can access only the data in a single database, the one specified in the connection request.”

 

Regards,

Stanislav

 

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Sherman Willden
Sent: Tuesday, October 31, 2017 9:15 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] How to access a second database

 

I am trying to access a table from another database. I have the permissions to create under my own login. I have performed the following so far:

sherman@sql-dev: createdb sandbox01

sherman@sql-dev:~$ createdb sandbox02.

After logging into sandbox02 I performed the following: sandbox02=# CREATE TABLE last_names(last_name TEXT);

sandbox02=# INSERT INTO last_names VALUES(willden);

 

Now I think I want to use a foreign key in sandbox01. Is the following how it works after logging into sandbox01?

sandbox01=# CREATE TABLE first_and_last(first_name TEXT, last_name FOREIGN KEY last_name REFERENCES sandbox02(last_names(last_name))

 

and then sandbox01=# INSERT INTO first_and_last(sherman, willden);

 

Thank you;

Sherman

pgsql-general by date:

Previous
From: Sherman Willden
Date:
Subject: [GENERAL] How to access a second database
Next
From: John R Pierce
Date:
Subject: Re: [GENERAL] How to access a second database