Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6Qe2-0006HN-2I for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Mar 2019 02:07:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h6Qe0-0003rM-KC for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Mar 2019 02:07:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6Qdz-0003r9-Ik for pgsql-bugs@lists.postgresql.org; Wed, 20 Mar 2019 02:07:52 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6Qdv-0007xq-9E for pgsql-bugs@lists.postgresql.org; Wed, 20 Mar 2019 02:07:51 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5EFE322DEC; Tue, 19 Mar 2019 22:07:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 19 Mar 2019 22:07:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=6kIDv46WPlD1bsi0IWTDELM6Waf PJqHrwxrR0kPijQE=; b=sp/LHWeFueI5nPEkAPDAmxIxQR79m5+5cG+xYvCD4mo /lrP9JJ2p5sZGmq8mgTngSevNYReinStzOivgF4mZFRI8BTx1inNRDtpo7zSbUoP wA/OyS6Q+NGv4MydkcR5Ta8QW4qLc5WLpm1g3zfErOD8uf6FlLrAmb6iSuJewFRa +d5jMf6e36j5X7GMO8cK1bDOsQ9A4cBc7ZEDO4utD4zV2Tk6zCkMY3fuLwAmWv7t iLq1j2657+nMMKBAeP4QGij8z4C6SLRqjsSWCkE0ImzJ7/k5SXXscERdFOEUcnSL Pvb5Z2Aj1GZD8GXPWqeLsQpDRaY2m+KG1ZC2fA5efKQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=6kIDv4 6WPlD1bsi0IWTDELM6WafPJqHrwxrR0kPijQE=; b=DASz0SEOZLTqyyBEAOJ87h JnZvg9HNM0FiOou+I/IS/9Ej2qmsCUtjlCCZ/YZPCmsI6ZgLJ/ZC8OoAURC2S8VH ktPzLeXYqG6F+qWWR2USQRjmy89HFdWLDuWImVqfYsrrIGXyJaS0zhS3pQMnq+Vt B6VqBRhsx13LyHzYseXWd5Lb7Bwe0RhIj2POzpkJMHZTWi22W6tb/gOwGcUILmGB IJjFaThBpiZ97vzB4PUywvw3WzEDOGhIM/0xeeGWUG5vMtIn1T0u2ihVumxWXZG+ Qx/5mmUt3RO6pV8ce1l6w1zXC0jPwxR8GjB3cTKdjByKKNQvs1X3kmw71yeHSdpA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrieehgdeggecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecukfhppeduudekrddvgedurddvgeekrdduudenucfrrghrrghm pehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlhhush htvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (mp76f1f80b.ap.nuro.jp [118.241.248.11]) by mail.messagingengine.com (Postfix) with ESMTPA id 681B81030F; Tue, 19 Mar 2019 22:07:42 -0400 (EDT) Date: Wed, 20 Mar 2019 11:07:31 +0900 From: Michael Paquier To: Amit Langote Cc: Amit Langote , exclusion@gmail.com, PostgreSQL mailing lists , PostgreSQL-development , Peter Eisentraut Subject: Re: BUG #15668: Server crash in transformPartitionRangeBounds Message-ID: <20190320020731.GE3488@paquier.xyz> References: <15668-0377b1981aa1a393@postgresql.org> <20190306064825.GH30982@paquier.xyz> <6ed2c24c-2f73-fa1c-0ed1-ed3597f13d0d@lab.ntt.co.jp> <20190306082730.GJ30982@paquier.xyz> <20190311072114.GG1818@paquier.xyz> <20190314042308.GG3493@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="QXO0/MSS4VvK6f+D" Content-Disposition: inline In-Reply-To: <20190314042308.GG3493@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --QXO0/MSS4VvK6f+D Content-Type: multipart/mixed; boundary="sfyO1m2EN8ZOtJL6" Content-Disposition: inline --sfyO1m2EN8ZOtJL6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Mar 14, 2019 at 01:23:08PM +0900, Michael Paquier wrote: > I actually think that what you propose here makes more sense than what > HEAD does because the most inner expression gets evaluated first. > This for example generates the same error as on HEAD: > =3D# create table foo (a int default (avg(1))); > ERROR: 42803: aggregate functions are not allowed in DEFAULT expressions I have been working on that, and in the case of a non-existing column the patch would generate the following error on HEAD: ERROR: 42703: column "non_existent" does not exist But with the patch we get that: ERROR: cannot use column reference in DEFAULT expression Still I think that this looks right as we should not have any direct column reference anyway, and it keeps the code more simple. So I have added more tests to cover those grounds. The docs of CREATE TABLE are actually wrong, right? It mentions that "subqueries and cross-references to other columns in the current table are not allowed", but cookDefault() rejects any kind of column references anyway for default expressions, including references to the column which uses the default expression (or we talk about generated columns here still if I recall Peter Eisentraunt's patch correctly generated columns don't allow references to the column using the expression itself, which is logic by the way). + * transformExpr() should have already rejected column references, + * subqueries, aggregates, window functions, and SRFs, based on the + * EXPR_KIND_ for a default expression. */ I would have added an assertion here, perhaps an elog(). Same remark for cookDefault(). The attached patch has an assertion. CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (sum(a)); -ERROR: aggregate functions are not allowed in partition bound +ERROR: cannot use column reference in partition bound expression It would be nice to also test the case where an aggregate is forbidden, so I have added a test with sum(1) instead of a column reference. We never actually tested in the tree the case of subqueries and SRFs used in default expressions, so added. The last patch you sent did not fix the original problem of the thread. That was intentional from your side I guess to show your point, still we are touching the same area of the code so I propose to fix everything together, and to improve the test coverage for list and range strategies. In order to achieve that, I have merged my previous=20 proposal into your patch, and added more tests. The new tests for the range strategy reproduce the crash. The result is attached. What do you think? -- Michael --sfyO1m2EN8ZOtJL6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="partition-bound-crash-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_t= able.sgml index e94fe2c3b6..5fe16aa6f6 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -784,7 +784,7 @@ WITH ( MODULUS numeric= _literal, REM The DEFAULT clause assigns a default data value f= or the column whose column definition it appears within. The value is any variable-free expression (subqueries and cross-references - to other columns in the current table are not allowed). The + to any columns in the current table are not allowed). The data type of the default expression must match the data type of the column. diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index c7b5ff62f9..fc682e0b52 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -2939,19 +2939,11 @@ cookDefault(ParseState *pstate, expr =3D transformExpr(pstate, raw_default, EXPR_KIND_COLUMN_DEFAULT); =20 /* - * Make sure default expr does not refer to any vars (we need this check - * since the pstate includes the target table). - */ - if (contain_var_clause(expr)) - ereport(ERROR, - (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), - errmsg("cannot use column references in default expression"))); - - /* - * transformExpr() should have already rejected subqueries, aggregates, - * window functions, and SRFs, based on the EXPR_KIND_ for a default - * expression. + * transformExpr() should have already rejected column references, + * subqueries, aggregates, window functions, and SRFs, based on the + * EXPR_KIND_ for a default expression. */ + Assert(!contain_var_clause(expr)); =20 /* * Coerce the expression to the correct type and typmod, if given. This diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_exp= r.c index e559353529..3e648dc8ef 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -520,6 +520,79 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref) CRERR_WRONG_DB, CRERR_TOO_MANY } crerr =3D CRERR_NO_COLUMN; + const char *err; + + /* + * Check to see if the column reference is in an invalid place within the + * query. We allow column references in most places, except in default + * expressions and partition bound expressions. + */ + err =3D NULL; + switch (pstate->p_expr_kind) + { + case EXPR_KIND_NONE: + Assert(false); /* can't happen */ + break; + case EXPR_KIND_OTHER: + case EXPR_KIND_JOIN_ON: + case EXPR_KIND_JOIN_USING: + case EXPR_KIND_FROM_SUBSELECT: + case EXPR_KIND_FROM_FUNCTION: + case EXPR_KIND_WHERE: + case EXPR_KIND_POLICY: + case EXPR_KIND_HAVING: + case EXPR_KIND_FILTER: + case EXPR_KIND_WINDOW_PARTITION: + case EXPR_KIND_WINDOW_ORDER: + case EXPR_KIND_WINDOW_FRAME_RANGE: + case EXPR_KIND_WINDOW_FRAME_ROWS: + case EXPR_KIND_WINDOW_FRAME_GROUPS: + case EXPR_KIND_SELECT_TARGET: + case EXPR_KIND_INSERT_TARGET: + case EXPR_KIND_UPDATE_SOURCE: + case EXPR_KIND_UPDATE_TARGET: + case EXPR_KIND_GROUP_BY: + case EXPR_KIND_ORDER_BY: + case EXPR_KIND_DISTINCT_ON: + case EXPR_KIND_LIMIT: + case EXPR_KIND_OFFSET: + case EXPR_KIND_RETURNING: + case EXPR_KIND_VALUES: + case EXPR_KIND_VALUES_SINGLE: + case EXPR_KIND_CHECK_CONSTRAINT: + case EXPR_KIND_DOMAIN_CHECK: + case EXPR_KIND_FUNCTION_DEFAULT: + case EXPR_KIND_INDEX_EXPRESSION: + case EXPR_KIND_INDEX_PREDICATE: + case EXPR_KIND_ALTER_COL_TRANSFORM: + case EXPR_KIND_EXECUTE_PARAMETER: + case EXPR_KIND_TRIGGER_WHEN: + case EXPR_KIND_PARTITION_EXPRESSION: + case EXPR_KIND_CALL_ARGUMENT: + case EXPR_KIND_COPY_WHERE: + /* okay */ + break; + + case EXPR_KIND_COLUMN_DEFAULT: + err =3D _("cannot use column reference in DEFAULT expression"); + break; + case EXPR_KIND_PARTITION_BOUND: + err =3D _("cannot use column reference in partition bound expression"); + break; + + /* + * There is intentionally no default: case here, so that the + * compiler will warn if we add a new ParseExprKind without + * extending this switch. If we do see an unrecognized value at + * runtime, the behavior will be the same as for EXPR_KIND_OTHER, + * which is sane anyway. + */ + } + if (err) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg_internal("%s", err), + parser_errposition(pstate, cref->location))); =20 /* * Give the PreParseColumnRefHook, if any, first shot. If it returns diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_= utilcmd.c index a37d1f18be..d38ad1ed62 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3750,8 +3750,16 @@ transformPartitionRangeBounds(ParseState *pstate, Li= st *blist, IsA(linitial(cref->fields), String)) cname =3D strVal(linitial(cref->fields)); =20 - Assert(cname !=3D NULL); - if (strcmp("minvalue", cname) =3D=3D 0) + if (cname =3D=3D NULL) + { + /* + * No field names have been found, meaning that there + * is not much to do with special value handling. Instead + * let the expression transformation handle any errors and + * limitations. + */ + } + else if (strcmp("minvalue", cname) =3D=3D 0) { prd =3D makeNode(PartitionRangeDatum); prd->kind =3D PARTITION_RANGE_DATUM_MINVALUE; @@ -3903,6 +3911,13 @@ transformPartitionBoundValue(ParseState *pstate, Nod= e *val, COERCE_IMPLICIT_CAST, -1); =20 + /* + * transformExpr() should have already rejected column references, + * subqueries, aggregates, window functions, and SRFs, based on the + * EXPR_KIND_ for a default expression. + */ + Assert(!contain_var_clause(value)); + if (value =3D=3D NULL) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), @@ -3914,13 +3929,6 @@ transformPartitionBoundValue(ParseState *pstate, Nod= e *val, if (!IsA(value, Const)) value =3D (Node *) expression_planner((Expr *) value); =20 - /* Make sure the expression does not refer to any vars. */ - if (contain_var_clause(value)) - ereport(ERROR, - (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), - errmsg("cannot use column references in partition bound expression"), - parser_errposition(pstate, exprLocation(value)))); - /* * Evaluate the expression, assigning the partition key's collation to the * resulting Const expression. diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/= expected/create_table.out index d51e547278..d3a7a8c21b 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -297,6 +297,38 @@ ERROR: tables declared WITH OIDS are not supported -- but explicitly not adding oids is still supported CREATE TEMP TABLE withoutoid() WITHOUT OIDS; DROP TABLE withoutoid; CREATE TEMP TABLE withoutoid() WITH (oids =3D false); DROP TABLE withoutoi= d; +-- check restriction with default expressions +-- invalid use of column reference in default expressions +CREATE TABLE default_expr_column (id int DEFAULT (id)); +ERROR: cannot use column reference in DEFAULT expression +LINE 1: CREATE TABLE default_expr_column (id int DEFAULT (id)); + ^ +CREATE TABLE default_expr_column (id int DEFAULT (bar.id)); +ERROR: cannot use column reference in DEFAULT expression +LINE 1: CREATE TABLE default_expr_column (id int DEFAULT (bar.id)); + ^ +CREATE TABLE default_expr_agg_column (id int DEFAULT (avg(id))); +ERROR: cannot use column reference in DEFAULT expression +LINE 1: ...TE TABLE default_expr_agg_column (id int DEFAULT (avg(id))); + ^ +-- invalid column definition +CREATE TABLE default_expr_non_column (a int DEFAULT (avg(non_existent))); +ERROR: cannot use column reference in DEFAULT expression +LINE 1: ...TABLE default_expr_non_column (a int DEFAULT (avg(non_existe... + ^ +-- invalid use of aggregate in default expression +CREATE TABLE default_expr_agg (a int DEFAULT (avg(1))); +ERROR: aggregate functions are not allowed in DEFAULT expressions +LINE 1: CREATE TABLE default_expr_agg (a int DEFAULT (avg(1))); + ^ +CREATE TABLE default_expr_agg (a int DEFAULT (select 1)); +ERROR: cannot use subquery in DEFAULT expression +LINE 1: CREATE TABLE default_expr_agg (a int DEFAULT (select 1)); + ^ +CREATE TABLE default_expr_agg (a int DEFAULT (generate_series(1,3))); +ERROR: set-returning functions are not allowed in DEFAULT expressions +LINE 1: CREATE TABLE default_expr_agg (a int DEFAULT (generate_serie... + ^ -- -- Partitioned tables -- @@ -489,18 +521,34 @@ Partitions: part_null FOR VALUES IN (NULL), part_p2 FOR VALUES IN (2), part_p3 FOR VALUES IN (3) =20 --- forbidden expressions for partition bound +-- forbidden expressions for partition bound with list partitioned table CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename); -ERROR: column "somename" does not exist +ERROR: cannot use column reference in partition bound expression LINE 1: ...expr_fail PARTITION OF list_parted FOR VALUES IN (somename); ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename.somename); +ERROR: cannot use column reference in partition bound expression +LINE 1: ...expr_fail PARTITION OF list_parted FOR VALUES IN (somename.s... + ^ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= a); -ERROR: cannot use column references in partition bound expression +ERROR: cannot use column reference in partition bound expression LINE 1: ..._bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (a); ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= a.a); +ERROR: cannot use column reference in partition bound expression +LINE 1: ...ogus_expr_fail PARTITION OF list_parted FOR VALUES IN (a.a); + ^ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= sum(a)); -ERROR: aggregate functions are not allowed in partition bound +ERROR: cannot use column reference in partition bound expression LINE 1: ...s_expr_fail PARTITION OF list_parted FOR VALUES IN (sum(a)); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= sum(somename)); +ERROR: cannot use column reference in partition bound expression +LINE 1: ..._fail PARTITION OF list_parted FOR VALUES IN (sum(somename))... + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= sum(1)); +ERROR: aggregate functions are not allowed in partition bound +LINE 1: ...s_expr_fail PARTITION OF list_parted FOR VALUES IN (sum(1)); ^ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= (select 1)); ERROR: cannot use subquery in partition bound @@ -558,6 +606,52 @@ DROP TABLE bigintp; CREATE TABLE range_parted ( a date ) PARTITION BY RANGE (a); +-- forbidden expressions for partition bounds with range partitioned table +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename) TO ('2019-01-01'); +ERROR: cannot use column reference in partition bound expression +LINE 2: FOR VALUES FROM (somename) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename.somename) TO ('2019-01-01'); +ERROR: cannot use column reference in partition bound expression +LINE 2: FOR VALUES FROM (somename.somename) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (a) TO ('2019-01-01'); +ERROR: cannot use column reference in partition bound expression +LINE 2: FOR VALUES FROM (a) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (a.a) TO ('2019-01-01'); +ERROR: cannot use column reference in partition bound expression +LINE 2: FOR VALUES FROM (a.a) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (sum(a)) TO ('2019-01-01'); +ERROR: cannot use column reference in partition bound expression +LINE 2: FOR VALUES FROM (sum(a)) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (sum(somename)) TO ('2019-01-01'); +ERROR: cannot use column reference in partition bound expression +LINE 2: FOR VALUES FROM (sum(somename)) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (sum(1)) TO ('2019-01-01'); +ERROR: aggregate functions are not allowed in partition bound +LINE 2: FOR VALUES FROM (sum(1)) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM ((select 1)) TO ('2019-01-01'); +ERROR: cannot use subquery in partition bound +LINE 2: FOR VALUES FROM ((select 1)) TO ('2019-01-01'); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (generate_series(1, 3)) TO ('2019-01-01'); +ERROR: set-returning functions are not allowed in partition bound +LINE 2: FOR VALUES FROM (generate_series(1, 3)) TO ('2019-01-01'); + ^ -- trying to specify list for range partitioned table CREATE TABLE fail_part PARTITION OF range_parted FOR VALUES IN ('a'); ERROR: invalid bound specification for a range partition diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/c= reate_table.sql index 4091c19cf0..b0704d90af 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -304,6 +304,18 @@ CREATE TABLE withoid() WITH (oids =3D true); CREATE TEMP TABLE withoutoid() WITHOUT OIDS; DROP TABLE withoutoid; CREATE TEMP TABLE withoutoid() WITH (oids =3D false); DROP TABLE withoutoi= d; =20 +-- check restriction with default expressions +-- invalid use of column reference in default expressions +CREATE TABLE default_expr_column (id int DEFAULT (id)); +CREATE TABLE default_expr_column (id int DEFAULT (bar.id)); +CREATE TABLE default_expr_agg_column (id int DEFAULT (avg(id))); +-- invalid column definition +CREATE TABLE default_expr_non_column (a int DEFAULT (avg(non_existent))); +-- invalid use of aggregate in default expression +CREATE TABLE default_expr_agg (a int DEFAULT (avg(1))); +CREATE TABLE default_expr_agg (a int DEFAULT (select 1)); +CREATE TABLE default_expr_agg (a int DEFAULT (generate_series(1,3))); + -- -- Partitioned tables -- @@ -450,10 +462,14 @@ CREATE TABLE part_p3 PARTITION OF list_parted FOR VAL= UES IN ((2+1)); CREATE TABLE part_null PARTITION OF list_parted FOR VALUES IN (null); \d+ list_parted =20 --- forbidden expressions for partition bound +-- forbidden expressions for partition bound with list partitioned table CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename); +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename.somename); CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= a); +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= a.a); CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= sum(a)); +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= sum(somename)); +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= sum(1)); CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= (select 1)); CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= generate_series(4, 6)); =20 @@ -497,6 +513,26 @@ CREATE TABLE range_parted ( a date ) PARTITION BY RANGE (a); =20 +-- forbidden expressions for partition bounds with range partitioned table +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename.somename) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (a) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (a.a) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (sum(a)) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (sum(somename)) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (sum(1)) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM ((select 1)) TO ('2019-01-01'); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (generate_series(1, 3)) TO ('2019-01-01'); + -- trying to specify list for range partitioned table CREATE TABLE fail_part PARTITION OF range_parted FOR VALUES IN ('a'); -- trying to specify modulus and remainder for range partitioned table --sfyO1m2EN8ZOtJL6-- --QXO0/MSS4VvK6f+D Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlyRoGMACgkQnvQgOdby QH3v1BAAqEgPICrZlQ09EAPSJKjW4rVpAOhxfQMDXp3VMEC7hS8M+Qg8SvxGntzP pb5Fb7CJdnc94bXYAW8cvxH5a+P6X03HGpjK62aGT/z7ub/E01q5nbnIXIt8MESn En//W/gxHMQQoraOEBwWqKoAGC+DH041AtwnGN0cebFkgAw/k6qaxjbdbJpimJIT DeDYiueYHwBYpGrlWEcVBJr6iDROSKUOs+/EBiCJoirG6+4jnlfXHwaBEM3/vf/P 9cmFgUSW77uP4awr6vyd+2ihw7dKTIUgDE/BBRm7gYODUBeRWj/05uVhSr7fDso+ RqZ+UJRw7uLEvke9rh7NnvIHFb6gM1A1LreqTAJg83IRqcrVrKVEy3Aj0nH+pqPJ HTHM2KquoYELQZDi5CrPF2DJ7V3kFdffzboi8UyavCGBcDSsP4ww2U2sQsWoUrd/ 7UY7LXZ5VZZYiKNp7j99wPlVZqjdVAHxsgDzYfEZYEicCc9fZ4yKuX9JOGrZyENx NMUy//X6NbfrOwLnHdyMDzjq9NuoI7Xf5Wwae2jnjm09HdAUsqk82dpgL1hrr2r0 711uC2FhqeGt0qux9Dtlct7f4bKrqf9+ip/SE4XztviroE44eFXlT5/644jQVlZN euubcyevSgam8eMfqbKAA5HnDkJr99S3gBKKv9BV6pvTczqkz/c= =swyu -----END PGP SIGNATURE----- --QXO0/MSS4VvK6f+D--