mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
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
This commit is contained in:
@@ -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:
|
||||
|
@@ -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),
|
||||
|
@@ -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,
|
||||
|
@@ -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),
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user