BUG #17137: Bug with datatypes definition in CTE - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17137: Bug with datatypes definition in CTE
Date
Msg-id 17137-3d3732d5a259612c@postgresql.org
Whole thread Raw
Responses Re: BUG #17137: Bug with datatypes definition in CTE  (Bruce Momjian <bruce@momjian.us>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17137
Logged by:          Alex Zhuravlev
Email address:      alexone07@mail.ru
PostgreSQL version: 13.3
Operating system:   Red Hat 8.4.1-1, 64-bit
Description:

SQL expression doesn't execute with error:
SQL Error [42804]: ERROR: recursive query "t" column 1 has type character
varying(20) in non-recursive term but type character varying overall
  Help: Cast the output of the non-recursive term to the correct type.

*But it works with text datatype.

Some repro's:
First:
WITH RECURSIVE t AS (
SELECT a::varchar AS b
  FROM (
       SELECT 'a'::varchar(20) AS a
       ) AS x
UNION ALL
SELECT 'a'::varchar AS b
  FROM t
)
SELECT *
  FROM t;

The Second:
CREATE TABLE tm1(a varchar(20)); SELECT a, a::varchar FROM tm1 \gdesc

The third:
CREATE TABLE t(n) AS SELECT '5.5'::numeric(20, 2); SELECT n::numeric FROM t
\gdesc

https://dbfiddle.uk/?rdbms=postgres_13&fiddle=c3bfe57c351cc783399fad539d5690d0


pgsql-bugs by date:

Previous
From: Andrey Borodin
Date:
Subject: Re: CREATE INDEX CONCURRENTLY does not index prepared xact's data
Next
From: "David G. Johnston"
Date:
Subject: CAST from numeric(18,3) to numeric doesnt work, posgresql 13.3