[GENERAL] psql variables
I use a bash script (similar to following example) to update tables. psql -v passed_in_var=\'some_value\' -f script_name Is it possible to pass a value back from psql to the bash script? Thanks, Paul Cunningham ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [GENERAL] psql variables
On Mon, 14 Mar 2005 11:06:32 -0500, Paul Cunningham <[EMAIL PROTECTED]> wrote: > I use a bash script (similar to following example) to update tables. > > psql -v passed_in_var=\'some_value\' -f script_name > > Is it possible to pass a value back from psql to the bash script? You can use '\! [ command ]' to execute shell commands within psql. This may not be what you want though. George Essig ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [GENERAL] psql variables
In article <[EMAIL PROTECTED]>, Paul Cunningham <[EMAIL PROTECTED]> wrote: % I use a bash script (similar to following example) to update tables. % % psql -v passed_in_var=\'some_value\' -f script_name % % Is it possible to pass a value back from psql to the bash script? If you run it like this $(psql -v passed_in_var=\'some_value\' -f script_name) and arrange for all the script output to be in the form var1="value 1" var2="value 2" var3="value 3" ... then var1, var2, etc will be set in bash (or ksh, or the posix shell). Note that there are no spaces around the equals signs. -- Patrick TJ McPhee North York Canada [EMAIL PROTECTED] ---(end of broadcast)--- TIP 8: explain analyze is your friend
Re: [GENERAL] psql variables
On Fri, 25 Mar 2005, Patrick TJ McPhee wrote: In article <[EMAIL PROTECTED]>, Paul Cunningham <[EMAIL PROTECTED]> wrote: % I use a bash script (similar to following example) to update tables. % % psql -v passed_in_var=\'some_value\' -f script_name % % Is it possible to pass a value back from psql to the bash script? If you run it like this $(psql -v passed_in_var=\'some_value\' -f script_name) and arrange for all the script output to be in the form var1="value 1" var2="value 2" var3="value 3" ... then var1, var2, etc will be set in bash (or ksh, or the posix shell). Note that there are no spaces around the equals signs. btw, how to expand psql variable in -c "" ? For example, this works as expected psql discovery-test -v a1=\'message_parts\' -f tt.sql but not psql discovery-test -v a1=\'message_parts\' -c "select * from iostat where relname=:a1;" ERROR: parse error at or near ":" at character 36 LINE 1: select * from iostat where relname=:a1; Regards, Oleg _ Oleg Bartunov, sci.researcher, hostmaster of AstroNet, Sternberg Astronomical Institute, Moscow University (Russia) Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(095)939-16-83, +007(095)939-23-83 ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]