Last active
September 6, 2018 16:11
-
-
Save joshlk/40bac1f7e9441f55ac9aaa2bf1902c24 to your computer and use it in GitHub Desktop.
Using a variable for input and output table in Postgres SQL pl/pgsql
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
CREATE OR REPLACE FUNCTION query( | |
in_tb character varying, | |
out_tb character varying | |
) | |
RETURNS integer | |
LANGUAGE plpgsql | |
AS $function$ | |
BEGIN | |
EXECUTE | |
'CREATE TABLE ' | |
|| out_tb | |
|| ' AS SELECT * FROM ' | |
|| in_tb | |
|| ' LIMIT 10'; | |
RETURN 1; | |
END | |
$function$; | |
select query('input_table', 'output_table'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment