Re: string || NULL ambiguity

From: "Thomas T(dot) Thai" <tom(at)minnesota(dot)com>
To: <neilc(at)samurai(dot)com>
Cc: <oleg(at)sai(dot)msu(dot)su>, <alvherre(at)dcc(dot)uchile(dot)cl>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: string || NULL ambiguity
Date: 2003-03-20 09:08:54
Message-ID: 4266.63.226.186.156.1048151334.squirrel@mail.minnesota.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>> On Wed, 2003-03-19 at 20:32, Oleg Bartunov wrote:
>>> On Wed, 19 Mar 2003, Alvaro Herrera wrote:
>>> > stringA||COALESCE(NULL, '')
>>> >
>>>
>>> we don't know in advance if it's NULL or not.
>>
>> Right, that's the point of COALESCE: the first non-NULL argument is
>> returned -- so if the first argument to COALESCE happens to be
>> non-NULL, COALESCE has no effect.
>
> I tried this with a txtidx column type:
>
> tsearch=# select coalesce(NULL,'');
> case
> ------
>
> (1 row)
>
> tsearch=# select coalesce(NULL,'hi');
> case
> ------
> hi
> (1 row)
>
> tsearch=# select title_fts from article;
> title_fts
> ----------------------------------
> '2':3A 'tsearch':1A 'version':2A
> 'easi':1A 'implement':2A
>
> (3 rows)
>
> tsearch=# select coalesce('',title_fts) from article;
> ERROR: Void value
> tsearch=# select coalesce('hi',title_fts) from article;
> case
> ------
> 'hi'
> 'hi'
> 'hi'
> (3 rows)
>
> ---

Sorry the above should have been:

tsearch=# select coalesce(title_fts, '') from article;
ERROR: Void value
tsearch=# select coalesce(title_fts, 'hi') from article;
case
----------------------------------
'2':3A 'tsearch':1A 'version':2A
'easi':1A 'implement':2A
'hi'
(3 rows)

> Note the error: "ERROR: Void value" above. Why is that happening?
>
> --
> Thomas
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kris Jurka 2003-03-20 11:09:52 Re: Open 7.4 features
Previous Message Thomas T. Thai 2003-03-20 08:34:21 Re: string || NULL ambiguity