Re: Specifying text to substitute for NULLs in selects

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Specifying text to substitute for NULLs in selects
Date: 2008-11-07 20:11:33
Message-ID: 20081107211133.07cb721a@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 6 Nov 2008 17:44:42 -0800 (PST)
pcreso(at)pcreso(dot)com wrote:

>
> Hi,
>
> I can specify the text used to represent a null value in output
> from copy, but I'd like to do something similar is select output,
> eg: all NULL values are represented by NA or NaN.
>
> I can't find anything in the docs about this.
>
> This could be managed using case statements around all the columns
> in the query, but is there a simpler way, like setting a system
> variable to specify this?

wtw_drupal=# create schema test;
CREATE SCHEMA
wtw_drupal=# create table test.test(c1 text);
CREATE TABLE
wtw_drupal=# insert into test.test values(null);
INSERT 0 1
wtw_drupal=# insert into test.test values('test');
INSERT 0 1
wtw_drupal=# \copy test.test to stdout null as 'BANANA'
BANANA
test
wtw_drupal=# drop schema test cascade;
NOTICE: drop cascades to table test.test
DROP SCHEMA

everything clearly explained in the COPY manual:
http://www.postgresql.org/docs/8.1/static/sql-copy.html

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Said Ramirez 2008-11-07 20:20:24 Re: Specifying text to substitute for NULLs in selects
Previous Message Dennis Brakhane 2008-11-07 19:45:01 Re: INSERT .... RETURNING