Re: pg_dump and DEFAULT column values - Mailing list pgsql-general

From Tom Lane
Subject Re: pg_dump and DEFAULT column values
Date
Msg-id 21436.1005082579@sss.pgh.pa.us
Whole thread Raw
In response to pg_dump and DEFAULT column values  ("Eric Ridge" <ebr@tcdi.com>)
List pgsql-general
"Eric Ridge" <ebr@tcdi.com> writes:
> I have a function and a table:
>   create table foo (
>      f1 integer default foo_func();
>   );

>   create function foo_func returns integer
>      as 'select max(f1)+1 from foo'
>      language 'sql';

> when I use pg_dump, and then psql (\i <dumpfile>) to dump/reload
> everything, table foo can't be created because it uses foo_func which
> can't be created because it uses a table (foo) which doesn't exist.

pg_dump has a hard time with circular dependencies :-(

Have you considered using a sequence, rather than generating new values
as shown above?  The approach you are using is extremely fragile:
consider what happens if two backends try to insert at the same time.

            regards, tom lane

pgsql-general by date:

Previous
From: Keary Suska
Date:
Subject: Re: Use of Serial Datatype and Sequence Issue
Next
From: jd@commandprompt.com (Joshua Drake)
Date:
Subject: Re: Sourceforge moving from PostgreSQL to Oracle