Re: [despammed] Serial data type

From: Andreas Kretschmer <akretschmer(at)despammed(dot)com>
To: "'pgsql-novice(at)postgresql(dot)org'" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [despammed] Serial data type
Date: 2005-04-13 15:50:01
Message-ID: 20050413155001.GB20909@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

am 13.04.2005, um 9:30:09 -0600 mailte Walker, Jed S folgendes:
> I have several tables that require auto-generated Ids. I have noticed the
> serial and bigserial data types (or pseudo-types). These seem like they make
> things much simpler, but if you use this, how can you find out the the value
> of the serial column after you insert a row? Do you have to lookup the

Please read the manual about currval().

> primary key or is it stored in a session variable or some other place? Is

In a squence, a extra database object.

> it better to define the sequence manually and just select it out by hand
> before doing the insert?

No. Why?

test_db=# create table seq_test (id serial, name varchar);
HINWEIS: CREATE TABLE erstellt implizit eine Sequenz >>seq_test_id_seq<< f?r die >>serial<<-Spalte >>seq_test.id<<
CREATE TABLE
test_db=# insert into seq_test (name) values ('Andreas');
INSERT 373930 1
test_db=# insert into seq_test (name) values ('Anja');
INSERT 373931 1
test_db=# select * from seq_test;
id | name
----+---------
1 | Andreas
2 | Anja
(2 Zeilen)

test_db=#

Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47212, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2005-04-13 16:10:55 Re: Serial data type
Previous Message Michael Fuhr 2005-04-13 15:34:42 Re: Problems on "copy" statement