Re: how does setval() work???

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: chris Gnther <guenther(at)uscreen(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: how does setval() work???
Date: 2001-01-10 16:32:06
Message-ID: 200101101632.f0AGW7N21365@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

chris Gnther wrote:
>database with the default values in the table I need to set my sequence
>by hand using setval() I think. But I just can't figure out how this works.
>
>Can anyone give me an example???

bray=# create table junk (id serial, name text);
NOTICE: CREATE TABLE will create implicit sequence 'junk_id_seq' for SERIAL
column 'junk.id'
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'junk_id_key' for
table 'junk'

bray=# insert into junk (name) values ('Fred');
INSERT 194510 1
bray=# select * from junk;
id | name
----+------
1 | Fred
(1 row)

bray=# select setval('junk_id_seq',5);
setval
--------
5
(1 row)

bray=# insert into junk (name) values ('Joe');
INSERT 194511 1
bray=# select * from junk;
id | name
----+------
1 | Fred
6 | Joe
(2 rows)

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Be patient therefore, brethren, unto the coming of the
Lord...Be patient; strengthen your hearts, for
the coming of the Lord draweth nigh."
James 5:7,8

Browse pgsql-novice by date

  From Date Subject
Next Message Rik Bradt 2001-01-10 17:03:13 RE: Dumping Large Object
Previous Message William Staniewicz 2001-01-10 16:23:08 converting .xls to delimited file