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

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: (view raw, whole thread or download thread mbox)
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 ""
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
postgres=# \d t1
                         Table "public.t1"
 Column |  Type   |                    Modifiers                    
 id     | integer | not null default nextval('t1_id_seq'::regclass)
    "t1_pkey" PRIMARY KEY, btree (id)


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


pgsql-novice by date

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

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