Skip to content

Commit d8f4109

Browse files
committed
pathman: schema-qualified names aren't mandatory anymore
1 parent 62d14ce commit d8f4109

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

contrib/pathman/expected/pathman.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ NOTICE: function test.hash_rel_hash_update_trigger_func() does not exist, skipp
333333
(1 row)
334334

335335
DROP TABLE test.hash_rel CASCADE;
336-
NOTICE: drop cascades to 3 other objects
337336
SELECT pathman.drop_range_partitions('test.num_range_rel');
338337
drop_range_partitions
339338
-----------------------

contrib/pathman/sql/hash.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ DECLARE
108108
rec RECORD;
109109
num INTEGER := 0;
110110
BEGIN
111+
relation := @extschema@.validate_relname(relation);
112+
111113
/* Drop trigger first */
112114
PERFORM @extschema@.drop_hash_triggers(relation);
113115
DELETE FROM @extschema@.pathman_config WHERE relname = relation;
114-
-- EXECUTE format('DROP TABLE %s CASCADE', relation);
115-
116+
117+
FOR rec in (SELECT * FROM pg_inherits WHERE inhparent = relation::regclass::oid)
118+
LOOP
119+
EXECUTE format('DROP TABLE %s', rec.inhrelid::regclass::text);
120+
END LOOP;
121+
116122
-- FOR rec in (SELECT * FROM pg_inherits WHERE inhparent = relation::regclass::oid)
117123
-- LOOP
118124
-- EXECUTE format('DROP FUNCTION IF EXISTS %s_hash_update_trigger_func() CASCADE'

contrib/pathman/sql/init.sql

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,23 @@ LANGUAGE plpgsql;
110110
CREATE OR REPLACE FUNCTION @extschema@.validate_relname(relname TEXT)
111111
RETURNS TEXT AS
112112
$$
113-
DECLARE
114-
ret TEXT := lower(relname);
115113
BEGIN
116-
IF NOT ret ~ '^([a-z_]+[a-z0-9_]*)\.([a-z_]+[a-z0-9_]*)$' THEN
117-
RAISE EXCEPTION 'Incorrect relation name. It must be fully qualified: <schema>.<relname>';
118-
END IF;
119-
RETURN ret;
114+
RETURN @extschema@.get_schema_qualified_name(relname::regclass, '.');
120115
END
121116
$$
122117
LANGUAGE plpgsql;
123118

124119

125120
/*
126-
*
121+
* Returns schema-qualified name for table
127122
*/
128-
CREATE OR REPLACE FUNCTION @extschema@.get_schema_qualified_name(cls regclass)
123+
CREATE OR REPLACE FUNCTION @extschema@.get_schema_qualified_name(
124+
cls REGCLASS
125+
, delimiter TEXT DEFAULT '_')
129126
RETURNS TEXT AS
130127
$$
131128
BEGIN
132-
RETURN relnamespace::regnamespace || '_' || relname FROM pg_class WHERE oid = cls::oid;
129+
RETURN relnamespace::regnamespace || delimiter || relname FROM pg_class WHERE oid = cls::oid;
133130
END
134131
$$
135132
LANGUAGE plpgsql;

contrib/pathman/sql/range.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ DECLARE
477477
EXECUTE format(''INSERT INTO %%s SELECT $1.*'', v_part_relid::regclass)
478478
USING NEW;
479479
ELSE
480-
RAISE EXCEPTION ''ERROR: Cannot determine approprite partition'';
480+
RAISE EXCEPTION ''ERROR: Cannot find partition'';
481481
END IF;
482482
END IF;
483483
RETURN NULL;

0 commit comments

Comments
 (0)