ERROR: could not determine which collation to use for view column

From: Rahila Syed <rahilasyed90(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: ERROR: could not determine which collation to use for view column
Date: 2016-10-15 22:17:24
Message-ID: CAH2L28vNm1cSCwyf-s_ZhQFxsAu+PbF+QW7rKL1Ur_iSZkAE1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Following error occurs while creating a view as UNION of two views with
UNKNOWN columns.

create table test_tb1(i int, j varchar);
create table test_tb2(j int, k varchar);
create or replace view v_test1(i,j,lit) AS SELECT a.j "i" ,a.k "j", ''
"lit" from test_tb2 a;
create or replace view v_test(i,j,lit) AS SELECT a.i "i" ,a.j "j", '' "lit"
from test_tb1 a;
create or replace view v_test_merge(i,j,lit) AS SELECT i,j,lit from v_test
UNION ALL SELECT i,j,lit from v_test1;

ERROR: could not determine which collation to use for view column "lit"
HINT: Use the COLLATE clause to set the collation explicitly.

The error occurs when a target list with column type as TEXT and collation
as InvalidOid is used to create a view.

In transformSetOperationTree, when a targetlist is formed from UNION of two
SELECTs,
the resultant column type is coerced to TEXT when both the columns are
UNKNOWN. But the resultant column collation of such UNKNOWN columns remain
InvalidOid
This is because the original columns types are not coerced to TEXT only
resultant type is. Hence original column types remain UNKNOWN while
determining the resultant collation.

When such target list with a column of type TEXT and collation as
InvalidOid is used while creating a view
in DefineVirtualRelation it throws error because the column type is
collatable but it does not have a collation assigned.

Shouldn’t the resultant collation be assigned value corresponding to TEXT
datatype and not UNKNOWN datatype in this case? i.e some valid value and
not InvalidOid.

Thank you,
Rahila Syed

Browse pgsql-bugs by date

  From Date Subject
Next Message Yuriy Tereshchuk 2016-10-16 00:15:38 Issue in pg_update
Previous Message John R Pierce 2016-10-15 08:47:40 Re: Installation Issue