Substitution Variables...

Moderator: NorbertKrupa

Post Reply
debfawn
Beginner
Beginner
Posts: 47
Joined: Tue Jan 29, 2013 2:30 pm

Substitution Variables...

Post by debfawn » Wed Jan 30, 2013 4:34 pm

Hi,

I have a quick question about variables in vsql. I'd like to set up a variable that I can use as text in a SELECT statement.

This is what I tried, but I get an error:

Code: Select all

dbadmin=> \set myname debbie
dbadmin=> \echo myname
myname
dbadmin=> select 'My name is ' || :myname;
ERROR 2624:  Column "debbie" does not exist
Is there something special I need to do so that I can get this result?

Code: Select all

dbadmin=> select 'My name is ' || :myname;
     ?column?
-------------------
 My name is debbie
Thanks!

doug_harmon
Beginner
Beginner
Posts: 36
Joined: Fri Feb 17, 2012 6:09 pm
Contact:

Re: Substitution Variables...

Post by doug_harmon » Thu Jan 31, 2013 8:48 pm

Code: Select all

dbadmin=> \set myname '''' debbie ''''
dbadmin=> select 'My name is ' || :myname ;
     ?column?
-------------------
 My name is debbie
(1 row)

debfawn
Beginner
Beginner
Posts: 47
Joined: Tue Jan 29, 2013 2:30 pm

Re: Substitution Variables...

Post by debfawn » Fri Feb 01, 2013 12:17 am

Your name is debbie too?!?!

Just kidding! Thanks, Doug! Now I can use this syntax in my scripts!

Post Reply

Return to “vSQL”