Re: pg_dump and DEFAULT column values

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Eric Ridge" <ebr(at)tcdi(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pg_dump and DEFAULT column values
Date: 2001-11-07 20:48:30
Message-ID: 6482.1005166110@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Eric Ridge" <ebr(at)tcdi(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Teviotdale 2001-11-07 20:52:41 Re: OID's as Primary Keys
Previous Message Al Kirkus 2001-11-07 20:14:41 Re: Probably simple answer