dbTalk Databases Forums  

alter table alter column: from integer to serial?

comp.databases.postgresql comp.databases.postgresql


Discuss alter table alter column: from integer to serial? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Thomas Guettler
 
Posts: n/a

Default alter table alter column: from integer to serial? - 02-11-2008 , 09:07 AM






Hi,

how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
FEHLER: Typ »serial« existiert nicht
(ERROR: Typ serial does not exist)

Thomas

Reply With Quote
  #2  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM






"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
  #3  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM



"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
  #4  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM



"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
  #5  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM



"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
  #6  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM



"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
  #7  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM



"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
  #8  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM



"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
  #9  
Old   
HansH
 
Posts: n/a

Default Re: alter table alter column: from integer to serial? - 02-23-2008 , 05:07 PM



"Thomas Guettler" <hv (AT) tbz-pariv (DOT) de> schreef in bericht
news:61b6ldF1t14enU1 (AT) mid (DOT) individual.net...
Quote:
how to update a primary key column from type integer to type serial?

foo=# alter table footable alter column id type serial;
(ERROR: Typ serial does not exist)

http://www.postgresql.org/docs/8.1/i...ATATYPE-SERIAL
" The data types serial and bigserial are not true types, but merely a
notational convenience for setting up unique identifier columns..."

To convert a table difined like
CREATE TABLE test_table
( test_column integer NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
into
CREATE TABLE test_table
( test_column serial NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_column) )
execute CREATE SEQUENCE test_table_test_column_seq
INCREMENT 1MINVALUE 1MAXVALUE 2147483648 START 1CACHE 1;
ALTER TABLE test_tableALTER COLUMN test_column
SET DEFAULT nextval('test_table_test_column_seq'::regclass);

Change MAXVALUE to the type -smallint, int or bigint-
Change START to the current max value of test_column.

HansH




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.