-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working on funcs to move default partition data to new partitions #2547
Changes from 3 commits
d6a6c4d
6bb9026
eba1a24
cd9d4e3
a83cb52
fd41aea
fdfa230
736f7f7
b2aa167
614c6a5
e024488
a25f2e4
377f244
ffb6818
fe71393
944d5cf
ff9fc54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,40 +26,52 @@ DECLARE | |
BEGIN | ||
IF ( TG_OP = 'DELETE' ) | ||
THEN | ||
alter_stmt = 'ALTER TABLE ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.partition_of_table_name) || | ||
' DETACH PARTITION ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name) || | ||
' ;'; | ||
IF ( OLD.active ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The multiple |
||
THEN | ||
alter_stmt = 'ALTER TABLE ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.partition_of_table_name) || | ||
' DETACH PARTITION ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name) || | ||
' ;'; | ||
END IF; | ||
action_stmt = 'DROP TABLE IF EXISTS ' || quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name) || ' ;'; | ||
table_name = quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.partition_of_table_name); | ||
alter_msg = 'DROP PARTITION ' || quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name); | ||
ELSIF ( TG_OP = 'UPDATE' ) | ||
THEN | ||
alter_stmt = 'ALTER TABLE ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.partition_of_table_name) || | ||
' DETACH PARTITION ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name) | ||
|| ' ;'; | ||
action_stmt = 'ALTER TABLE ' || | ||
/* If the partition was active, then detach it */ | ||
if ( OLD.active ) | ||
THEN | ||
alter_stmt = 'ALTER TABLE ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.partition_of_table_name) || | ||
' ATTACH PARTITION ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name) || ' '; | ||
IF ( (NEW.partition_parameters->>'default')::boolean ) | ||
' DETACH PARTITION ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name) | ||
|| ' ;'; | ||
END IF; | ||
|
||
/* If we are going to active or are still active, then attach the partition */ | ||
if ( NEW.active ) | ||
THEN | ||
alter_stmt = alter_stmt || 'DEFAULT ;'; | ||
action_msg = 'DEFAULT'; | ||
ELSE | ||
alter_stmt = alter_stmt || 'FOR VALUES FROM ( ' || | ||
quote_literal(NEW.partition_parameters->>'from') || '::date ) TO (' || | ||
quote_literal(NEW.partition_parameters->>'to') || '::date ) ;'; | ||
action_msg = 'FOR VALUES FROM ( ' || | ||
quote_literal(NEW.partition_parameters->>'from') || '::date ) TO (' || | ||
quote_literal(NEW.partition_parameters->>'to') || '::date )'; | ||
action_stmt = 'ALTER TABLE ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.partition_of_table_name) || | ||
' ATTACH PARTITION ' || | ||
quote_ident(OLD.schema_name) || '.' || quote_ident(OLD.table_name) || ' '; | ||
IF ( (NEW.partition_parameters->>'default') = 'true' ) | ||
THEN | ||
action_stmt = action_stmt || 'DEFAULT ;'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes malformed statement build |
||
action_msg = 'DEFAULT'; | ||
ELSE | ||
action_stmt = action_stmt || 'FOR VALUES FROM ( ' || | ||
quote_literal(NEW.partition_parameters->>'from') || '::date ) TO (' || | ||
quote_literal(NEW.partition_parameters->>'to') || '::date ) ;'; | ||
action_msg = 'FOR VALUES FROM ( ' || | ||
quote_literal(NEW.partition_parameters->>'from') || '::date ) TO (' || | ||
quote_literal(NEW.partition_parameters->>'to') || '::date )'; | ||
END IF; | ||
END IF; | ||
|
||
table_name = quote_ident(NEW.schema_name) || '.' || quote_ident(NEW.partition_of_table_name); | ||
action_msg = 'UPDATE PARTITION ' || quote_ident(NEW.schema_name) || '.' || quote_ident(NEW.table_name) || | ||
action_msg = 'ALTER PARTITION ' || quote_ident(NEW.schema_name) || '.' || quote_ident(NEW.table_name) || | ||
' ' || action_msg; | ||
ELSIF ( TG_OP = 'INSERT' ) | ||
THEN | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to fix a bug copying partitioned table data.