pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Referencing a column from another table in a different database with a foreign key constraint.
2+ messages / 2 participants
[nested] [flat]

* Referencing a column from another table in a different database with a foreign key constraint.
@ 2003-05-19 11:39  Dan S <dan@binaryfrost.net>
  0 siblings, 1 reply; 2+ messages in thread

From: dan@binaryfrost.net @ 2003-05-19 11:39 UTC (permalink / raw)
  To: pgsql-sql

I am trying to write a foreign key table constraint which references
another column from a table in another database from within
PostgreSQL.

Within the database 'rsg_auth', there is a table called 'user_table'
which has a column (amongst others) called 'username'.

In another database called 'browser perm' I am trying to create the
following:

CREATE TABLE user_agreement (
  ua_name    VARCHAR(16)    NOT NULL,
  ua_desc    TEXT        NOT NULL,
  sat_name    VARCHAR(20)        DEFAULT '',
  contract    VARCHAR(30)        DEFAULT '',
  filetype    VARCHAR(30)        NOT NULL,
  areacode    VARCHAR(30)        NOT NULL,
  nrt    CHAR NOT NULL DEFAULT 'N' CONSTRAINT chkcons_nrt_y_n CHECK
(nrt IN ('Y', 'N')),
  PRIMARY KEY       (ua_name),
  CONSTRAINT fk_uaname_username        FOREIGN KEY (ua_name)       
REFERENCES rsg_auth.user_table(username)        ON UPDATE CASCADE     
  ON DELETE CASCADE
)

When I submitt it, I get the following error:
    ERROR:  parser: parse error at or near "."

Obviously this has something to do with my reference to the other
table.

Can anyone put my syntax straight please?

Thanks in advance.

-- 

Mr. Daniel J. Smale
Remote Sensing Group
Plymouth Marine Laboratory



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Referencing a column from another table in a different
@ 2003-05-23 01:48  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Dan S <dan@binaryfrost.net>
  0 siblings, 0 replies; 2+ messages in thread

From: Stephan Szabo @ 2003-05-23 01:48 UTC (permalink / raw)
  To: Dan S <dan@binaryfrost.net>; +Cc: pgsql-sql


On 19 May 2003, Dan S wrote:

> I am trying to write a foreign key table constraint which references
> another column from a table in another database from within
> PostgreSQL.
>
> Within the database 'rsg_auth', there is a table called 'user_table'
> which has a column (amongst others) called 'username'.
>
> In another database called 'browser perm' I am trying to create the
> following:
>
> CREATE TABLE user_agreement (
>   ua_name    VARCHAR(16)    NOT NULL,
>   ua_desc    TEXT        NOT NULL,
>   sat_name    VARCHAR(20)        DEFAULT '',
>   contract    VARCHAR(30)        DEFAULT '',
>   filetype    VARCHAR(30)        NOT NULL,
>   areacode    VARCHAR(30)        NOT NULL,
>   nrt    CHAR NOT NULL DEFAULT 'N' CONSTRAINT chkcons_nrt_y_n CHECK
> (nrt IN ('Y', 'N')),
>   PRIMARY KEY       (ua_name),
>   CONSTRAINT fk_uaname_username        FOREIGN KEY (ua_name)
> REFERENCES rsg_auth.user_table(username)        ON UPDATE CASCADE
>   ON DELETE CASCADE
> )
>
> When I submitt it, I get the following error:
>     ERROR:  parser: parse error at or near "."
>
> Obviously this has something to do with my reference to the other
> table.

You can't do this currently.  If they were in separate schemas of the same
database you should be able to do it with something like the above, but
across databases it won't work.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-05-23 01:48 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-05-19 11:39 Referencing a column from another table in a different database with a foreign key constraint. Dan S <dan@binaryfrost.net>
2003-05-23 01:48 ` Re: Referencing a column from another table in a different Stephan Szabo <sszabo@megazone23.bigpanda.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox