From f2b42ebe0e78ec197fa8b79147569eec4b2bcd7a Mon Sep 17 00:00:00 2001 From: Matvey Arye Date: Wed, 31 May 2017 19:21:54 -0400 Subject: [PATCH] Fix problems with partitioning logic for padded fields Padded fields such as character(20) did not work correctly before because of differences between type output and coercion/casting. --- src/partitioning.c | 13 ++++++++++++- test/expected/insert.out | 18 ++++++++++++++++++ test/sql/insert.sql | 11 +++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/partitioning.c b/src/partitioning.c index 87f9e23f9..26da1d17e 100644 --- a/src/partitioning.c +++ b/src/partitioning.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "partitioning.h" #include "metadata_queries.h" @@ -32,10 +33,20 @@ partitioning_info_set_textfunc_fmgr(PartitioningInfo *pi, Oid relid) Oid type_id, func_id; bool isVarlena; + CoercionPathType cpt; pi->column_attnum = get_attnum(relid, pi->column); type_id = get_atttype(relid, pi->column_attnum); - getTypeOutputInfo(type_id, &func_id, &isVarlena); + + /* + * First look for an explicit cast type. Needed since the output of for + * example character(20) not the same as character(20)::text + */ + cpt = find_coercion_pathway(TEXTOID, type_id, COERCION_EXPLICIT, &func_id); + if (cpt != COERCION_PATH_FUNC) + { + getTypeOutputInfo(type_id, &func_id, &isVarlena); + } fmgr_info_cxt(func_id, &pi->partfunc.textfunc_fmgr, CurrentMemoryContext); } diff --git a/test/expected/insert.out b/test/expected/insert.out index 7c09c9c7b..edbf16c3d 100644 --- a/test/expected/insert.out +++ b/test/expected/insert.out @@ -459,3 +459,21 @@ SELECT * FROM error_test; Mon Mar 20 09:18:25.7 2017 | 22.4 | dev2 (2 rows) +--test character(9) partition keys since there were issues with padding causing partitioning errors +CREATE TABLE tick_character ( + symbol character(9) NOT NULL, mid REAL NOT NULL, spread REAL NOT NULL, + time TIMESTAMPTZ NOT NULL +); +SELECT create_hypertable ('tick_character', 'time', 'symbol', 2); + create_hypertable +------------------- + +(1 row) + +INSERT INTO tick_character ( symbol, mid, spread, time ) VALUES ( 'GBPJPY', 142.639000, 5.80, 'Mon Mar 20 09:18:22.3 2017'); +SELECT * FROM tick_character; + symbol | mid | spread | time +-----------+---------+--------+-------------------------------- + GBPJPY | 142.639 | 5.8 | Mon Mar 20 09:18:22.3 2017 PDT +(1 row) + diff --git a/test/sql/insert.sql b/test/sql/insert.sql index 4d137be49..a8d1388b0 100644 --- a/test/sql/insert.sql +++ b/test/sql/insert.sql @@ -20,3 +20,14 @@ INSERT INTO error_test VALUES ('Mon Mar 20 09:18:22.3 2017', 21.1, NULL); \set ON_ERROR_STOP 1 INSERT INTO error_test VALUES ('Mon Mar 20 09:18:25.7 2017', 22.4, 'dev2'); SELECT * FROM error_test; + +--test character(9) partition keys since there were issues with padding causing partitioning errors +CREATE TABLE tick_character ( + symbol character(9) NOT NULL, mid REAL NOT NULL, spread REAL NOT NULL, + time TIMESTAMPTZ NOT NULL +); + +SELECT create_hypertable ('tick_character', 'time', 'symbol', 2); +INSERT INTO tick_character ( symbol, mid, spread, time ) VALUES ( 'GBPJPY', 142.639000, 5.80, 'Mon Mar 20 09:18:22.3 2017'); +SELECT * FROM tick_character; +