How to do auto numbering on INT column

Started by Junkoneover 19 years ago4 messagesgeneral
Jump to latest
#1Junkone
junkone1@gmail.com

HI
I have a simple table created using PGAdmin III. How do i do a auto
numbering on a column SYMBOL_ID?
My table is
CREATE TABLE "SYMBOL"
(
"SYMBOL_ID" int4 NOT NULL,
"SYMBOL2EXCHANGE" int2 NOT NULL,
"SYMBOL_ALIAS" text[],
"RELATED_SYMBOLS_OTHER_EXCHANGES" int8[],
"SYMBOL_NAME" text,
"COMPANY_NAME" text,
"SYMBOL2SECTOR" int2,
"SYMBOL2INDUSTRY" int4,
"STOCK_SUMMARY" text
)

Thanks

Seede

#2Chris Mair
chrisnospam@1006.org
In reply to: Junkone (#1)
Re: How to do auto numbering on INT column

HI
I have a simple table created using PGAdmin III. How do i do a auto
numbering on a column SYMBOL_ID?
My table is
CREATE TABLE "SYMBOL"
(
"SYMBOL_ID" int4 NOT NULL,
"SYMBOL2EXCHANGE" int2 NOT NULL,
"SYMBOL_ALIAS" text[],
"RELATED_SYMBOLS_OTHER_EXCHANGES" int8[],
"SYMBOL_NAME" text,
"COMPANY_NAME" text,
"SYMBOL2SECTOR" int2,
"SYMBOL2INDUSTRY" int4,
"STOCK_SUMMARY" text
)

Use column type SERIAL, or, if you want to fine tune things,
use sequences:
http://www.postgresql.org/docs/8.1/static/sql-createsequence.html
(in fact, SERIAL does define a sequence behind the scenes for you).

Bye, Chris.

--

Chris Mair
http://www.1006.org

#3Brent Wood
b.wood@niwa.co.nz
In reply to: Junkone (#1)
Re: How to do auto numbering on INT column

Junkone wrote:

HI
I have a simple table created using PGAdmin III. How do i do a auto
numbering on a column SYMBOL_ID?
My table is
CREATE TABLE "SYMBOL"
(
"SYMBOL_ID" int4 NOT NULL,
"SYMBOL2EXCHANGE" int2 NOT NULL,
"SYMBOL_ALIAS" text[],
"RELATED_SYMBOLS_OTHER_EXCHANGES" int8[],
"SYMBOL_NAME" text,
"COMPANY_NAME" text,
"SYMBOL2SECTOR" int2,
"SYMBOL2INDUSTRY" int4,
"STOCK_SUMMARY" text
)

If you can, the easy way is to recreate the table using a serial
datatype instead of int4.

See the docs at
http://www.postgresql.org/docs/8.1/interactive/datatype.html#DATATYPE-SERIAL

Otherwise this also shows the long way to do it.

HTH,

Brent Wood

#4Alban Hertroys
alban@magproductions.nl
In reply to: Junkone (#1)
Re: How to do auto numbering on INT column

Junkone wrote:

CREATE TABLE "SYMBOL"
(
"SYMBOL_ID" int4 NOT NULL,
"SYMBOL2EXCHANGE" int2 NOT NULL,
"SYMBOL_ALIAS" text[],
"RELATED_SYMBOLS_OTHER_EXCHANGES" int8[],
"SYMBOL_NAME" text,
"COMPANY_NAME" text,
"SYMBOL2SECTOR" int2,
"SYMBOL2INDUSTRY" int4,
"STOCK_SUMMARY" text
)

I think you'll want to remove all those double-quotes. They make your
table and column names case sensitive. You'd need to quote these in your
queries as well, if you stay with what pgadmin (apparently) created.

--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //