"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