Re: currval, lastval, nextvar?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: currval, lastval, nextvar?
Date: 2009-04-23 16:07:08
Message-ID: 28852.1240502828@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> writes:
> Yes. You don't need call nextval.

Well, you do, but the point is that the default expression for a
serial column includes the nextval() call. Look at the table with
\d, eg

postgres=# create table t1(id serial primary key);
NOTICE: CREATE TABLE will create implicit sequence "t1_id_seq" for serial column "t1.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
CREATE TABLE
postgres=# \d t1
Table "public.t1"
Column | Type | Modifiers
--------+---------+-------------------------------------------------
id | integer | not null default nextval('t1_id_seq'::regclass)
Indexes:
"t1_pkey" PRIMARY KEY, btree (id)

postgres=#

So if you do an insert that doesn't provide a value for that column,
the nextval is done implicitly.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Andreas Kretschmer 2009-04-23 16:17:39 Re: currval, lastval, nextvar?
Previous Message A. Kretschmer 2009-04-23 15:59:52 Re: currval, lastval, nextvar?