Thread: Default sequence values

Default sequence values

From
"Seth Banks"
Date:
I'm getting errors in pgsql when I try to run this create table statement
past...Could someone help me out here? I think it's the default value of
company_id that's erroring out. Any help is appreciated.

CREATE SEQUENCE company_id_seq;
CREATE TABLE company ( company_id     int4 PRIMARY KEY DEFAULT nextval(company_id_seq), parent_id      int4 NULL, name
        text NOT NULL, address_1      text NULL, address_2      text NULL, fax            text NULL, city
textNULL, state_province text NULL, zip            text NULL, country        text NULL, description    text NULL,
stock_symbol  text NULL
 
);
CREATE INDEX name_idx on company (name);



Re: [SQL] Default sequence values

From
Tom Lane
Date:
"Seth Banks" <seth@subimage.com> writes:
>   company_id     int4 PRIMARY KEY DEFAULT nextval(company_id_seq),

Try
 company_id     int4 PRIMARY KEY DEFAULT nextval('company_id_seq'),

Actually, this would work just as well:
 company_id     SERIAL,

and it'd even make the sequence object for you.
        regards, tom lane