Search Postgresql Archives

Re: Recursive FOREIGN KEY?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Joe Stump <joe@joestump.net> writes:
> I had to insert the initial record and then add the foreign key
> restraint after inserting the initial record was created (0 being the
> first level of the category structure) -

Why?  It worked fine for me without any workaround ...

regression=# CREATE TABLE categories (
regression(#   categoryID integer PRIMARY KEY,
regression(#   parentID integer REFERENCES categories (categoryID) ON DELETE CASCADE,
regression(#   name text);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "categories_pkey" for table "categories"
CREATE TABLE
regression=# insert into categories values(0,0,'root');
INSERT 1349044 1
regression=# insert into categories values(1,2,'root');
ERROR:  insert or update on table "categories" violates foreign key constraint "$1"
DETAIL:  Key (parentid)=(2) is not present in table "categories".
regression=# insert into categories values(1,0,'root');
INSERT 1349046 1
regression=#

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux