BUG #13909: String concat error with CITEXT after 9.5.0 upgrade.

Lists: pgsql-bugs
From: hein(at)bitechsystems(dot)co(dot)za
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #13909: String concat error with CITEXT after 9.5.0 upgrade.
Date: 2016-02-03 15:17:23
Message-ID: 20160203151723.2768.51719@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 13909
Logged by: Hein
Email address: hein(at)bitechsystems(dot)co(dot)za
PostgreSQL version: 9.5.0
Operating system: Windows 10 / Linux
Description:

After upgrading to 9.5 with a new database, concatenation of a citext and a
function that returns citext does not work. It gives a syntax error.

Code to duplicate, requires citext extension:

CREATE OR REPLACE FUNCTION isnull(
p_value citext
,p_replacevalue citext = ''
)
RETURNS citext
AS $$
select case when p_value is null then p_replacevalue else p_value end
$$ LANGUAGE sql IMMUTABLE COST 1;

DO
$$
DECLARE
m_text citext;
BEGIN
m_text = 'test' || isnull(m_text,''); --code breaks here!
--raise notice '%', isnull(m_text);
END;
$$ LANGUAGE plpgsql ;


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hein(at)bitechsystems(dot)co(dot)za
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13909: String concat error with CITEXT after 9.5.0 upgrade.
Date: 2016-02-04 17:54:56
Message-ID: 22439.1454608496@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg토토 캔SQL : Postg토토 캔SQL 메일 링리스트 : 2016-02-04 이후 PGSQL-BUGS 17:54

hein(at)bitechsystems(dot)co(dot)za writes:
> m_text = 'test' || isnull(m_text,''); --code breaks here!

ISNULL is a keyword, which I can't really recommend using as a function
name. This example used to accidentally fail to fail before 9.5 because
ISNULL was considered to bind tighter than ||. But now it binds less
tightly, meaning that the first part of the expression is parsed as
(('test' ||) IS NULL), which is not what you meant.

You could fix this with more parentheses:

m_text = 'test' || (isnull(m_text,''));

or by double-quoting the function name so it doesn't look like a keyword:

m_text = 'test' || "isnull"(m_text,'');

but you might be better advised to rename the function.

regards, tom lane