Re: how to show serial number of record

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: how to show serial number of record
Date: 2007-01-19 06:18:26
Message-ID: 20070119061826.GB26274@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am Thu, dem 18.01.2007, um 15:34:33 +0530 mailte deepak pal folgendes:
> hi i want to add a coloum called serial numer in my record set how could i do
> it..that column is not in table.

Do you mean something like this:?

test=# create table foo (t text);
CREATE TABLE
test=*# insert into foo values ('foo');
INSERT 0 1
test=*# insert into foo values ('bar');
INSERT 0 1
test=*# insert into foo values ('batz');
INSERT 0 1
test=*# select * from foo;
t
------
foo
bar
batz
(3 rows)

test=*# create sequence foo_seq;
CREATE SEQUENCE
test=*# select nextval('foo_seq'), * from foo;
nextval | t
---------+------
1 | foo
2 | bar
3 | batz
(3 rows)

Of course, you can rename the first column using the 'as' - syntax.

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris 2007-01-19 06:18:58 Re: help me to solve the problem
Previous Message Denis Lussier 2007-01-19 05:36:24 EnterpriseDB Apology