Skip site navigation (1) Skip section navigation (2)

Re: parametrized query

From: Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>
To: Ben Kim <bkim(at)coe(dot)tamu(dot)edu>, pgsql-admin(at)postgresql(dot)org
Subject: Re: parametrized query
Date: 2004-04-28 16:06:20
Message-ID: 200404281806.20203.a.schmitz@cityweb.de (view raw or flat)
Thread:
Lists: 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

-- 



In response to

pgsql-admin by date

Next:From: Jie LiangDate: 2004-04-28 18:12:17
Subject: 7.4.2 out of memory
Previous:From: Ben KimDate: 2004-04-28 15:46:54
Subject: parametrized query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group