Re: NULL values and string

From: Richard Huxton <dev(at)archonet(dot)com>
To: Sergey Karin <sergey(dot)karin(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: NULL values and string
Date: 2006-02-02 11:02:21
Message-ID: 43E1E6BD.4030109@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sergey Karin wrote:
> Hi, List!
>
> I'm using PG8.1.
>
> Are there any abilities to represent NULL values as string?

Null isn't a real value. Try not to think of it as a value.

http://archives.postgresql.org/pgsql-sql/2003-01/msg00222.php

> num_value alias for $1;

> string_value := \'input value = \' || num_value;

> If I einvoke my function with NULL argument, it return NULL. But I want
> 'input value = NULL'.

Because NULL means unknown. A string with an unknown string appended to
it is itself unknown.

> Of course, I can check input value like this:
>
> if(num_value isnull) then
> string_value := \'input value = NULL\';
> else
> string_value := \'input_value = \' || num_value;
> end if;
>
> But it is not laconic...

Try something like:
string_value := ''input_value = '' || COALESCE(num_value, 'a null');

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Silas Justiniano 2006-02-02 12:08:53 Indexes again
Previous Message Tino Wildenhain 2006-02-02 10:59:04 Re: NULL values and string