Re: No serial type

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: No serial type
Дата
Msg-id dcc563d10811180937r2f97bdd6ma9f94853ffa228c@mail.gmail.com
обсуждение исходный текст
Ответ на No serial type  (Simon Connah <simon.n.connah@btopenworld.com>)
Ответы Re: No serial type  (Raymond O'Donnell <rod@iol.ie>)
Re: No serial type  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: No serial type  (Christian Schröder <cs@deriva.de>)
Список pgsql-general
On Tue, Nov 18, 2008 at 10:24 AM, Simon Connah
<simon.n.connah@btopenworld.com> wrote:
> Hi,
> I've just started using PostgreSQL and have been reading up on it. Part of
> what I wanted to do was to have a column which automatically incremented
> itself by one every time I do an INSERT. From reading the manual I was lead
> to believe that the correct type for this was either serial or bigserial.
> But whenever I try and update my column to this type it says that it can not
> find that data type. Am I doing something wrong?

Serial is a "pseudotype".  It represents creating an int or bigint and
a sequence then assigning a default value for the column and setting
dependency in the db so the sequence will be dropped when the table
gets dropped.  If you don't want to recreate the table, you can do
this:

create table a (i int primary key, info text);
create sequence a_i_seq;
alter table a alter column i set default nextval('a_i_seq');

not sure the alter table syntax is spot on, haven't used it in a few months.

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

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: High Availability for PostgreSQL on Windows 2003.
Следующее
От: "Andrus"
Дата:
Сообщение: Conversion of string to int using digits at beginning