union bug - Mailing list pgsql-bugs

From Ivan
Subject union bug
Date
Msg-id 246467369.20051019181203@mail.ru
Whole thread Raw
Responses Re: union bug
List pgsql-bugs
Hello,

PostgreSQL 8.1beta3 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.4.2 (mingw-special)
Windows XP SP2

The following query

CREATE DOMAIN test_domain
  AS varchar(64)
  NOT NULL;

CREATE TYPE test_type AS
   ("Id" int4,
    "Data" test_domain);

CREATE OR REPLACE FUNCTION union_test()
  RETURNS SETOF test_type AS
$BODY$
    select 1 as "Id", 'string1'::test_domain as "Data"
    union all
    select 2 as "Id", 'string2'::test_domain as "Data"
$BODY$
  LANGUAGE 'sql' VOLATILE;

generates error message

ERROR:  return type mismatch in function declared to return test_type
DETAIL:  Final SELECT returns character varying instead of test_domain at column 2.
CONTEXT:  SQL function "union_test"

but this one is not

CREATE OR REPLACE FUNCTION union_test2()
  RETURNS SETOF test_type AS
$BODY$
  select "Id"::int4, "Data"::test_domain
  from (
    select 1 as "Id", 'string1' as "Data"
    union all
    select 2 as "Id", 'string2' as "Data"
    ) as q1;
$BODY$
  LANGUAGE 'sql' VOLATILE;

--
Best regards,
 Ivan                          mailto:Ivan-Sun1@mail.ru

pgsql-bugs by date:

Previous
From: "Stanislav Sukholet"
Date:
Subject: BUG #1976: steps to reproduce BUG #1438: Non UTF-8 client encoding problem
Next
From: Richard Huxton
Date:
Subject: Function taking compound type defined on a view with ORDER BY