From 6f80215d6f3c7783ac9e6025af1d1c5d701b86d9 Mon Sep 17 00:00:00 2001 From: martinko Date: Fri, 15 Feb 2013 13:47:08 +0100 Subject: [PATCH] londiste: create_partition now sets owner to match parent table --- .../functions/londiste.create_partition.sql | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sql/londiste/functions/londiste.create_partition.sql b/sql/londiste/functions/londiste.create_partition.sql index b13448b4..3d540e33 100644 --- a/sql/londiste/functions/londiste.create_partition.sql +++ b/sql/londiste/functions/londiste.create_partition.sql @@ -47,6 +47,7 @@ declare parent_oid oid; part_schema text; part_name text; + owner name; pos int4; fq_table text; fq_part text; @@ -112,6 +113,20 @@ begin sql := sql || ') inherits (' || fq_table || ')'; execute sql; + -- find out parent table owner + select o.rolname into owner + from pg_class t, pg_namespace s, pg_roles o + where t.relnamespace = s.oid + and s.nspname = parent_schema + and t.relname = parent_name + and t.relowner = o.oid; + + -- set proper part table ownership + if owner != user then + sql = 'alter table ' || fq_part || ' owner to ' || owner; + execute sql; + end if; + -- extra check constraint if i_part_field != '' then part_start := date_trunc(i_part_period, i_part_time); @@ -183,7 +198,7 @@ begin -- copy rules for r in - select rw.rulename, rw.ev_enabled, pg_get_ruledef(rw.oid) as definition + select rw.rulename, rw.ev_enabled, pg_catalog.pg_get_ruledef(rw.oid) as definition from pg_catalog.pg_rewrite rw where rw.ev_class = parent_oid and rw.rulename <> '_RETURN'::name @@ -226,4 +241,3 @@ begin return 1; end; $$ language plpgsql; - -- 2.39.5