Re: serial - Mailing list pgsql-general

From Grzegorz Jaśkiewicz
Subject Re: serial
Date
Msg-id 2f4958ff0812040543n1329e6ceo52dbfa395a7dbbcd@mail.gmail.com
Whole thread Raw
In response to serial  (Gustavo Rosso <grosso@sadaic.org.ar>)
List pgsql-general
On Thu, Dec 4, 2008 at 2:42 PM, Gustavo Rosso <grosso@sadaic.org.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

pgsql-general by date:

Previous
From: "Grzegorz Jaśkiewicz"
Date:
Subject: Re: column name order matters in insert into foo from bar
Next
From: "Serge Fonville"
Date:
Subject: Re: serial