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 6482.1005166110@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg_dump and DEFAULT column values  ("Eric Ridge" <ebr@tcdi.com>)
List pgsql-general
"Eric Ridge" <ebr@tcdi.com> writes:
>> a sequence it is!  thanks.

> well, but then again, I want the default value of that field to be 1
> greater than the max value, not the next value in a sequence.
> The client application has the ability to change the value of that
> field, but new records need to be max+1.

Hmm.  I think you should think hard about why you believe that the
default has to work that way and you can't just use a sequence.
You're paying a high price to conform to what seems a very questionable
set of assumptions.

> So I guess to make pg_dump happy, and to solve potential concurrency
> issues, I need a trigger for that field?  Or will I have the same
> circular reference problem with a trigger?

The circular reference problem arises because SQL-language functions
are parsed and checked at CREATE FUNCTION time.  A cheezy way to get
around it is to define the function before the table, but write it in
a PL language --- presently, at least, PL function definitions are not
checked until first use.  So you could do

    create function get_the_max() ... language 'plpgsql';

    create table ... default get_the_max()

and it should work and also dump correctly.

            regards, tom lane

pgsql-general by date:

Previous
From: Vivek Khera
Date:
Subject: constraint surgery
Next
From: "Eric Ridge"
Date:
Subject: Re: pg_dump and DEFAULT column values