Thread: psql parsing and variable problems

psql parsing and variable problems

From
Sarah Officer
Date:
I have been looking at the psql documentation  posted on the web
site.  I am trying to set variables, but I can't seem to make that
happen.  I also notice that psql doesn't seem to parse full
backslash commands.  Are the documents out of date, or is the a bug?

\echo foo

is interpreted as \e and pops me into the editor.

\qecho foo

is interpreted as \q and exits psql.

When I try to use a variable, psql doesn't seem to recognize it.

> create table status (
>   code varchar(5) not null,
>   stat_desc varchar(30) not null);
CREATE

> insert into status(code, stat_desc) values ('A1', 'First Status');
INSERT 19082 1

> select * from status;
code|stat_desc
----+------------
A1  |First Status
(1 row)


Following the example in the documentation, I try to set a psql
variable, but psql isn't interpreting it the way I expect it to.

>\set foo 'status'
> select * from :foo;
ERROR:  parser: parse error at or near ":"
> \set foo status
> select * from :foo;
ERROR:  parser: parse error at or near ":"

Any suggestions?  Is the posted documentation out of date?  How can
I use a psql variable?  What is the alternative?  What I really want
to do is use the 'psql --set' option so I can pass the path to the
plpgsql library from the command line.

CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
:plpgsqlpath LANGUAGE 'C';

Any help is appreciated,

Sarah Officer
officers@aries.tucson.saic.com

Re: [GENERAL] psql parsing and variable problems

From
Bruce Momjian
Date:
> I have been looking at the psql documentation  posted on the web
> site.  I am trying to set variables, but I can't seem to make that
> happen.  I also notice that psql doesn't seem to parse full
> backslash commands.  Are the documents out of date, or is the a bug?
>
> \echo foo
>
> is interpreted as \e and pops me into the editor.
>
> \qecho foo
>
> is interpreted as \q and exits psql.

The web page manual reflects the coming 7.0 release.  We have talked
about splitting the docs so there is a stable and development version of
the docs, but we haven't do that yet.

--
  Bruce Momjian                        |  http://www.op.net/~candle
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026