Search Postgresql Archives

Re: Specifying text to substitute for NULLs in selects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 07 Nov 2008 15:20:24 -0500
Said Ramirez <sramirez@xxxxxxxxxx> wrote:

> I think you are more after something like
> 
> SELECT CASE WHEN foo IS NULL THEN 'NA' END FROM bar.

missing an else at least and...

wtw_drupal=# create table test.test(c1 int);
CREATE TABLE
wtw_drupal=# insert into test.test values(null);
INSERT 0 1
wtw_drupal=# insert into test.test values(1);
INSERT 0 1
wtw_drupal=# \copy (select case when c1 is null then 'NA' else c1
end from test.test) to stdout ERROR:  invalid input syntax for
integer: "NA" \copy: ERROR:  invalid input syntax for integer: "NA"

furthermore... even if c1 was text you may end up in output like:
'NA'
that will be hard to be discerned from a "normal" string.

BTW I just discovered that COPY doesn't work on view.

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux