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

Commita711b36

Browse files
committed
Fix under-parenthesized display of AT TIME ZONE constructs.
In commit40c24bf, I forgot to use get_rule_expr_paren() for thearguments of AT TIME ZONE, resulting in possibly not printing parensfor expressions that need it. But get_rule_expr_paren() wouldn't havegotten it right anyway, because isSimpleNode() hadn't been taught thatCOERCE_SQL_SYNTAX parent nodes don't guarantee sufficient parentheses.Improve all that. Also use this methodology for F_IS_NORMALIZED, sothat we don't print useless parens for that.In passing, remove a comment that was obsoleted later.Per report from Duncan Sands. Back-patch to v14 where this codecame in. (Before that, we didn't try to print AT TIME ZONE that way,so there was no bug just ugliness.)Discussion:https://postgr.es/m/f41566aa-a057-6628-4b7c-b48770ecb84a@deepbluecap.com
1 parentf79cca5 commita711b36

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8290,11 +8290,12 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
82908290
{
82918291
caseT_FuncExpr:
82928292
{
8293-
/* special handling for casts */
8293+
/* special handling for castsand COERCE_SQL_SYNTAX*/
82948294
CoercionFormtype= ((FuncExpr*)parentNode)->funcformat;
82958295

82968296
if (type==COERCE_EXPLICIT_CAST||
8297-
type==COERCE_IMPLICIT_CAST)
8297+
type==COERCE_IMPLICIT_CAST||
8298+
type==COERCE_SQL_SYNTAX)
82988299
return false;
82998300
return true;/* own parentheses */
83008301
}
@@ -8342,11 +8343,12 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
83428343
return false;
83438344
caseT_FuncExpr:
83448345
{
8345-
/* special handling for casts */
8346+
/* special handling for castsand COERCE_SQL_SYNTAX*/
83468347
CoercionFormtype= ((FuncExpr*)parentNode)->funcformat;
83478348

83488349
if (type==COERCE_EXPLICIT_CAST||
8349-
type==COERCE_IMPLICIT_CAST)
8350+
type==COERCE_IMPLICIT_CAST||
8351+
type==COERCE_SQL_SYNTAX)
83508352
return false;
83518353
return true;/* own parentheses */
83528354
}
@@ -10117,9 +10119,11 @@ get_func_sql_syntax(FuncExpr *expr, deparse_context *context)
1011710119
caseF_TIMEZONE_TEXT_TIMETZ:
1011810120
/* AT TIME ZONE ... note reversed argument order */
1011910121
appendStringInfoChar(buf,'(');
10120-
get_rule_expr((Node*)lsecond(expr->args),context, false);
10122+
get_rule_expr_paren((Node*)lsecond(expr->args),context, false,
10123+
(Node*)expr);
1012110124
appendStringInfoString(buf," AT TIME ZONE ");
10122-
get_rule_expr((Node*)linitial(expr->args),context, false);
10125+
get_rule_expr_paren((Node*)linitial(expr->args),context, false,
10126+
(Node*)expr);
1012310127
appendStringInfoChar(buf,')');
1012410128
return true;
1012510129

@@ -10171,9 +10175,10 @@ get_func_sql_syntax(FuncExpr *expr, deparse_context *context)
1017110175

1017210176
caseF_IS_NORMALIZED:
1017310177
/* IS xxx NORMALIZED */
10174-
appendStringInfoString(buf,"((");
10175-
get_rule_expr((Node*)linitial(expr->args),context, false);
10176-
appendStringInfoString(buf,") IS");
10178+
appendStringInfoString(buf,"(");
10179+
get_rule_expr_paren((Node*)linitial(expr->args),context, false,
10180+
(Node*)expr);
10181+
appendStringInfoString(buf," IS");
1017710182
if (list_length(expr->args)==2)
1017810183
{
1017910184
Const*con= (Const*)lsecond(expr->args);
@@ -10194,11 +10199,6 @@ get_func_sql_syntax(FuncExpr *expr, deparse_context *context)
1019410199
appendStringInfoChar(buf,')');
1019510200
return true;
1019610201

10197-
/*
10198-
* XXX EXTRACT, a/k/a date_part(), is intentionally not covered
10199-
* yet. Add it after we change the return type to numeric.
10200-
*/
10201-
1020210202
caseF_NORMALIZE:
1020310203
/* NORMALIZE() */
1020410204
appendStringInfoString(buf,"NORMALIZE(");

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,7 @@ select pg_get_viewdef('tt20v', true);
19221922
-- reverse-listing of various special function syntaxes required by SQL
19231923
create view tt201v as
19241924
select
1925+
('2022-12-01'::date + '1 day'::interval) at time zone 'UTC' as atz,
19251926
extract(day from now()) as extr,
19261927
(now(), '1 day'::interval) overlaps
19271928
(current_timestamp(2), '1 day'::interval) as o,
@@ -1944,10 +1945,11 @@ select
19441945
select pg_get_viewdef('tt201v', true);
19451946
pg_get_viewdef
19461947
-----------------------------------------------------------------------------------------------
1947-
SELECT EXTRACT(day FROM now()) AS extr, +
1948+
SELECT (('12-01-2022'::date + '@ 1 day'::interval) AT TIME ZONE 'UTC'::text) AS atz, +
1949+
EXTRACT(day FROM now()) AS extr, +
19481950
((now(), '@ 1 day'::interval) OVERLAPS (CURRENT_TIMESTAMP(2), '@ 1 day'::interval)) AS o,+
1949-
(('foo'::text) IS NORMALIZED) AS isn, +
1950-
(('foo'::text) IS NFKC NORMALIZED) AS isnn, +
1951+
('foo'::text IS NORMALIZED) AS isn, +
1952+
('foo'::text IS NFKC NORMALIZED) AS isnn, +
19511953
NORMALIZE('foo'::text) AS n, +
19521954
NORMALIZE('foo'::text, NFKD) AS nfkd, +
19531955
OVERLAY('foo'::text PLACING 'bar'::text FROM 2) AS ovl, +

‎src/test/regress/sql/create_view.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ select pg_get_viewdef('tt20v', true);
703703

704704
createviewtt201vas
705705
select
706+
('2022-12-01'::date+'1 day'::interval) attime zone'UTC'as atz,
706707
extract(dayfrom now())as extr,
707708
(now(),'1 day'::interval) overlaps
708709
(current_timestamp(2),'1 day'::interval)as o,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp