Re: Boolean partitions syntax - Mailing list pgsql-hackers

From Amit Langote
Subject Re: Boolean partitions syntax
Date
Msg-id 2d49cd86-acb9-fc5b-8eb7-e467b01ec25a@lab.ntt.co.jp
Whole thread Raw
In response to Re: Boolean partitions syntax  (Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>)
Responses Re: Boolean partitions syntax  (Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>)
List 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



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Online enabling of checksums
Next
From: Andres Freund
Date:
Subject: Re: Changing the autovacuum launcher scheduling; oldest table firstalgorithm