From: David Garamond <lists@zara.6.isreserved.com>
To: Andreas Haumer <andreas@xss.co.at>
To: pgsql-sql@postgresql.org
Subject: Re: Displaying two tables side by side
Date: Thu, 12 Aug 2004 01:55:16 +0700
Message-ID: <411A6B94.3080807@zara.6.isreserved.com> (raw)
In-Reply-To: <411A5976.4090502@xss.co.at>
References: <411A2926.9020500@zara.6.isreserved.com>
<411A5976.4090502@xss.co.at>
Andreas Haumer wrote:
> You could try to use PosgreSQL's ctid system column to join on like this:
>
> test=# select *,ctid from t1;
> a | b | ctid
> - ---+---+-------
> 2 | 2 | (0,1)
> 3 | 5 | (0,2)
> 4 | 7 | (0,3)
> 9 | 0 | (0,4)
>
>
> test=# select *,ctid from t2;
> c | d | ctid
> - ---+---+-------
> 4 | 5 | (0,1)
> 7 | 3 | (0,2)
> 3 | 2 | (0,3)
> 1 | 1 | (0,4)
> 2 | 0 | (0,5)
>
>
> test=# select * from t1 right outer join t2 on (t1.ctid=t2.ctid);
> a | b | c | d
> - ---+---+---+---
> 2 | 2 | 4 | 5
> 3 | 5 | 7 | 3
> 4 | 7 | 3 | 2
> 9 | 0 | 1 | 1
> | | 2 | 0
>
>
> Note that this is of course very platform specific. On Oracle
> you could use rownum, for example.
> I don't have a more portable solution on hand right now.
>
> HTH
Thanks, I just found out about ctid. I was thinking on a rownum
equivalent too, actually.
I guess a more portable solution would be creating a temporary table for
each table to add the ctid/"row counter" equivalent, and then join on that.
--
dave
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: lists@zara.6.isreserved.com, andreas@xss.co.at
Subject: Re: Displaying two tables side by side
In-Reply-To: <411A6B94.3080807@zara.6.isreserved.com>
* 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