pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedVar substitution in SELECT statements
4+ messages / 3 participants
[nested] [flat]
* Var substitution in SELECT statements
@ 2001-04-24 01:20 Randall Perry <rgp@systame.com>
2001-04-24 01:41 ` Re: Var substitution in SELECT statements Randall Perry <rgp@systame.com>
2001-04-25 02:01 ` Re: [GENERAL] Var substitution in SELECT statements Tod McQuillin <devin@spamcop.net>
0 siblings, 2 replies; 4+ messages in thread
From: Randall Perry @ 2001-04-24 01:20 UTC (permalink / raw)
To: pgsql-interfaces; pgsql-general@postgresql.org
This works:
$res = $conn->exec("select cust, contact, user_name, email from $t where
user_name = a1a");
This doesn't:
$c = "a1a";
$res = $conn->exec("select cust, contact, user_name, email from $t where
user_name = $c");
and returns the error:
Attribute 'a1a' not found
How do you do var substitution with the Pg module in Perl?
--
Randy Perry
sysTame
Mac Consulting/Sales
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Var substitution in SELECT statements
2001-04-24 01:20 Var substitution in SELECT statements Randall Perry <rgp@systame.com>
@ 2001-04-24 01:41 ` Randall Perry <rgp@systame.com>
2001-04-24 07:15 ` Re: Var substitution in SELECT statements will trillich <will@serensoft.com>
1 sibling, 1 reply; 4+ messages in thread
From: Randall Perry @ 2001-04-24 01:41 UTC (permalink / raw)
To: pgsql-general@postgresql.org; pgsql-interfaces
on 4/23/01 9:20 PM, Randall Perry at rgp@systame.com wrote:
> This works:
> $res = $conn->exec("select cust, contact, user_name, email from $t where
> user_name = a1a");
>
> This doesn't:
> $c = "a1a";
> $res = $conn->exec("select cust, contact, user_name, email from $t where
> user_name = $c");
>
> and returns the error:
> Attribute 'a1a' not found
>
>
> How do you do var substitution with the Pg module in Perl?
Whoops! Needed to quote the var as so (for $c above):
$c = "\'$c\'";
Works now.
--
Randy Perry
sysTame
Mac Consulting/Sales
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Var substitution in SELECT statements
2001-04-24 01:20 Var substitution in SELECT statements Randall Perry <rgp@systame.com>
2001-04-24 01:41 ` Re: Var substitution in SELECT statements Randall Perry <rgp@systame.com>
@ 2001-04-24 07:15 ` will trillich <will@serensoft.com>
0 siblings, 0 replies; 4+ messages in thread
From: will trillich @ 2001-04-24 07:15 UTC (permalink / raw)
To: pgsql-general@postgresql.org
On Mon, Apr 23, 2001 at 09:41:51PM -0400, Randall Perry wrote:
> on 4/23/01 9:20 PM, Randall Perry at rgp@systame.com wrote:
>
> > This works:
> > $res = $conn->exec("select cust, contact, user_name, email from $t where
> > user_name = a1a");
> >
> > This doesn't:
> > $c = "a1a";
> > $res = $conn->exec("select cust, contact, user_name, email from $t where
> > user_name = $c");
> >
> > and returns the error:
> > Attribute 'a1a' not found
> >
> >
> > How do you do var substitution with the Pg module in Perl?
>
> Whoops! Needed to quote the var as so (for $c above):
>
> $c = "\'$c\'";
>
> Works now.
also try
$sth = $dbh->prepare("select fields from tbl where f1 = ? and f2 = ?")
$sth->execute($val1,$val2);
while ($ref = $sth->fetchrow_hashref()) {
...
}
$sth->finish();
--
don't visit this page. it's bad for you. take my expert word for it.
http://www.salon.com/people/col/pagl/2001/03/21/spring/index1.html
will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [GENERAL] Var substitution in SELECT statements
2001-04-24 01:20 Var substitution in SELECT statements Randall Perry <rgp@systame.com>
@ 2001-04-25 02:01 ` Tod McQuillin <devin@spamcop.net>
1 sibling, 0 replies; 4+ messages in thread
From: Tod McQuillin @ 2001-04-25 02:01 UTC (permalink / raw)
To: Randall Perry <rgp@systame.com>; +Cc: pgsql-interfaces
On Mon, 23 Apr 2001, Randall Perry wrote:
> This works:
> $res = $conn->exec("select cust, contact, user_name, email from $t where
> user_name = a1a");
>
> This doesn't:
> $c = "a1a";
> $res = $conn->exec("select cust, contact, user_name, email from $t where
> user_name = $c");
>
> and returns the error:
> Attribute 'a1a' not found
>
> How do you do var substitution with the Pg module in Perl?
First, I would highly recommend you investigate the perl DBI abd DBD::Pg
modules -- they handle variable placeholders quite efficiently and
correctly.
But for your problem above, surely you must use single quotes around any
string you include as a literal in an SQL query.
$res = $conn->exec("select cust, contact, user_name, email from $t
where user_name = '$c'");
--
Tod McQuillin
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-04-25 02:01 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-24 01:20 Var substitution in SELECT statements Randall Perry <rgp@systame.com>
2001-04-24 01:41 ` Randall Perry <rgp@systame.com>
2001-04-24 07:15 ` will trillich <will@serensoft.com>
2001-04-25 02:01 ` Tod McQuillin <devin@spamcop.net>
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