Skip to content

Commit f104cc5

Browse files
author
Nikita Glukhov
committed
Rename GUC json_as_jsonb to sql_json
1 parent 31501d1 commit f104cc5

File tree

9 files changed

+45
-27
lines changed

9 files changed

+45
-27
lines changed

doc/src/sgml/config.sgml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9510,19 +9510,20 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
95109510
</listitem>
95119511
</varlistentry>
95129512

9513-
<varlistentry id="guc-json-as-jsonb" xreflabel="json_as_jsonb">
9514-
<term><varname>json_as_jsonb</varname> (<type>boolean</type>)
9513+
<varlistentry id="guc-sql-json" xreflabel="sql_json">
9514+
<term><varname>sql_json</varname> (<type>enum</type>)
95159515
<indexterm><primary>json</primary></indexterm>
95169516
<indexterm><primary>jsonb</primary></indexterm>
95179517
<indexterm>
9518-
<primary><varname>json_as_jsonb</varname> configuration parameter</primary>
9518+
<primary><varname>sql_json</varname> configuration parameter</primary>
95199519
</indexterm>
95209520
</term>
95219521
<listitem>
95229522
<para>
9523-
When on, SQL type <type>JSON</type> is mapped to
9524-
<productname>PostgreSQL</productname> type <type>jsonb</type>.
9525-
But SQL type <type>JSON TEXT</type> is always mapped to
9523+
Valid values are <literal>json</literal> and <literal>jsonb</literal>.
9524+
Specifies what <productname>PostgreSQL</productname> type is used
9525+
as an implementation of SQL type <type>JSON</type>.
9526+
SQL type <type>JSON TEXT</type> is always mapped to
95269527
<productname>PostgreSQL</productname> type <type>json</type>.
95279528
</para>
95289529
</listitem>

src/backend/parser/gram.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12940,7 +12940,7 @@ interval_second:
1294012940
JsonType:
1294112941
JSON
1294212942
{
12943-
$$ = SystemTypeName(json_as_jsonb ? "jsonb" : "json");
12943+
$$ = SystemTypeName(SQLJSON_TYPE_NAME());
1294412944
$$->location = @1;
1294512945
}
1294612946
| JSON TEXT_P
@@ -13644,7 +13644,7 @@ c_expr: columnref { $$ = $1; }
1364413644
}
1364513645
| JSON '(' a_expr ')'
1364613646
{
13647-
List *typname = list_make1(makeString(json_as_jsonb ? "jsonb" : "json"));
13647+
List *typname = list_make1(makeString(SQLJSON_TYPE_NAME()));
1364813648

1364913649
$$ = (Node *) makeFuncCall(typname, list_make1($3), COERCE_EXPLICIT_CALL, @1);
1365013650
}

src/backend/utils/adt/format_type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
297297
break;
298298

299299
case JSONBOID:
300-
buf = pstrdup(json_as_jsonb ? "json" : "jsonb");
300+
buf = pstrdup(SQLJSON_TYPE_IS_JSONB() ? "json" : "jsonb");
301301
break;
302302

303303
case JSONOID:
304-
buf = pstrdup(json_as_jsonb ? "json text" : "json");
304+
buf = pstrdup(SQLJSON_TYPE_IS_JSONB() ? "json text" : "json");
305305
break;
306306
}
307307

src/backend/utils/adt/jsonb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static char *JsonbToCStringWorker(StringInfo out, JsonbContainer *in,
100100
int estimated_len, JsonFormat format);
101101
static void add_indent(StringInfo out, bool indent, int level);
102102

103-
bool json_as_jsonb; /* GUC for mapping jsonb to SQL/JSON JSON */
103+
int sql_json_type; /* GUC for mapping jsonb to SQL/JSON JSON */
104104

105105
/*
106106
* jsonb type input function

src/backend/utils/misc/guc.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@ static struct config_enum_entry shared_memory_options[] = {
499499
{NULL, 0, false}
500500
};
501501

502+
const struct config_enum_entry sql_json_type_info[] = {
503+
{"json", SQLJSON_TYPE_JSON, false},
504+
{"jsonb", SQLJSON_TYPE_JSONB, false},
505+
{NULL, 0, false}
506+
};
507+
502508
/*
503509
* Options for enum values stored in other modules
504510
*/
@@ -2037,17 +2043,6 @@ static struct config_bool ConfigureNamesBool[] =
20372043
NULL, NULL, NULL
20382044
},
20392045

2040-
{
2041-
{"json_as_jsonb", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
2042-
gettext_noop("Use jsonb type as default implementation of SQL JSON type."),
2043-
gettext_noop("When turned on, jsonb type is mapped to SQL JSON type, "
2044-
"json type is mapped to JSON TEXT type.")
2045-
},
2046-
&json_as_jsonb,
2047-
false,
2048-
NULL, NULL, NULL
2049-
},
2050-
20512046
/* End-of-list marker */
20522047
{
20532048
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
@@ -4796,6 +4791,17 @@ static struct config_enum ConfigureNamesEnum[] =
47964791
NULL, NULL, NULL
47974792
},
47984793

4794+
{
4795+
{"sql_json", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
4796+
gettext_noop("Sets what PostgreSQL type to use as an implementaion of SQL JSON type."),
4797+
NULL
4798+
},
4799+
&sql_json_type,
4800+
SQLJSON_TYPE_JSON,
4801+
sql_json_type_info,
4802+
NULL, NULL, NULL
4803+
},
4804+
47994805
/* End-of-list marker */
48004806
{
48014807
{NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@
749749
# - Other Platforms and Clients -
750750

751751
#transform_null_equals = off
752+
#sql_json = json # jsonb
752753

753754

754755
#------------------------------------------------------------------------------

src/include/utils/jsonb.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,16 @@ extern void JsonbHashScalarValueExtended(const JsonbValue *scalarVal,
402402
extern int reserveFromBuffer(StringInfo buffer, int len);
403403
extern void appendToBuffer(StringInfo buffer, const void *data, int len);
404404

405-
extern bool json_as_jsonb; /* GUC */
405+
typedef enum SqlJsonType
406+
{
407+
SQLJSON_TYPE_JSON = 0,
408+
SQLJSON_TYPE_JSONB = 1
409+
} SqlJsonType;
410+
411+
#define SQLJSON_TYPE_IS_JSONB() (sql_json_type == SQLJSON_TYPE_JSONB)
412+
#define SQLJSON_TYPE_OID() (SQLJSON_TYPE_IS_JSONB() ? JSONBOID : JSONOID)
413+
#define SQLJSON_TYPE_NAME() (SQLJSON_TYPE_IS_JSONB() ? "jsonb" : "json")
414+
415+
extern int sql_json_type; /* GUC */
406416

407417
#endif /* __JSONB_H__ */

src/test/regress/expected/jsonb.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5044,7 +5044,7 @@ create table test_json_as_json (js json, jb jsonb);
50445044
js | json | | |
50455045
jb | jsonb | | |
50465046

5047-
set json_as_jsonb = on;
5047+
set sql_json = jsonb;
50485048
select json(' { "aa": 1, "b" : 2 }');
50495049
jsonb
50505050
-------------------
@@ -5109,7 +5109,7 @@ select json_object_field(jt, 'a') from test_json_as_jsonb;
51095109
1
51105110
(1 row)
51115111

5112-
set json_as_jsonb = off;
5112+
set sql_json = json;
51135113
\d test_json_as_jsonb
51145114
Table "public.test_json_as_jsonb"
51155115
Column | Type | Collation | Nullable | Default

src/test/regress/sql/jsonb.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ select json text ' { "aa": 1, "b" : 2 }';
12891289
create table test_json_as_json (js json, jb jsonb);
12901290
\d test_json_as_json
12911291

1292-
set json_as_jsonb = on;
1292+
set sql_json = jsonb;
12931293

12941294
select json(' { "aa": 1, "b" : 2 }');
12951295
select json ' { "aa": 1, "b" : 2 }';
@@ -1309,7 +1309,7 @@ select jsonb_object_field(jb, 'a') from test_json_as_jsonb;
13091309
select jsonb_object_field(jt, 'a') from test_json_as_jsonb;
13101310
select json_object_field(jt, 'a') from test_json_as_jsonb;
13111311

1312-
set json_as_jsonb = off;
1312+
set sql_json = json;
13131313
\d test_json_as_jsonb
13141314

13151315
select * from test_json_as_jsonb;

0 commit comments

Comments
 (0)