pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedparametrized query
2+ messages / 2 participants
[nested] [flat]
* parametrized query
@ 2004-04-28 15:46 Ben Kim <bkim@coe.tamu.edu>
0 siblings, 1 reply; 2+ messages in thread
From: Ben Kim @ 2004-04-28 15:46 UTC (permalink / raw)
To: pgsql-admin
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: parametrized query
@ 2004-04-28 16:06 Andreas Schmitz <a.schmitz@cityweb.de>
parent: Ben Kim <bkim@coe.tamu.edu>
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schmitz @ 2004-04-28 16:06 UTC (permalink / raw)
To: Ben Kim <bkim@coe.tamu.edu>; pgsql-admin
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
--
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2004-04-28 16:06 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-04-28 15:46 parametrized query Ben Kim <bkim@coe.tamu.edu>
2004-04-28 16:06 ` Andreas Schmitz <a.schmitz@cityweb.de>
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