Обсуждение: Don't want blank data

Поиск
Список
Период
Сортировка

Don't want blank data

От
David Olbersen
Дата:
Greetings, Is there a way to have postgresql always return a value for each row requested? To be more clear, if I were
usinga Perl SQL hybrid I would write something like
 
 SELECT computer_ip or 'unset' FROM computers;
 So that if computers.computer_ip is NULL or '' I will get 'unset' back from the database. I hope this makes sense and
somebodycan point me in a good direction
 

-- Dave



Re: Don't want blank data

От
Stephan Szabo
Дата:
On Thu, 25 Jan 2001, David Olbersen wrote:

> Greetings,
>   Is there a way to have postgresql always return a value for each row
>   requested? To be more clear, if I were using a Perl SQL hybrid I would write
>   something like
> 
>   SELECT computer_ip or 'unset' FROM computers;
> 
>   So that if computers.computer_ip is NULL or '' I will get 'unset' back from
>   the database. I hope this makes sense and somebody can point me in a good
>   direction

Perhaps:select case when computer_ip is null or computer_ip='' then 'unset'::text  else computer_ip end from
computers;

(the ::text should probably be whatever type computer_ip is)...



Re: Don't want blank data

От
"Oliver Elphick"
Дата:
David Olbersen wrote: >Greetings, >  Is there a way to have postgresql always return a value for each row >  requested?
Tobe more clear, if I were using a Perl SQL hybrid I would wri     >te >  something like > >  SELECT computer_ip or
'unset'FROM computers; > >  So that if computers.computer_ip is NULL or '' I will get 'unset' back fro     >m >  the
database.I hope this makes sense and somebody can point me in a good >  direction
 

SELECT COALESCE(computer_ip,'unset') AS computer_ip FROM computers;

COALESCE() returns the leftmost non-null value from its parameters.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
========================================   "My little children, let us not love in word, neither      in tongue; but in
deedand in truth."                                                     I John 3:18