Skip to content

Commit 74778ce

Browse files
committed
Return null check if there is only column in expression
1 parent 91506a3 commit 74778ce

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

sql/pathman_basic.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CREATE TABLE test.hash_rel (
1111
INSERT INTO test.hash_rel VALUES (1, 1);
1212
INSERT INTO test.hash_rel VALUES (2, 2);
1313
INSERT INTO test.hash_rel VALUES (3, 3);
14-
SELECT pathman.create_hash_partitions('test.hash_rel', 'value + 1', 3);
14+
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
1515
ALTER TABLE test.hash_rel ALTER COLUMN value SET NOT NULL;
1616
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3, partition_data:=false);
1717
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;

src/partition_creation.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,34 @@ get_part_expression_info(Oid relid, const char *expr_string,
17661766
/* Keep raw expression */
17671767
expr_info->raw_expr = get_raw_expression(relid, expr_string,
17681768
&query_string, &parsetree);
1769+
1770+
/* If expression is just column we check that is not null */
1771+
if (IsA(expr_info->raw_expr, ColumnRef))
1772+
{
1773+
ColumnRef *col = (ColumnRef *) expr_info->raw_expr;
1774+
if (list_length(col->fields) == 1)
1775+
{
1776+
HeapTuple tp;
1777+
bool result;
1778+
char *attname = strVal(linitial(col->fields));
1779+
1780+
/* check if attribute is nullable */
1781+
tp = SearchSysCacheAttName(relid, attname);
1782+
if (HeapTupleIsValid(tp))
1783+
{
1784+
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
1785+
result = !att_tup->attnotnull;
1786+
ReleaseSysCache(tp);
1787+
}
1788+
else
1789+
elog(ERROR, "Cannot find type name for attribute \"%s\" "
1790+
"of relation \"%s\"",
1791+
attname, get_rel_name_or_relid(relid));
1792+
1793+
if (result)
1794+
elog(ERROR, "partitioning key \"%s\" must be NOT NULL", attname);
1795+
}
1796+
}
17691797
expr_info->expr_datum = (Datum) 0;
17701798

17711799
/* We don't need pathman activity initialization for this relation yet */

src/pl_funcs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ PG_FUNCTION_INFO_V1( build_check_constraint_name_attname );
5757

5858
PG_FUNCTION_INFO_V1( validate_relname );
5959
PG_FUNCTION_INFO_V1( is_date_type );
60-
PG_FUNCTION_INFO_V1( is_attribute_nullable );
61-
//PG_FUNCTION_INFO_V1( is_expression_suitable );
6260

6361
PG_FUNCTION_INFO_V1( add_to_pathman_config );
6462
PG_FUNCTION_INFO_V1( pathman_config_params_trigger_func );
@@ -602,6 +600,7 @@ is_date_type(PG_FUNCTION_ARGS)
602600
PG_RETURN_BOOL(is_date_type_internal(PG_GETARG_OID(0)));
603601
}
604602

603+
605604
/*
606605
* ------------------------
607606
* Useful string builders

0 commit comments

Comments
 (0)