Re: determining which table to lookup depending on data - Mailing list pgsql-general

From Richard Huxton
Subject Re: determining which table to lookup depending on data
Date
Msg-id 45863B4C.5010006@archonet.com
Whole thread Raw
In response to determining which table to lookup depending on data values  (Steve Castellotti <SteveC@innocent.com>)
List 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

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: How non-superuser can restore database containing procedures
Next
From: Gene
Date:
Subject: Re: fedora core 6 startup script for pg 8.2