Last active
June 12, 2020 19:00
-
-
Save slabad/d7892f275572700d6a6173dfd5a22f0f to your computer and use it in GitHub Desktop.
Dynamic Table Creation #psql #postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO | |
$$ | |
BEGIN | |
EXECUTE format('CREATE TABLE %I AS SELECT * FROM backup', 'backup_' || to_char(CURRENT_DATE,'yyyy-mm-dd')); | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE OR REPLACE FUNCTION fn_hello(v_table text) | |
returns void | |
AS $$ | |
BEGIN | |
EXECUTE format('create table rollback.%I (id int, name text)', v_table || '_' || to_char(CURRENT_DATE, 'yyyymmdd')); | |
END; | |
$$ | |
LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment