Re: help with serial type

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: help with serial type
Дата
Msg-id Pine.LNX.4.30.0104261729510.758-100000@peter.localdomain
обсуждение исходный текст
Ответ на help with serial type  (Jason <gee308@mediaone.net>)
Список 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@gmx.net   http://funkturm.homeip.net/~peter


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: newbie ?'s
Следующее
От: Jeff Waugh
Дата:
Сообщение: Re: Classes of returned rows