Question

I'm calling a bash script which prepares some directories etc. At some point it also calls a psql script something like this:

psql $PSQL_LOGIN -v SERVER=$SERVER

So far so good.

The sql that I want to execute is something like this:

select 'wget :SERVER.xxxx.com?geoX=id1&geoY=id2' 
from table1 where id1 > zzz;

What I expect out of this is a string that looks like

wget test.xxx.com?geoX=yyy&geoY=qqq

In oracle I could do something like

select 'wget' || :SERVER '.xxx.com?geoX='|| id1 || etc etc

But I cannot make it work in postgres when it should be embedded in a string I've tried to escape the ' and withoud but so far no luck. Anybody got any ideas?

Was it helpful?

Solution

I've found the answer to this question. When calling from the shell script, its in the shell script itself that the escaping must be done. So instead of the above i should do the calling like this :

psql $PSQL_LOGIN -V SERVER="'$SERVER'"

that is double quote and single quote. Then the sql file can be done the same way as in Oracle :

select 'wget' || :SERVER '.example.com?geoX='|| id1 || ' etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top