Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 471A363381D for ; Thu, 16 Apr 2009 16:11:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 94104-02 for ; Thu, 16 Apr 2009 16:11:20 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vs137086.vserver.de (static-ip-62-75-137-86.inaddr.intergenia.de [62.75.137.86]) by mail.postgresql.org (Postfix) with ESMTP id 594FD633558 for ; Thu, 16 Apr 2009 16:11:19 -0300 (ADT) Received: (qmail 22117 invoked from network); 16 Apr 2009 21:11:17 +0200 Received: from p54b3aec0.dip0.t-ipconnect.de (HELO a-kretschmer.de) (84.179.174.192) by static-ip-62-75-137-86.inaddr.intergenia.de with (AES256-SHA encrypted) SMTP; 16 Apr 2009 21:11:17 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1LuWzV-00038R-LH for pgsql-sql@postgresql.org; Thu, 16 Apr 2009 21:11:17 +0200 Date: Thu, 16 Apr 2009 21:11:17 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: how to set the value to the column Message-ID: <20090416191117.GA11946@tux> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/95 X-Sequence-Number: 32441 DM 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°