Re: Displaying two tables side by side

From: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
To: Andreas Haumer <andreas(at)xss(dot)co(dot)at>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Displaying two tables side by side
Date: 2004-08-11 18:55:16
Message-ID: 411A6B94.3080807@zara.6.isreserved.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2004-08-11 19:13:21 Re: reply to setting
Previous Message Rod Taylor 2004-08-11 18:32:30 Re: Displaying two tables side by side