Re: using serial values

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: gearond(at)cvc(dot)net
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: using serial values
Date: 2003-02-13 20:19:11
Message-ID: 1045167551.10914.60.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2003-02-13 at 20:03, Dennis Gearon wrote:
> How do I get the values for the serial field? Do they automatically insert themselves with a
> default if I do not use that field in the INSERT statement?

Yes.

Or you can explicitly use nextval('sequence_name') to get the next
value.

> Example:
>
> create table EntityTypes(
> entity_type_id serial NOT NULL CONSTRAINT PK_EntityTypes1 PRIMARY KEY,
> entity_type varchar(16) NOT NULL,
> CONSTRAINT UC_EntityTypes_Entity_Type1 UNIQUE(entity_type)
> );
>
>
> INSERT INTO EntityTypes( entity_type ) VALUES 'Big Smile, Good Dresser, Easy to Get Along With';
>
> Will the above statement causes a row to be inserted with the value
> for 'entity_type_id' to be
> automatically 1 or 0?

Actually it will fail for syntax errors, but once you have corrected
those, it will insert a row with entity_type = 1.

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"The earth is the LORD'S, and the fullness thereof; the
world, and they that dwell therein."
Psalms 24:1

In response to

Browse pgsql-general by date

  From Date Subject
Next Message P G 2003-02-13 20:19:50 What is the default timeout setting?
Previous Message P G 2003-02-13 20:16:03 What other parameters to consider when increasing max connections?