Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d59643

Browse files
committed
Account for collation when coercing the output of a SQL function.
Commit913bbd8 overlooked that the result of coerce_to_target_typemight need collation fixups. Per report from Andreas Joseph Krogh.Discussion:https://postgr.es/m/VisenaEmail.72.37d08ec2b8cb8fb5.17179940cd3@tc7-visena
1 parent0516f94 commit2d59643

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

‎src/backend/executor/functions.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include"nodes/makefuncs.h"
2525
#include"nodes/nodeFuncs.h"
2626
#include"parser/parse_coerce.h"
27+
#include"parser/parse_collate.h"
2728
#include"parser/parse_func.h"
2829
#include"storage/proc.h"
2930
#include"tcop/utility.h"
@@ -1989,6 +1990,7 @@ coerce_fn_result_column(TargetEntry *src_tle,
19891990
-1);
19901991
if (cast_result==NULL)
19911992
return false;
1993+
assign_expr_collations(NULL,cast_result);
19921994
src_tle->expr= (Expr*)cast_result;
19931995
/* Make a Var referencing the possibly-modified TLE */
19941996
new_tle_expr= (Expr*)makeVarFromTargetEntry(1,src_tle);
@@ -2007,6 +2009,7 @@ coerce_fn_result_column(TargetEntry *src_tle,
20072009
-1);
20082010
if (cast_result==NULL)
20092011
return false;
2012+
assign_expr_collations(NULL,cast_result);
20102013
/* Did the coercion actually do anything? */
20112014
if (cast_result!= (Node*)var)
20122015
*upper_tlist_nontrivial= true;

‎src/test/regress/expected/collate.out

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,18 @@ SELECT a, CAST(b AS varchar) FROM collate_test2 ORDER BY 2;
536536
3 | bbc
537537
(4 rows)
538538

539+
-- result of a SQL function
540+
CREATE FUNCTION vc (text) RETURNS text LANGUAGE sql
541+
AS 'select $1::varchar';
542+
SELECT a, b FROM collate_test1 ORDER BY a, vc(b);
543+
a | b
544+
---+-----
545+
1 | abc
546+
2 | Abc
547+
3 | bbc
548+
4 | ABD
549+
(4 rows)
550+
539551
-- polymorphism
540552
SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test1)) ORDER BY 1;
541553
unnest
@@ -682,7 +694,7 @@ SELECT collation for ((SELECT b FROM collate_test1 LIMIT 1));
682694
-- must get rid of them.
683695
--
684696
DROP SCHEMA collate_tests CASCADE;
685-
NOTICE: drop cascades to17 other objects
697+
NOTICE: drop cascades to18 other objects
686698
DETAIL: drop cascades to table collate_test1
687699
drop cascades to table collate_test_like
688700
drop cascades to table collate_test2
@@ -694,6 +706,7 @@ drop cascades to view collview1
694706
drop cascades to view collview2
695707
drop cascades to view collview3
696708
drop cascades to type testdomain
709+
drop cascades to function vc(text)
697710
drop cascades to function dup(anyelement)
698711
drop cascades to table collate_test20
699712
drop cascades to table collate_test21

‎src/test/regress/sql/collate.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ SELECT a, CAST(b AS varchar) FROM collate_test1 ORDER BY 2;
177177
SELECT a, CAST(bASvarchar)FROM collate_test2ORDER BY2;
178178

179179

180+
-- result of a SQL function
181+
182+
CREATEFUNCTIONvc (text) RETURNStext LANGUAGE sql
183+
AS'select $1::varchar';
184+
185+
SELECT a, bFROM collate_test1ORDER BY a, vc(b);
186+
187+
180188
-- polymorphism
181189

182190
SELECT*FROM unnest((SELECT array_agg(bORDER BY b)FROM collate_test1))ORDER BY1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp