pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
serial in output
3+ messages / 3 participants
[nested] [flat]

* serial in output
@ 2005-10-28 11:18  alessandra de gregorio <adegregorio@fgscapital.com>
  0 siblings, 2 replies; 3+ messages in thread

From: alessandra de gregorio @ 2005-10-28 11:18 UTC (permalink / raw)
  To: pgsql-sql

Hi,

What function should I use to get a serial number, together with my results,
from a query?

Ex. Of output I want:

1	ooo	pp	ij
2	hou	joo	iu	
3	bhi	ft	yh

Basically, I would like to have one column with integers, from 1 onwards, no
matter how many tables I join in, or the data that I get back.

Thanks






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: serial in output
@ 2005-11-04 12:48  Andreas Kretschmer <akretschmer@spamfence.net>
  parent: alessandra de gregorio <adegregorio@fgscapital.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Andreas Kretschmer @ 2005-11-04 12:48 UTC (permalink / raw)
  To: pgsql-sql

alessandra de gregorio <adegregorio@fgscapital.com> schrieb:

> Hi,
> 
> What function should I use to get a serial number, together with my results,
> from a query?
> 
> Ex. Of output I want:
> 
> 1	ooo	pp	ij
> 2	hou	joo	iu	
> 3	bhi	ft	yh
> 
> Basically, I would like to have one column with integers, from 1 onwards, no
> matter how many tables I join in, or the data that I get back.

Create a sequence and then "select nextval('your_sequence'), * from foo;"


HTH, Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: serial in output
@ 2005-11-04 14:03  Harald Fuchs <hf0923x@protecting.net>
  parent: alessandra de gregorio <adegregorio@fgscapital.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Harald Fuchs @ 2005-11-04 14:03 UTC (permalink / raw)
  To: pgsql-sql

In article <20051028111824.C8C7DDA53F@svr1.postgresql.org>,
"alessandra de gregorio" <adegregorio@fgscapital.com> writes:

> Hi,
> What function should I use to get a serial number, together with my results,
> from a query?

> Ex. Of output I want:

> 1	ooo	pp	ij
> 2	hou	joo	iu	
> 3	bhi	ft	yh

> Basically, I would like to have one column with integers, from 1 onwards, no
> matter how many tables I join in, or the data that I get back.

I'd do it in application code, but if you insist on doing it at the
SQL layer:

CREATE TEMPORARY SEQUENCE tmpseq;
SELECT nextval('tmpseq'), othercols... FROM ...




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-11-04 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-28 11:18 serial in output alessandra de gregorio <adegregorio@fgscapital.com>
2005-11-04 12:48 ` Andreas Kretschmer <akretschmer@spamfence.net>
2005-11-04 14:03 ` Harald Fuchs <hf0923x@protecting.net>

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