Обсуждение: automatic numbering in a new column

Поиск
Список
Период
Сортировка

automatic numbering in a new column

От
ppdcc@sapo.pt
Дата:
Hello to all,


I'm have a database with two tables, one of them is the streets. Can  
anybody tell me how do i create, with a sql instruction, a new column  
with automatic numbering in this table?
This column don?t have to be the primary key but has to be unique for  
each feature.


can anybody tell me?

thanks

pdcc


Re: automatic numbering in a new column

От
Guillaume Lelarge
Дата:
On Wed, 2011-08-24 at 19:40 +0100, ppdcc@sapo.pt wrote:
[...]
> 
> I'm have a database with two tables, one of them is the streets. Can  
> anybody tell me how do i create, with a sql instruction, a new column  
> with automatic numbering in this table?

Use the serial pseudo type for this column.

-- 
Guillaume http://blog.guillaume.lelarge.info http://www.dalibo.com



Re: automatic numbering in a new column

От
Guillaume Lelarge
Дата:
A few comments before answering:
1. Don't top post. It makes it hard to read.
2. Reply to the list.
3. Choose your list more carefully. pgadmin-support is about pgAdmin  support, not about SQL.

This being said, I'll quickly answer your question...

On Wed, 2011-08-24 at 19:47 +0100, ppdcc@sapo.pt wrote:
> and how i do that?
> 
> cAN you make a example for me
> 

CREATE TABLE t1 (c1 serial, c2 text);

c1 will be automatically numbered if you don't set a value for it. Just
like this: INSERT INTO t1 (c2) VALUES ('hello');


-- 
Guillaume http://blog.guillaume.lelarge.info http://www.dalibo.com