sql - How to use a psql variable in the middle of other characters? -


i wondering if possible use variable in middle of other characters in sql statement psql.

for example:

psql -v x=apple -f "example.sql" 

with example.sql being:

select * :x; 

works fine. it's executed as:

select * apple; 

but how handle situation example.sql like:

select * red_:x_pie; 

i want psql read "red_apple_pie" syntax error on ":" instead.

thanks.

you'll have use string concatenation:

declare x text;  begin x = 'apple';  select * "food" "name" = 'red_' || x || '_pie'; 

i used example because it's simpler understand (table names have enclosed in quotes).


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -