Re: Boolean partitions syntax

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: robertmhaas(at)gmail(dot)com, peter(dot)eisentraut(at)2ndquadrant(dot)com, sfrost(at)snowman(dot)net, hornschnorter(at)gmail(dot)com, dilipbalaut(at)gmail(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Boolean partitions syntax
Date: 2018-03-02 07:49:29
Message-ID: 2d49cd86-acb9-fc5b-8eb7-e467b01ec25a@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Horiguchi-san,

On 2018/02/05 18:17, Kyotaro HORIGUCHI wrote:
> At Mon, 29 Jan 2018 13:21:54 +0900, Amit Langote wrote:
>> Partition bound literals as captured gram.y don't have any type
>> information attached. They're carried over in a A_Const to
>> transformPartitionBoundValue() and coerced to the target partition key
>> type there. Note that each of the the partition bound literal datums
>> received from gram.y is castNode(A_Const)'d in parse_utilcmds.c.
>
> eval_const_expressions is already running under
> transformPartitionBoundValue to resolve remaining coercion. I
> suppose we can use AexprConst to restrict the syntax within
> appropriate variations. Please find the attached patch.
> It allows the following syntax as a by-prodcut.
>
> | create table c4 partition of t for values in (numeric(1,0) '5');
>
> Parser accepts arbitrary defined types but it does no harm.
>
> | create table c2 partition of t for values from (line '{0,1,0}') to (1);
> | ERROR: specified value cannot be cast to type double precision for column "a"
>
> It rejects unacceptable functions but the message may look
> somewhat unfriendly.
>
> | =# create table c1 partition of t for values in (random());
> | ERROR: syntax error at or near ")"
> | LINE 1: create table c1 partition of t for values in (random());
> | ^
> (marker is placed under the closing parenthesis of "random()")
>
> | =# create table c1 partition of t for values in (random(0) 'x');
> | ERROR: type "random" does not exist
> | LINE 1: create table c1 partition of t for values in (random(0) 'x')...
> (marker is placed under the first letter of the "random".)

I had tried the approach your patch takes and had noticed that the syntax
had stopped accepting negative values (a regression test fails due to that).

create table foo (a int) partition by list (a);
create table foo1 partition of foo for values in (-1);
ERROR: syntax error at or near "-"
LINE 1: create table foo1 partition of foo for values in (-1);

I guess the following in gram.y leaves out negative numbers:

/*
* Constants
*/
AexprConst: Iconst
{
$$ = makeIntConst($1, @1);
}
| FCONST
{
$$ = makeFloatConst($1, @1);
}

I had tried fixing that as well, but it didn't readily work.

Thanks,
Amit

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2018-03-02 07:51:45 Re: Changing the autovacuum launcher scheduling; oldest table first algorithm
Previous Message Andres Freund 2018-03-02 07:44:30 Re: Online enabling of checksums