agora inbox for pgsql-bugs@postgresql.org  
help / color / mirror / Atom feed
From: zengman <zengman@halodbtech.com>
To: 曾满 <zengman@halodbtech.com>
To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re:BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false'
Date: Mon, 17 Aug 2026 22:09:41 +0800
Message-ID: <tencent_0AAF798D129E099858B151E9@qq.com> (raw)
In-Reply-To: <19625-683b498c92087bc8@postgresql.org>
References: <19625-683b498c92087bc8@postgresql.org>

Hi,

The formatting above seems a bit messed up, so I am re-attaching the diff file.

--
Regards,
Man Zeng

Attachments:

  [application/octet-stream] json-bool-default-fix.patch (1.3K, ../tencent_0AAF798D129E099858B151E9@qq.com/2-json-bool-default-fix.patch)
  download | inline diff:
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 30c889f505f..175b3d3ee69 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -4956,20 +4956,17 @@ transformJsonBehavior(ParseState *pstate, JsonExpr *jsexpr,
 			coerce_at_runtime = true;
 
 			/*
-			 * json_populate_type() expects to be passed a jsonb value, so gin
-			 * up a Const containing the appropriate boolean value represented
-			 * as jsonb, discarding the original Const containing a plain
-			 * boolean.
+			 * json_populate_type() only takes a jsonb value, so convert a
+			 * boolean to jsonb by calling to_jsonb() on it.  That way any
+			 * boolean-valued expression -- whether a canned TRUE/FALSE
+			 * constant or a user-supplied DEFAULT expression -- is converted
+			 * according to the value it actually evaluates to.
 			 */
 			if (exprType(expr) == BOOLOID)
-			{
-				char	   *val = btype == JSON_BEHAVIOR_TRUE ? "true" : "false";
-
-				expr = (Node *) makeConst(JSONBOID, -1, InvalidOid, -1,
-										  DirectFunctionCall1(jsonb_in,
-															  CStringGetDatum(val)),
-										  false, false);
-			}
+				expr = (Node *) makeFuncExpr(F_TO_JSONB, JSONBOID,
+											 list_make1(expr),
+											 InvalidOid, InvalidOid,
+											 COERCE_EXPLICIT_CALL);
 		}
 		else
 		{


view thread (3+ messages)  latest in thread

Message-ID: <tencent_0AAF798D129E099858B151E9@qq.com>
Permalink:  ../tencent_0AAF798D129E099858B151E9@qq.com/
Also on:    postgresql.org/message-id/tencent_0AAF798D129E099858B151E9@qq.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: zengman@halodbtech.com, pgsql-bugs@lists.postgresql.org
  Subject: Re:BUG #19625: SQL/JSON boolean DEFAULT expression silently replaced with 'false'
  In-Reply-To: <tencent_0AAF798D129E099858B151E9@qq.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox