pg_dump and DEFAULT column values - Mailing list pgsql-general

From Eric Ridge
Subject pg_dump and DEFAULT column values
Date
Msg-id D3ADE25911614840BC69C72E3171E4ED0FBDFF@tcdiexch.tcdi.com
Whole thread Raw
Responses Re: pg_dump and DEFAULT column values
List pgsql-general
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.

So I always have to hand-edit the dump file:

  create table foo (
     f1 integer;
  );

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

  alter table foo alter column f1 set default foo_func();


Is there a way for pg_dump to do this automagically? or should I define
the table and function differently?  Should the default value be
replaced with an on insert trigger?

eric

pgsql-general by date:

Previous
From: "Culley Harrelson"
Date:
Subject: functions vs embedded SQL
Next
From: Jeff Davis
Date:
Subject: Re: functions vs embedded SQL