Page 1 of 1

Set variable to value containing a space

Posted: Mon Feb 23, 2015 2:35 pm
by hopewell
Hi all,

How can I set a variable equal to a value that contains a space?

If I do it the following the strings data1 and data2 are concatenated:

Code: Select all

dbadmin=> \set myvar data1 data2
dbadmin=> \echo :myvar
data1data2
If I use quotes, I get the space, but I also get the quotes:

Code: Select all

dbadmin=> \set myvar "data1 data2"
dbadmin=> \echo :myvar
"data1 data2"
I don't want the quotes!

Thank you

Re: Set variable to value containing a space

Posted: Mon Feb 23, 2015 3:46 pm
by JimKnicely
Try single quotes:

Code: Select all

dbadmin=> \set myvar 'data1 data2'
dbadmin=> \echo :myvar
data1 data2

Re: Set variable to value containing a space

Posted: Mon Mar 02, 2015 3:37 pm
by hopewell
Nice, thanks Jim!