Re: Is a SERIAL column a "black box", or not? - Mailing list pgsql-hackers

From Mark Dilger
Subject Re: Is a SERIAL column a "black box", or not?
Date
Msg-id 4454E27D.2090503@markdilger.com
Whole thread Raw
In response to Is a SERIAL column a "black box", or not?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Is a SERIAL column a "black box", or not?  (mark@mark.mielke.cc)
List pgsql-hackers
Tom Lane wrote:
> 1. A serial column is a "black box" that you're not supposed to muck with
> the innards of.  This philosophy leads to the proposal that we disallow
> modifying the column default expression of a serial column, and will
> ultimately lead to thoughts like trying to hide the associated sequence
> from direct access at all.

It would be madness to prevent people from accessing the associated sequence.
Assume the following schema:
  CREATE TABLE a (a_id SERIAL NOT NULL UNIQUE, ...);  CREATE TABLE b (a_fk INTEGER REFERENCES a(a_id), ...);

Now, if I need to insert into both tables a and b, how do I do it?  After
inserting into table a, if I can't access the sequence to get currval, I'll need
to do a select against the table to find the row that I just inserted (which
could be slow), and if the columns other than a_id do not uniquely identify a
single row, then I can't do this at all.

mark


pgsql-hackers by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Is a SERIAL column a "black box", or not?
Next
From: Tom Lane
Date:
Subject: Altering view ownership doesn't work ...