Re: Boolean partitions syntax - Mailing list pgsql-hackers

From Dilip Kumar
Subject Re: Boolean partitions syntax
Date
Msg-id CAFiTN-uorQdCqDH-6GXO4=t8VgyHyHqhsr=r8v1P2--V26==zQ@mail.gmail.com
Whole thread Raw
In response to Boolean partitions syntax  (Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>)
Responses Re: Boolean partitions syntax
List pgsql-hackers

On Tue, Dec 12, 2017 at 7:19 AM, Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> wrote:
Hi.

Horiguchi-san pointed out [1] on a nearby thread that the partitioning
syntax (the FOR VALUES clause) doesn't accept true and false as valid
partition bound datums, which seems to me like an oversight.  Attached a
patch to fix that.

create table bools (a bool) partition by list (a);

Before patch:

create table bools_t partition of bools for values in (true);
ERROR:  syntax error at or near "true"
LINE 1: ...reate table bools_t partition of bools for values in (true);

After:

create table bools_t partition of bools for values in (true);
CREATE TABLE
\d bools_t
              Table "public.bools_t"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 a      | boolean |           |          |
Partition of: bools FOR VALUES IN (true)

Thanks,
Amit

[1]
https://www.postgresql.org/message-id/20171128.203915.26713586.horiguchi.kyotaro%40lab.ntt.co.jp

+makeBoolAConstNoCast(bool state, int location)
+{
+ A_Const *n = makeNode(A_Const);
+
+ n->val.type = T_String;
+ n->val.val.str = (state ? "t" : "f");
+ n->location = location;
+
+ return (Node *) n;
+}
+

I think we can change makeBoolAConst as below so that we can avoid duplicate code.

static Node *
makeBoolAConst(bool state, int location)
{
Node *n = makeBoolAConstNoCast(state, location);

return makeTypeCast(n, SystemTypeName("bool"), -1);
}

--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com

pgsql-hackers by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Using ProcSignal to get memory context stats from a running backend
Next
From: Tom Lane
Date:
Subject: Re: Using ProcSignal to get memory context stats from a running backend