Re: Displaying two tables side by side - Mailing list pgsql-sql

From David Garamond
Subject Re: Displaying two tables side by side
Date
Msg-id 411A6B94.3080807@zara.6.isreserved.com
Whole thread Raw
In response to Re: Displaying two tables side by side  (Andreas Haumer <andreas@xss.co.at>)
List 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


pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: Displaying two tables side by side
Next
From: Bruno Wolff III
Date:
Subject: Re: reply to setting