Skip site navigation (1) Skip section navigation (2)

Re: Is a SERIAL column a "black box", or not?

From: mark(at)mark(dot)mielke(dot)cc
To: Mark Dilger <pgsql(at)markdilger(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Is a SERIAL column a "black box", or not?
Date: 2006-04-30 18:07:08
Message-ID: 20060430180708.GA18303@mark.mielke.cc (view raw or flat)
Thread:
Lists: pgsql-hackers
On Sun, Apr 30, 2006 at 09:14:53AM -0700, Mark Dilger wrote:
> 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.

Not madness. Just evidence of another problem, which is where the insert
that returns results comes in...

Cheers,
mark

-- 
mark(at)mielke(dot)cc / markm(at)ncf(dot)ca / markm(at)nortel(dot)com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


In response to

Responses

pgsql-hackers by date

Next:From: eleinDate: 2006-04-30 21:02:12
Subject: Re: Is a SERIAL column a "black box", or not?
Previous:From: Tom LaneDate: 2006-04-30 17:17:15
Subject: Re: Altering view ownership doesn't work ...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group