| От | Adam Rich |
|---|---|
| Тема | Re: how to return field based on field= NULL or not |
| Дата | |
| Msg-id | 4A920EC0.5070808@sbcglobal.net обсуждение исходный текст |
| Ответ на | how to return field based on field= NULL or not (Juan Backson <juanbackson@gmail.com>) |
| Список | pgsql-general |
Juan Backson wrote: > Hi, > > In my table, I have fieldA and fieldB. At any point in time, only one > of these fields can have data in it. The other is NULL. > > Instead of "select fieldA, fieldB from table", I want it to return > either fieldA or fieldB depends on whether it is NULL or not. > > The reason is because I want to use "select > array_to_string(array_accum(field A or field B) ,',') from table. > > Is it possible to do it that way? > > Thanks, > JB The two main ways of doing this are COALESCE(fieldA, fieldB) http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AEN14484 and CASE WHEN fieldA IS NULL THEN fieldB ELSE fieldA END; http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AEN14434
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера