Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created February 15, 2018 22:39
Show Gist options
  • Save mhkeller/4d5d5947d64616ded7bf558f73f476e8 to your computer and use it in GitHub Desktop.
Save mhkeller/4d5d5947d64616ded7bf558f73f476e8 to your computer and use it in GitHub Desktop.
Setting a variable in pgsql
-- least onerous option from here https://stackoverflow.com/questions/1490942/how-to-declare-a-variable-in-a-postgresql-query#16552441
set session my.vars.id = '%my_string%';
SELECT
*
FROM
my_table
WHERE
field LIKE current_setting('my.vars.id')::text
OR other_field LIKE current_setting('my.vars.id')::text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment