Re: serial

From: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>
To: "Gustavo Rosso" <grosso(at)sadaic(dot)org(dot)ar>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: serial
Date: 2008-12-04 13:43:28
Message-ID: 2f4958ff0812040543n1329e6ceo52dbfa395a7dbbcd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 4, 2008 at 2:42 PM, Gustavo Rosso <grosso(at)sadaic(dot)org(dot)ar> wrote:
> I created this table:
>
> create table se (n serial);
>
in case you did just insert into se(n) values(0); twice, it won't work
if you want to add series of numbers, don't define it as serial.
Serial is for a different purpose.
if you want a series of generated numbers, please use generate_series();

so :

create table se(n int not null);
insert into se(n) select generate_series(1,100);

serial is used for different purposes. Say, you need an auto
incremented id on a row:
create table foo(
id serial,
name varchar(128)
);

and than:

insert into foo(name) values('Gustavo'), ('Grzegorz') returning id;

;]

hth

--
GJ

In response to

  • serial at 2008-12-04 14:42:13 from Gustavo Rosso

Browse pgsql-general by date

  From Date Subject
Next Message Serge Fonville 2008-12-04 13:45:50 Re: serial
Previous Message Pavel Stehule 2008-12-04 13:41:57 Re: serial