From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
---|---|
To: | jg <jg(at)rilk(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Coalesce bug ? |
Date: | 2012-12-21 15:26:31 |
Message-ID: | 50D47FA7.60900@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 12/21/2012 07:03 AM, jg wrote:
> Hi,
>
> In PostgreSQL 9.2, I have the following behavior, and I found it strange.
>
> ps3 is executed or "never executed" ? !!!
>
> JG
>
> [postgres(at)]test=# create or replace function ps3(a int) returns int as $$ BEGIN
> RAISE WARNING 'Call ps3(%)=%',$1,$1; RETURN $1::int;
> END; $$ LANGUAGE plpgsql STRICT IMMUTABLE;
> CREATE FUNCTION
> Temps : 22,632 ms
> [postgres(at)]test=# select coalesce( (select ps3(1)), (SELECT ps3(2)) );
> WARNING: Call ps3(1)=1
> WARNING: Call ps3(2)=2
> coalesce
> ----------
> 1
> (1 ligne)
>
> Temps : 0,692 ms
> [postgres(at)]test=# select coalesce( ps3(1), ps3(2) );
> WARNING: Call ps3(1)=1
> coalesce
> ----------
> 1
> (1 ligne)
>
> Temps : 0,441 ms
Well I believe there is no bug.
In the first case the nested parentheses mean the SELECT statements are
run first and the COALESCE is run on the return results.
In the second case COALESCE is working as advertised. Working left to
right it finds the first non NULL argument and stops.
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | jg | 2012-12-21 15:26:33 | Re: Coalesce bug ? |
Previous Message | David Johnston | 2012-12-21 15:25:29 | Re: Coalesce bug ? |