Re: psql: Is it possible to run a query from a *sql file?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: nasr(dot)laili(at)tin(dot)it
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: psql: Is it possible to run a query from a *sql file?
Date: 2005-05-01 17:24:29
Message-ID: 25274.1114968269@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Ennio-Sr <nasr(dot)laili(at)tin(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Havasvölgyi Ottó 2005-05-01 18:33:02 how to make collation work
Previous Message Ennio-Sr 2005-05-01 16:32:03 psql: Is it possible to run a query from a *sql file?