diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2021-02-27 08:11:14 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2021-02-27 08:13:24 +0100 |
commit | f4adc41c4f92cc91d507b19e397140c35bb9fd71 (patch) | |
tree | 387b6ecdd5e9b4547d887b73f01689aa954f177d /src/backend/utils/adt/ruleutils.c | |
parent | 4e90052c46c7751779ed83627676ed5e74ebe6d4 (diff) | |
download | postgresql-f4adc41c4f92cc91d507b19e397140c35bb9fd71.tar.gz postgresql-f4adc41c4f92cc91d507b19e397140c35bb9fd71.zip |
Enhanced cycle mark values
Per SQL:202x draft, in the CYCLE clause of a recursive query, the
cycle mark values can be of type boolean and can be omitted, in which
case they default to TRUE and FALSE.
Reviewed-by: Vik Fearing <vik@postgresfriends.org>
Discussion: https://www.postgresql.org/message-id/flat/db80ceee-6f97-9b4a-8ee8-3ba0c58e5be2@2ndquadrant.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 4a9244f4f66..879288c1394 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -5208,10 +5208,21 @@ get_with_clause(Query *query, deparse_context *context) } appendStringInfo(buf, " SET %s", quote_identifier(cte->cycle_clause->cycle_mark_column)); - appendStringInfoString(buf, " TO "); - get_rule_expr(cte->cycle_clause->cycle_mark_value, context, false); - appendStringInfoString(buf, " DEFAULT "); - get_rule_expr(cte->cycle_clause->cycle_mark_default, context, false); + + { + Const *cmv = castNode(Const, cte->cycle_clause->cycle_mark_value); + Const *cmd = castNode(Const, cte->cycle_clause->cycle_mark_default); + + if (!(cmv->consttype == BOOLOID && !cmv->constisnull && DatumGetBool(cmv->constvalue) == true && + cmd->consttype == BOOLOID && !cmd->constisnull && DatumGetBool(cmd->constvalue) == false)) + { + appendStringInfoString(buf, " TO "); + get_rule_expr(cte->cycle_clause->cycle_mark_value, context, false); + appendStringInfoString(buf, " DEFAULT "); + get_rule_expr(cte->cycle_clause->cycle_mark_default, context, false); + } + } + appendStringInfo(buf, " USING %s", quote_identifier(cte->cycle_clause->cycle_path_column)); } |