Skip site navigation (1) Skip section navigation (2)

a few Questions about quoted varaibles in psql

From: "Leo Leo" <leoel(at)gmx(dot)at>
To: pgsql-sql(at)postgresql(dot)org
Subject: a few Questions about quoted varaibles in psql
Date: 2004-02-26 15:58:28
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql

How can I interpret a variable in psql, when the variable has to be quoted?

for example:

\set myVar myValue
\echo :myVar
The Result ist then "myValue" ==> ok

But: in my case the variable-values have to be in quotes:

\set db_username myUsername
\set db_password myPassword

CREATE USER :db_username WITH PASSWORD :db_password

==> This will not work, because you need quotes

CREATE USER :db_username WITH PASSWORD ':db_password'

==> This will create the user with Password :db_password and not myPassword
(so it takes the name of the varibale and not den value)

I played a bit with excaping, but even '\'':db_password'\'' will not work

What can I do, in order to achieve, that psql interprets a variable in

Another Problem:
How can I concatenate a variable with a string without having a space in

\set foo bar
\echo :foo test
==> bar test  (but there is a space in between)

\echo :foo||test
==> this does not work (I want bartest)
Is it somehow possible to do this?

Thanks for your help!


GMX ProMail (250 MB Mailbox, 50 FreeSMS, Virenschutz, 2,99 EUR/Monat...)
jetzt 3 Monate GRATIS + 3x DER SPIEGEL +++ +++

pgsql-sql by date

Next:From: Michael ChaneyDate: 2004-02-26 16:37:02
Subject: Re: Last day of month
Previous:From: Stephan SzaboDate: 2004-02-26 15:29:27
Subject: Re: Return more than a record

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group