Re: help with serial type

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jason <gee308(at)mediaone(dot)net>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: help with serial type
Date: 2001-04-26 15:32:45
Message-ID: Pine.LNX.4.30.0104261729510.758-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jason writes:

> Hi , I'm a postgreSQL newbie. I have a table called "atable" that has
> the columns:
> title varchar(20)
> name varchar(20)
> id serial
> if I do:
> INSERT INTO TABLE atable VALUES('SQL1','Jason')
> the 'id' gets updated with a new number automatically. I then later
> added a new column called 'date'. Now if I do an insert with:
> INSERT INTO TABLE atable VALUES('SQL2','Toy','',date('now'))
> the id will update the first time to '0',

This is not really valid. What you are telling PostgreSQL is to insert a
value of '' (empty string) into the id column. This gets converted to 0
(zero) by the implicit type converter. The serial type only generates a
sequence number if you do not override it explicitly with a different
value. So what you want is something like this:

INSERT INTO TABLE atable (title, name, date_field)
VALUES ('SQL2', 'Toy', current_date);

--
Peter Eisentraut peter_e(at)gmx(dot)net http://funkturm.homeip.net/~peter

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2001-04-26 15:36:26 Re: Consulta
Previous Message J.H.M. Dassen Ray 2001-04-26 15:32:02 Re: Why Size Of Data Backed Up Varies Significantly In SQL 6.5?