pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Schmitz <a.schmitz@cityweb.de>
To: Ben Kim <bkim@coe.tamu.edu>
To: pgsql-admin@postgresql.org
Subject: Re: parametrized query
Date: Wed, 28 Apr 2004 18:06:20 +0200
Message-ID: <200404281806.20203.a.schmitz@cityweb.de> (raw)
In-Reply-To: <Pine.GSO.4.10.10404281036520.5854-100000@edsun.coe.tamu.edu>
References: <Pine.GSO.4.10.10404281036520.5854-100000@edsun.coe.tamu.edu>


Put it into a shell script like

echo "select * from mytable where id = $1;" | psql $DBNAME

That can be executed using the shell function in psql

\! [COMMAND]   execute command in shell or start interactive shell

regards,

-Andreas


On Wednesday 28 April 2004 17:46, Ben Kim wrote:
> I tried but couldn't find an answer if this is possible in psql.
>
> Create a file named test.sql
> 	select * from mytable where id = ? (or use $1, $2...)
> Then in psql do
> 	\i test.sql 337
>
> to achieve the same effect "select * from mytable where id=337"
>
> as I would in perl
> 	$sth = $dbh -> prepare ("insert into mytable values (?, ?, ?)")
>
> Is writing a function the only way? Is there another way that can be done
> without writing a function?
>
> Thanks,
> Ben Kim
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
>                http://archives.postgresql.org

-- 





view thread (2+ messages)

Message-ID: <200404281806.20203.a.schmitz@cityweb.de>
Permalink:  ../200404281806.20203.a.schmitz@cityweb.de/
Also on:    postgresql.org/message-id/200404281806.20203.a.schmitz@cityweb.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: a.schmitz@cityweb.de, bkim@coe.tamu.edu
  Subject: Re: parametrized query
  In-Reply-To: <200404281806.20203.a.schmitz@cityweb.de>
  References: <Pine.GSO.4.10.10404281036520.5854-100000@edsun.coe.tamu.edu> <200404281806.20203.a.schmitz@cityweb.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox