summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-01-14 10:46:49 +0100
committerPeter Eisentraut <peter@eisentraut.org>2022-01-17 10:38:23 +0100
commit941460fcf731a32e6a90691508d5cfa3d1f8eeaf (patch)
tree2de0be4abcf7db131607ce9ba590a8040c16d6e3 /src/backend/commands
parentca86a63d207aca1f52ff13a1ce13854681d1bbf9 (diff)
downloadpostgresql-941460fcf731a32e6a90691508d5cfa3d1f8eeaf.tar.gz
Add Boolean node
Before, SQL-level boolean constants were represented by a string with a cast, and internal Boolean values in DDL commands were usually represented by Integer nodes. This takes the place of both of these uses, making the intent clearer and having some amount of type safety. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/8c1a2e37-c68d-703c-5a83-7a6077f4f997@enterprisedb.com
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/define.c2
-rw-r--r--src/backend/commands/functioncmds.c14
-rw-r--r--src/backend/commands/sequence.c4
-rw-r--r--src/backend/commands/tsearchcmds.c9
-rw-r--r--src/backend/commands/user.c28
5 files changed, 34 insertions, 23 deletions
diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c
index ce1a9df268..0755ab1eae 100644
--- a/src/backend/commands/define.c
+++ b/src/backend/commands/define.c
@@ -59,6 +59,8 @@ defGetString(DefElem *def)
return psprintf("%ld", (long) intVal(def->arg));
case T_Float:
return castNode(Float, def->arg)->fval;
+ case T_Boolean:
+ return boolVal(def->arg) ? "true" : "false";
case T_String:
return strVal(def->arg);
case T_TypeName:
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 119b795982..25b75375a8 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -813,15 +813,15 @@ compute_function_attributes(ParseState *pstate,
if (transform_item)
*transform = transform_item->arg;
if (windowfunc_item)
- *windowfunc_p = intVal(windowfunc_item->arg);
+ *windowfunc_p = boolVal(windowfunc_item->arg);
if (volatility_item)
*volatility_p = interpret_func_volatility(volatility_item);
if (strict_item)
- *strict_p = intVal(strict_item->arg);
+ *strict_p = boolVal(strict_item->arg);
if (security_item)
- *security_definer = intVal(security_item->arg);
+ *security_definer = boolVal(security_item->arg);
if (leakproof_item)
- *leakproof_p = intVal(leakproof_item->arg);
+ *leakproof_p = boolVal(leakproof_item->arg);
if (set_items)
*proconfig = update_proconfig_value(NULL, set_items);
if (cost_item)
@@ -1417,12 +1417,12 @@ AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
if (volatility_item)
procForm->provolatile = interpret_func_volatility(volatility_item);
if (strict_item)
- procForm->proisstrict = intVal(strict_item->arg);
+ procForm->proisstrict = boolVal(strict_item->arg);
if (security_def_item)
- procForm->prosecdef = intVal(security_def_item->arg);
+ procForm->prosecdef = boolVal(security_def_item->arg);
if (leakproof_item)
{
- procForm->proleakproof = intVal(leakproof_item->arg);
+ procForm->proleakproof = boolVal(leakproof_item->arg);
if (procForm->proleakproof && !superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index f2ffd42a05..27cb630758 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -1401,7 +1401,7 @@ init_params(ParseState *pstate, List *options, bool for_identity,
/* CYCLE */
if (is_cycled != NULL)
{
- seqform->seqcycle = intVal(is_cycled->arg);
+ seqform->seqcycle = boolVal(is_cycled->arg);
Assert(BoolIsValid(seqform->seqcycle));
seqdataform->log_cnt = 0;
}
@@ -1739,7 +1739,7 @@ sequence_options(Oid relid)
options = lappend(options,
makeDefElem("cache", (Node *) makeFloat(psprintf(INT64_FORMAT, pgsform->seqcache)), -1));
options = lappend(options,
- makeDefElem("cycle", (Node *) makeInteger(pgsform->seqcycle), -1));
+ makeDefElem("cycle", (Node *) makeBoolean(pgsform->seqcycle), -1));
options = lappend(options,
makeDefElem("increment", (Node *) makeFloat(psprintf(INT64_FORMAT, pgsform->seqincrement)), -1));
options = lappend(options,
diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c
index 39f0bf7a0d..4cc4e3c00f 100644
--- a/src/backend/commands/tsearchcmds.c
+++ b/src/backend/commands/tsearchcmds.c
@@ -1742,6 +1742,15 @@ buildDefItem(const char *name, const char *val, bool was_quoted)
return makeDefElem(pstrdup(name),
(Node *) makeFloat(pstrdup(val)),
-1);
+
+ if (strcmp(val, "true") == 0)
+ return makeDefElem(pstrdup(name),
+ (Node *) makeBoolean(true),
+ -1);
+ if (strcmp(val, "false") == 0)
+ return makeDefElem(pstrdup(name),
+ (Node *) makeBoolean(false),
+ -1);
}
/* Just make it a string */
return makeDefElem(pstrdup(name),
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 5f6e94949b..f9d3c1246b 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -217,17 +217,17 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
if (dpassword && dpassword->arg)
password = strVal(dpassword->arg);
if (dissuper)
- issuper = intVal(dissuper->arg) != 0;
+ issuper = boolVal(dissuper->arg);
if (dinherit)
- inherit = intVal(dinherit->arg) != 0;
+ inherit = boolVal(dinherit->arg);
if (dcreaterole)
- createrole = intVal(dcreaterole->arg) != 0;
+ createrole = boolVal(dcreaterole->arg);
if (dcreatedb)
- createdb = intVal(dcreatedb->arg) != 0;
+ createdb = boolVal(dcreatedb->arg);
if (dcanlogin)
- canlogin = intVal(dcanlogin->arg) != 0;
+ canlogin = boolVal(dcanlogin->arg);
if (disreplication)
- isreplication = intVal(disreplication->arg) != 0;
+ isreplication = boolVal(disreplication->arg);
if (dconnlimit)
{
connlimit = intVal(dconnlimit->arg);
@@ -245,7 +245,7 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
if (dvalidUntil)
validUntil = strVal(dvalidUntil->arg);
if (dbypassRLS)
- bypassrls = intVal(dbypassRLS->arg) != 0;
+ bypassrls = boolVal(dbypassRLS->arg);
/* Check some permissions first */
if (issuper)
@@ -700,37 +700,37 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
*/
if (dissuper)
{
- new_record[Anum_pg_authid_rolsuper - 1] = BoolGetDatum(intVal(dissuper->arg));
+ new_record[Anum_pg_authid_rolsuper - 1] = BoolGetDatum(boolVal(dissuper->arg));
new_record_repl[Anum_pg_authid_rolsuper - 1] = true;
}
if (dinherit)
{
- new_record[Anum_pg_authid_rolinherit - 1] = BoolGetDatum(intVal(dinherit->arg));
+ new_record[Anum_pg_authid_rolinherit - 1] = BoolGetDatum(boolVal(dinherit->arg));
new_record_repl[Anum_pg_authid_rolinherit - 1] = true;
}
if (dcreaterole)
{
- new_record[Anum_pg_authid_rolcreaterole - 1] = BoolGetDatum(intVal(dcreaterole->arg));
+ new_record[Anum_pg_authid_rolcreaterole - 1] = BoolGetDatum(boolVal(dcreaterole->arg));
new_record_repl[Anum_pg_authid_rolcreaterole - 1] = true;
}
if (dcreatedb)
{
- new_record[Anum_pg_authid_rolcreatedb - 1] = BoolGetDatum(intVal(dcreatedb->arg));
+ new_record[Anum_pg_authid_rolcreatedb - 1] = BoolGetDatum(boolVal(dcreatedb->arg));
new_record_repl[Anum_pg_authid_rolcreatedb - 1] = true;
}
if (dcanlogin)
{
- new_record[Anum_pg_authid_rolcanlogin - 1] = BoolGetDatum(intVal(dcanlogin->arg));
+ new_record[Anum_pg_authid_rolcanlogin - 1] = BoolGetDatum(boolVal(dcanlogin->arg));
new_record_repl[Anum_pg_authid_rolcanlogin - 1] = true;
}
if (disreplication)
{
- new_record[Anum_pg_authid_rolreplication - 1] = BoolGetDatum(intVal(disreplication->arg));
+ new_record[Anum_pg_authid_rolreplication - 1] = BoolGetDatum(boolVal(disreplication->arg));
new_record_repl[Anum_pg_authid_rolreplication - 1] = true;
}
@@ -779,7 +779,7 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
if (dbypassRLS)
{
- new_record[Anum_pg_authid_rolbypassrls - 1] = BoolGetDatum(intVal(dbypassRLS->arg));
+ new_record[Anum_pg_authid_rolbypassrls - 1] = BoolGetDatum(boolVal(dbypassRLS->arg));
new_record_repl[Anum_pg_authid_rolbypassrls - 1] = true;
}