Обсуждение: BUG #3116: attribute has wrong type
The following bug has been logged online: Bug reference: 3116 Logged by: Greg Sabino Mullane Email address: greg@turnstep.com PostgreSQL version: 8.1.8 Operating system: Linux Description: attribute has wrong type Details: Reproduced on 8.2.3, 8.1.8, and CVS HEAD: CREATE OR REPLACE FUNCTION gregtest(int) RETURNS varchar LANGUAGE sql AS $$ SELECT 'abc'::text; $$; -- Works: SELECT gregtest(123); -- Does not: SELECT boom FROM ( SELECT 123, gregtest(123) AS boom) AS tmp; ERROR: attribute 2 has wrong type DETAIL: TABLE has type text, but query expects character varying.
"Greg Sabino Mullane" <greg@turnstep.com> writes: > CREATE OR REPLACE FUNCTION gregtest(int) RETURNS varchar > LANGUAGE sql AS $$ SELECT 'abc'::text; $$; Hm, I'd argue that that should be rejected. SQL functions currently demand exact match between the declared return type and their final SELECT command ... wonder why this case is getting past? regards, tom lane
I wrote: > "Greg Sabino Mullane" <greg@turnstep.com> writes: >> CREATE OR REPLACE FUNCTION gregtest(int) RETURNS varchar >> LANGUAGE sql AS $$ SELECT 'abc'::text; $$; > Hm, I'd argue that that should be rejected. SQL functions currently > demand exact match between the declared return type and their final > SELECT command ... wonder why this case is getting past? Nah, I stand corrected: /* * For base-type returns, the target list should have exactly one * entry, and its type should agree with what the user declared. (As * of Postgres 7.2, we accept binary-compatible types too.) */ On reflection I think the problem is that inline_function() is inserting the function's expression and not adding a RelabelType node to make sure that the rebuilt expression still returns exactly the type the function claims to return. Will fix. regards, tom lane