From: | Ennio-Sr <nasr(dot)laili(at)tin(dot)it> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: psql: Is it possible to run a query from a *sql file? |
Date: | 2005-05-01 23:38:17 |
Message-ID: | 20050501233817.GA5165@deby.ei.hnet |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
* Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> [010505, 13:24]:
> Ennio-Sr <nasr(dot)laili(at)tin(dot)it> writes:
> > I've been unsuccessfully trying something like this simple one:
> [...]
>
> Perhaps you want something like
> [...]
> regression=# \set foo `read val; echo "'$val'"`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That as it!
> [...]
> 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
Hi Tom,
thanks for your quick and helpful answer.
I've already some nice shell scripts that work wonderfully; I was just
trying to learn a litte bit more about the use of the \i file.sql.
Your explanation helped me understand the whereabouts :-)
As an example, this works perfectly now:
# op_srch.sql (called from within psql with command => \i op_srch.sql:
-------------------
\echo Insert search Filed and Key: ;
\set fld `read fld; echo "$fld"`
\set key `read key; echo "'%$key%'"`
\echo :fld
\echo :key
SELECT autore, titolo, editore FROM bibl WHERE unaccent(lower(:fld))
like lower(:key);
-------------------
Thanks again.
All the best,
Ennio.
--
[Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo. \\?//
Fa' qualche cosa di cui non sei capace!" (diceva Henry Miller) ] (°|°)
[Why use Win$ozz (I say) if ... "even a fool can do that. )=(
Do something you aren't good at!" (as Henry Miller used to say) ]
From | Date | Subject | |
---|---|---|---|
Next Message | Ennio-Sr | 2005-05-02 00:38:39 | Re: psql: Is it possible to run a query from a *sql file? |
Previous Message | Volkan YAZICI | 2005-05-01 20:28:49 | Re: how to make collation work |