case T_FieldSelect:
{
/*
- * FieldSelect is a special case because the field may have
- * a non-default collation, in which case we should use that.
- * The field's collation was already looked up and saved
- * in the node.
+ * For FieldSelect, the result has the field's declared
+ * collation, independently of what happened in the arguments.
+ * (The immediate argument must be composite and thus not
+ * collatable, anyhow.) The field's collation was already
+ * looked up and saved in the node.
*/
FieldSelect *expr = (FieldSelect *) node;
if (OidIsValid(expr->resultcollid))
{
/* Node's result type is collatable. */
- if (expr->resultcollid == DEFAULT_COLLATION_OID)
- {
- /*
- * The immediate input node necessarily yields a
- * composite type, so it will have no exposed
- * collation. However, if we are selecting a field
- * from a function returning composite, see if we
- * can bubble up a collation from the function's
- * input. XXX this is a bit of a hack, rethink ...
- */
- if (IsA(expr->arg, FuncExpr))
- {
- FuncExpr *fexpr = (FuncExpr *) expr->arg;
-
- if (OidIsValid(fexpr->inputcollid))
- expr->resultcollid = fexpr->inputcollid;
- }
- }
/* Pass up field's collation as an implicit choice. */
collation = expr->resultcollid;
strength = COLLATE_IMPLICIT;
fselect->fieldnum = i + 1;
fselect->resulttype = att->atttypid;
fselect->resulttypmod = att->atttypmod;
- /* resultcollid may get overridden by parse_collate.c */
+ /* save attribute's collation for parse_collate.c */
fselect->resultcollid = att->attcollation;
return (Node *) fselect;
}
fselect->fieldnum = i + 1;
fselect->resulttype = att->atttypid;
fselect->resulttypmod = att->atttypmod;
- /* resultcollid may get overridden by parse_collate.c */
+ /* save attribute's collation for parse_collate.c */
fselect->resultcollid = att->attcollation;
if (targetlist)
äbc
(4 rows)
-CREATE FUNCTION dup (f1 anyelement, f2 out anyelement, f3 out anyarray)
- AS 'select $1, array[$1,$1]' LANGUAGE sql;
-SELECT a, (dup(b)).* FROM collate_test1 ORDER BY 2;
- a | f2 | f3
----+-----+-----------
- 1 | abc | {abc,abc}
- 4 | ABC | {ABC,ABC}
- 2 | äbc | {äbc,äbc}
- 3 | bbc | {bbc,bbc}
-(4 rows)
-
-SELECT a, (dup(b)).* FROM collate_test2 ORDER BY 2;
- a | f2 | f3
----+-----+-----------
- 1 | abc | {abc,abc}
- 4 | ABC | {ABC,ABC}
- 3 | bbc | {bbc,bbc}
- 2 | äbc | {äbc,äbc}
-(4 rows)
-
-SELECT a, (dup(b)).* FROM collate_test3 ORDER BY 2;
- a | f2 | f3
----+-----+-----------
- 4 | ABC | {ABC,ABC}
- 1 | abc | {abc,abc}
- 3 | bbc | {bbc,bbc}
- 2 | äbc | {äbc,äbc}
+CREATE FUNCTION dup (anyelement) RETURNS anyelement
+ AS 'select $1' LANGUAGE sql;
+SELECT a, dup(b) FROM collate_test1 ORDER BY 2;
+ a | dup
+---+-----
+ 1 | abc
+ 4 | ABC
+ 2 | äbc
+ 3 | bbc
+(4 rows)
+
+SELECT a, dup(b) FROM collate_test2 ORDER BY 2;
+ a | dup
+---+-----
+ 1 | abc
+ 4 | ABC
+ 3 | bbc
+ 2 | äbc
+(4 rows)
+
+SELECT a, dup(b) FROM collate_test3 ORDER BY 2;
+ a | dup
+---+-----
+ 4 | ABC
+ 1 | abc
+ 3 | bbc
+ 2 | äbc
(4 rows)
-- indexes
bbc
(4 rows)
-CREATE FUNCTION dup (f1 anyelement, f2 out anyelement, f3 out anyarray)
- AS 'select $1, array[$1,$1]' LANGUAGE sql;
-SELECT a, (dup(b)).* FROM collate_test1 ORDER BY 2;
- a | f2 | f3
----+-----+-----------
- 4 | ABD | {ABD,ABD}
- 2 | Abc | {Abc,Abc}
- 1 | abc | {abc,abc}
- 3 | bbc | {bbc,bbc}
+CREATE FUNCTION dup (anyelement) RETURNS anyelement
+ AS 'select $1' LANGUAGE sql;
+SELECT a, dup(b) FROM collate_test1 ORDER BY 2;
+ a | dup
+---+-----
+ 4 | ABD
+ 2 | Abc
+ 1 | abc
+ 3 | bbc
(4 rows)
-SELECT a, (dup(b)).* FROM collate_test2 ORDER BY 2;
- a | f2 | f3
----+-----+-----------
- 4 | ABD | {ABD,ABD}
- 2 | Abc | {Abc,Abc}
- 1 | abc | {abc,abc}
- 3 | bbc | {bbc,bbc}
+SELECT a, dup(b) FROM collate_test2 ORDER BY 2;
+ a | dup
+---+-----
+ 4 | ABD
+ 2 | Abc
+ 1 | abc
+ 3 | bbc
(4 rows)
-- indexes
SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test2)) ORDER BY 1;
SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test3)) ORDER BY 1;
-CREATE FUNCTION dup (f1 anyelement, f2 out anyelement, f3 out anyarray)
- AS 'select $1, array[$1,$1]' LANGUAGE sql;
+CREATE FUNCTION dup (anyelement) RETURNS anyelement
+ AS 'select $1' LANGUAGE sql;
-SELECT a, (dup(b)).* FROM collate_test1 ORDER BY 2;
-SELECT a, (dup(b)).* FROM collate_test2 ORDER BY 2;
-SELECT a, (dup(b)).* FROM collate_test3 ORDER BY 2;
+SELECT a, dup(b) FROM collate_test1 ORDER BY 2;
+SELECT a, dup(b) FROM collate_test2 ORDER BY 2;
+SELECT a, dup(b) FROM collate_test3 ORDER BY 2;
-- indexes
SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test1)) ORDER BY 1;
SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test2)) ORDER BY 1;
-CREATE FUNCTION dup (f1 anyelement, f2 out anyelement, f3 out anyarray)
- AS 'select $1, array[$1,$1]' LANGUAGE sql;
+CREATE FUNCTION dup (anyelement) RETURNS anyelement
+ AS 'select $1' LANGUAGE sql;
-SELECT a, (dup(b)).* FROM collate_test1 ORDER BY 2;
-SELECT a, (dup(b)).* FROM collate_test2 ORDER BY 2;
+SELECT a, dup(b) FROM collate_test1 ORDER BY 2;
+SELECT a, dup(b) FROM collate_test2 ORDER BY 2;
-- indexes