BUG #8228: Unexpected "set-valued function" with varchar(n) but not varchar

From: david(dot)g(dot)johnston(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #8228: Unexpected "set-valued function" with varchar(n) but not varchar
Date: 2013-06-13 19:10:50
Message-ID: E1UnCv4-0007oF-Bo@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 8228
Logged by: David Johnston
Email address: david(dot)g(dot)johnston(at)gmail(dot)com
PostgreSQL version: 9.0.13
Operating system: Ubuntu Linux 10.04
Description:

The following query results in "SQL Error: ERROR: set-valued function called
in context that cannot accept a set"

SELECT *, CASE WHEN id = 2 THEN
(regexp_matches(input_string,'^0*([1-9]\d+)$'))[1] ELSE input_string
END::varchar(30) AS o_l2_a
FROM (
VALUES (1,''), (2,'0000000049404'),(3,'FROM 10000000876')
) l0_src (id, input_string)

The nearly identical query:

SELECT *, CASE WHEN id = 2 THEN
(regexp_matches(input_string,'^0*([1-9]\d+)$'))[1] ELSE input_string
END::varchar AS o_l2_a
FROM (
VALUES (1,''), (2,'0000000049404'),(3,'FROM 10000000876')
) l0_src (id, input_string)

returns 3 records as expected.

The only difference is that the cast at the end of the case construct uses
"varchar(30)" in the failure situation but a plain "varchar" in the
successful situation.

version
PostgreSQL 9.0.13 on x86_64-unknown-linux-gnu, compiled by GCC gcc-4.4.real
(Ubuntu 4.4.3-4ubuntu5) 4.4.3, 64-bit

Using "substring(CASE ... END::varchar,1,30)" also results in the
"set-valued function" error message.

David J.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Joshua Berry 2013-06-13 19:30:32 Re: [ODBC] Segmentation Fault in Postgres server when using psqlODBC
Previous Message Tom Lane 2013-06-13 17:16:06 Re: [ODBC] Segmentation Fault in Postgres server when using psqlODBC