Re: psql: Is it possible to run a query from a *sql file? - Mailing list pgsql-novice

From Tom Lane
Subject Re: psql: Is it possible to run a query from a *sql file?
Date
Msg-id 25274.1114968269@sss.pgh.pa.us
Whole thread Raw
In response to psql: Is it possible to run a query from a *sql file?  (Ennio-Sr <nasr.laili@tin.it>)
Responses Re: psql: Is it possible to run a query from a *sql file?  (Ennio-Sr <nasr.laili@tin.it>)
Re: psql: Is it possible to run a query from a *sql file?  (Ennio-Sr <nasr.laili@tin.it>)
List pgsql-novice
Ennio-Sr <nasr.laili@tin.it> writes:
> I've been unsuccessfully trying something like this simple one:

> \! echo "insert key: ";read key; export $key;
> SELECT autore, titolo, editore FROM bibl WHERE autore like '%[$key]%'

Perhaps you want something like

regression=# \echo prompt
prompt
regression=# \set foo `read val; echo "'$val'"`
qwerty
regression=# select :foo;
 ?column?
----------
 qwerty
(1 row)

although on the whole I think you'd be better off turning this around:
write it as a shell script and invoke psql for individual steps,
rather than the other way round.  It's hard to envision a script that
needs user interaction and won't shortly thereafter need control
structures etc.

            regards, tom lane

pgsql-novice by date:

Previous
From: Ennio-Sr
Date:
Subject: psql: Is it possible to run a query from a *sql file?
Next
From: Havasvölgyi Ottó
Date:
Subject: how to make collation work