From: | Ragnar <gnari(at)hive(dot)is> |
---|---|
To: | dterrors(at)hotmail(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Are these two creation commands functionally identical? |
Date: | 2007-08-11 09:21:18 |
Message-ID: | 1186824078.528.19.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On fim, 2007-08-09 at 20:55 +0000, dterrors(at)hotmail(dot)com wrote:
> I want to to know if these two are functionally equivalent. Is this:
>
> Create table "sales"
> (
> "saleid" BigSerial NOT NULL,
> "userid" Bigint NOT NULL,
> "parent_saleid" Bigint NOT NULL,
> primary key ("saleid")
> ) Without Oids;
> Alter table "sales" add foreign key ("userid") references
> "users" ("userid") on update restrict on delete restrict;
> Alter table "sales" add foreign key ("parent_saleid") references
> "sales" ("saleid") on update restrict on delete restrict;
this constraint seems a bit strange to me. are you going
to special-case the first insert into this table?
> Is the above functionally identical to:
>
> Create table "sales"
> (
> "saleid" BigSerial NOT NULL,
> "userid" bigint references users(userid),
> "parent_saleid" bigint references sales(saleid),
> primary key ("saleid")
> ) Without Oids;
no these 2 are not fuctionally identical, because the second one
does not have a NOT NULL constraint on the foreign keys,
allowing you to insert:
INSERT INTO sales (saleid,userid,parent_saleid)
VALUES (100,null,100);
gnari
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2007-08-11 10:28:45 | why it doesn't work? referential integrity |
Previous Message | Louis-David Mitterrand | 2007-08-11 08:57:33 | Re: timestamp skew during 7.4 -> 8.2 upgrade |