pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan Wieck <JanWieck@Yahoo.com>
To: Josh Berkus <josh@agliodbs.com>
Cc: Cedar Cox <cedarc@visionforisrael.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: REFERENCES constraint
Date: Wed, 8 Aug 2001 13:50:52 -0400 (EDT)
Message-ID: <200108081750.f78HoqJ11933@jupiter.us.greatbridge.com> (raw)
In-Reply-To: <web-98845@davinci.ethosmedia.com>

Josh Berkus wrote:
> Cedar,
>
> > 1. Can a column reference more than one table?  (This assumes you use
> > a
> > single sequence to generate the IDs for both "tbla" and "tblb".  I
> > guess
> > you would also have the problem of enforcing a unique index.  Say
> > what?!
> > A unique index across multiple tables.. absurd :)  eg..
> >
> >   CREATE TABLE blah (
> >     id int4,
> >     f_id int4 REFERENCES tbla (id) REFERENCES tblb (id)
> >   )
>
> I'd reccomend, instead, having blah reference tbla and tbla reference
> tblb.  It'd have the same effect, without forcing you to monkey around
> with custom triggers.

    Nobody  said  that  primary  keys  are  limited to the serial
    datatype. So in case that tbla and tblb could have  different
    sets  of keys with a possible intersection, and further given
    that blah.f_id shall  be  limited  to  values  both  have  in
    common, there's no other way than having multiple foreign key
    constraints on that one column.

    Thus, it is possible. I'm not sure if  the  above  syntax  is
    supported,  but  at  least you can put table level CONSTRAINT
    clauses into the statement and/or add the  constraints  later
    with ALTER TABLE.

>
> > 2. Can a column reference another column in the same table?  eg..
> >
> >   CREATE TABLE bloo (
> >     id int4,
> >     p_id int4 REFERENCES bloo (id)
> >   -- or
> >   --p_id int4 REFERENCES (id)
> >   )
>
> Er ... why would you want to?

    To  build  a  tree  structure  of nodes. Root nodes have p_id
    (meaning parent-id I guess) set to NULL, all others must have
    an  existing node as parent.  Together with ON DELETE CASCADE
    it'd build  an  expert-directory-structure  (experts  usually
    have "alias rm='/bin/rm -rf'" in their .profile, you know).

    Again, since it makes sense it is possible.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




view thread (10+ messages)  latest in thread

Message-ID: <200108081750.f78HoqJ11933@jupiter.us.greatbridge.com>
Permalink:  ../200108081750.f78HoqJ11933@jupiter.us.greatbridge.com/
Also on:    postgresql.org/message-id/200108081750.f78HoqJ11933@jupiter.us.greatbridge.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: JanWieck@Yahoo.com, josh@agliodbs.com, cedarc@visionforisrael.com
  Subject: Re: REFERENCES constraint
  In-Reply-To: <200108081750.f78HoqJ11933@jupiter.us.greatbridge.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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