Is it safe to use DEFAULT currval() - Mailing list pgsql-general

From Richard Huxton
Subject Is it safe to use DEFAULT currval()
Date
Msg-id 200309271740.27943.dev@archonet.com
Whole thread Raw
Responses Re: Is it safe to use DEFAULT currval()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I've got a table, and I'm trying to track changes to it, but can't do it via a
primary key including a revision-number (historical reasons).

CREATE TABLE foo (
  id       SERIAL,
  blah     text,
  tracking int4 DEFAULT currval('foo_id_seq')
  PRIMARY KEY (id)
);

I'm actually setting the DEFAULT on tracking using ALTER TABLE after the
event.

Now - it works, but is that a design feature or just luck?

It's convenient that tracking = id of the first entry, but not vital, so I can
always use a separate sequence if needs be.

--
  Richard Huxton
  Archonet Ltd

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Schema backup - SOLVED
Next
From: Richard Huxton
Date:
Subject: Re: PostgreSQL Delphi