Re: determining which table to lookup depending on data

From: Richard Huxton <dev(at)archonet(dot)com>
To: Steve Castellotti <SteveC(at)innocent(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: determining which table to lookup depending on data
Date: 2006-12-18 06:55:08
Message-ID: 45863B4C.5010006@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steve Castellotti wrote:
> SELECT name FROM (SELECT table_name FROM media WHERE media_id=1);

You can try something like:

SELECT name FROM audio JOIN media ON id
WHERE table_name='audio' AND media_id=1
UNION ALL
SELECT name FROM video JOIN media ON id
WHERE table_name='video' AND media_id=1
;

Assuming you've got indexes on (id) on both tables that should be
reasonably quick.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gene 2006-12-18 07:08:44 Re: fedora core 6 startup script for pg 8.2
Previous Message Richard Huxton 2006-12-18 06:49:36 Re: How non-superuser can restore database containing procedures