Last active
December 22, 2020 09:38
-
-
Save malkab/889889b7255fed7516a82da3250ff663 to your computer and use it in GitHub Desktop.
PostgreSQL - Variables in SQL Scripts
This file contains 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
/** | |
Usage and expansion of variables in SQL scripts to be executed with psql \i command. | |
*/ | |
-- Expansion with quotes as varchar variables example | |
\set analysis_id a | |
delete from warehouse.analysis_tasks where analysis_id = :'analysis_id'; | |
delete from warehouse.properties where analysis_id = :'analysis_id'; | |
delete from sunnsaas.analysis where analysis_id = :'analysis_id'; | |
-- Use in SQL commands body example | |
\set myvariable value | |
select * from :myvariable.table1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment