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   [EMAIL PROTECTED]   http://funkturm.homeip.net/~peter


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly

Reply via email to