Обсуждение: how to set the value to the column
Hi All,
I have a table test with columns name and value
test table
name
value
It has around 500 rows.
I added a new column id to the table,
Table test
id,
name,
value
I am not sure how to insert numbers to my column id (1-500).
Thanks
DM <dm.aeqa@gmail.com> wrote:
> Hi All,
>
> I have a table test with columns name and value
>
> test table
> name
> value
>
> It has around 500 rows.
>
> I added a new column id to the table,
>
> Table test
> id,
> name,
> value
>
> I am not sure how to insert numbers to my column id (1-500).
You can create a SEQUENCE and use this Sequence for that, an example:
test=# create table foo (name text);
CREATE TABLE
Zeit: 2,824 ms
test=*# copy foo from stdin;
Geben Sie die zu kopierenden Daten ein, gefolgt von einem Zeilenende.
Beenden Sie mit einem Backslash und einem Punkt alleine auf einer Zeile.
>> a
>> b
>> c
>> d
>> e
>> \.
Zeit: 5592,132 ms
test=*# create sequence foo_seq;
CREATE SEQUENCE
Zeit: 10,030 ms
test=*# alter table foo add column id int;
ALTER TABLE
Zeit: 0,347 ms
test=*# update foo set id = nextval('foo_seq');
UPDATE 5
Zeit: 0,379 ms
test=*# select * from foo;name | id
------+----a | 1b | 2c | 3d | 4e | 5
(5 Zeilen)
Zeit: 0,241 ms
test=*#
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
never mind i got the answer.
Thanks for looking into it.
- deepak
On Thu, Apr 16, 2009 at 12:00 PM, DM <dm.aeqa@gmail.com> wrote:
Hi All,I have a table test with columns name and valuetest tablenamevalueIt has around 500 rows.I added a new column id to the table,Table testid,name,valueI am not sure how to insert numbers to my column id (1-500).Thanks