Re: How to access a second database

From: Stanislav Ganin <sganin(at)vmware(dot)com>
To: Sherman Willden <operasopranos(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to access a second database
Date: 2017-10-31 07:40:47
Message-ID: BN3PR0501MB1378F14B38925AC75F3062DDB35E0@BN3PR0501MB1378.namprd05.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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):
“A 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(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Sherman Willden
Sent: Tuesday, October 31, 2017 9:15 AM
To: pgsql-general(at)postgresql(dot)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(at)sql-dev: createdb sandbox01
sherman(at)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2017-10-31 07:41:52 Re: How to access a second database
Previous Message Sherman Willden 2017-10-31 07:15:14 How to access a second database