Skip to content

Commit 3999694

Browse files
committed
check if operator + and - are available for given type in append_range_partition() and prepend_range_partition() functions
1 parent 73e0b26 commit 3999694

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

init.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,3 +896,13 @@ CREATE OR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
896896
init_callback REGPROCEDURE)
897897
RETURNS VOID AS 'pg_pathman', 'invoke_on_partition_created_callback'
898898
LANGUAGE C;
899+
900+
/*
901+
*
902+
*/
903+
CREATE OR REPLACE FUNCTION @extschema@.is_operator_supported(
904+
type_oid OID,
905+
opname TEXT)
906+
RETURNS BOOLEAN AS 'pg_pathman', 'is_operator_supported'
907+
LANGUAGE C;
908+

range.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ BEGIN
573573

574574
v_atttype := @extschema@.get_partition_key_type(parent_relid);
575575

576+
IF NOT @extschema@.is_operator_supported(v_atttype, '+') THEN
577+
RAISE EXCEPTION 'Type % doesn''t support ''+'' operator', v_atttype::regtype;
578+
END IF;
579+
576580
SELECT range_interval
577581
FROM @extschema@.pathman_config
578582
WHERE partrel = parent_relid
@@ -678,6 +682,10 @@ BEGIN
678682

679683
v_atttype := @extschema@.get_partition_key_type(parent_relid);
680684

685+
IF NOT @extschema@.is_operator_supported(v_atttype, '-') THEN
686+
RAISE EXCEPTION 'Type % doesn''t support ''-'' operator', v_atttype::regtype;
687+
END IF;
688+
681689
SELECT range_interval
682690
FROM @extschema@.pathman_config
683691
WHERE partrel = parent_relid

src/pl_funcs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ PG_FUNCTION_INFO_V1( check_security_policy );
6969
PG_FUNCTION_INFO_V1( debug_capture );
7070
PG_FUNCTION_INFO_V1( get_pathman_lib_version );
7171

72+
PG_FUNCTION_INFO_V1( is_operator_supported );
73+
7274

7375
/*
7476
* User context for function show_partition_list_internal().
@@ -900,6 +902,20 @@ check_security_policy(PG_FUNCTION_ARGS)
900902
PG_RETURN_BOOL(true);
901903
}
902904

905+
Datum
906+
is_operator_supported(PG_FUNCTION_ARGS)
907+
{
908+
Oid tp = PG_GETARG_OID(0);
909+
char *opname = TextDatumGetCString(PG_GETARG_TEXT_P(1));
910+
Oid opid;
911+
912+
opid = compatible_oper_opid(list_make1(makeString(opname)), tp, tp, true);
913+
if (!OidIsValid(opid))
914+
PG_RETURN_BOOL(false);
915+
916+
PG_RETURN_BOOL(true);
917+
}
918+
903919

904920
/*
905921
* -------

src/pl_range_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ interval_is_trivial(Oid atttype, Datum interval, Oid interval_type)
795795
/*
796796
* If operator result type isn't the same as original value then
797797
* convert it. We need this to make sure that specified interval would
798-
* change the _origianal_ value somehow. For example, if we add one second
798+
* change the _original_ value somehow. For example, if we add one second
799799
* to a date then we'll get a timestamp which is one second later than
800800
* original date (obviously). But when we convert it back to a date we will
801801
* get the same original value meaning that one second interval wouldn't

0 commit comments

Comments
 (0)