pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: how to set the value to the column
Date: Thu, 16 Apr 2009 21:11:17 +0200
Message-ID: <20090416191117.GA11946@tux> (raw)
In-Reply-To: <eae6a62a0904161200j14dd0759j9b3fb656f526f833@mail.gmail.com>
References: <eae6a62a0904161200j14dd0759j9b3fb656f526f833@mail.gmail.com>

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    |  1
 b    |  2
 c    |  3
 d    |  4
 e    |  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°



view thread (3+ messages)

Message-ID: <20090416191117.GA11946@tux>
Permalink:  ../20090416191117.GA11946@tux/
Also on:    postgresql.org/message-id/20090416191117.GA11946@tux

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: akretschmer@spamfence.net
  Subject: Re: how to set the value to the column
  In-Reply-To: <20090416191117.GA11946@tux>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox