Re: DECODE
От | Josh Berkus |
---|---|
Тема | Re: DECODE |
Дата | |
Msg-id | web-495383@davinci.ethosmedia.com обсуждение исходный текст |
Ответ на | DECODE (David Link <dlink@soundscan.com>) |
Список | pgsql-novice |
David, > How does one do the equivalence of Oracle's DECODE in PostgreSQL? > > select > decode (v.media, 'V', 'VHS', 'L', 'Laser Disk', 'Unknown') > from > videos v > ; Use a CASE statement: SELECT (CASE WHEN v.media = 'V' THEN 'VHS' WHEN v.media = 'L' THEN 'Laser Disk' ELSE 'Unknown' END) AS media_exp FROM videos v; If you wanted, you could write a PL/pgSQL function to simplify this, using two array parameters to hold the lists. HOWEVER, it would be far better than both of the above, relationally, to create a reference table populated with the appropriate values (media_code, media_name) and JOIN the reference table. This would prevent you from having to populate a special function on each and every query! -Josh ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco
В списке pgsql-novice по дате отправления: