From: | Tod McQuillin <devin(at)spamcop(dot)net> |
---|---|
To: | Randall Perry <rgp(at)systame(dot)com> |
Cc: | <pgsql-interfaces(at)postgresql(dot)org> |
Subject: | Re: [GENERAL] Var substitution in SELECT statements |
Date: | 2001-04-25 02:01:56 |
Message-ID: | Pine.GSO.4.31.0104242058350.4814-100000@sysadmin |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general 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
From | Date | Subject | |
---|---|---|---|
Next Message | Theo van der Sluijs | 2001-04-25 07:31:46 | state locked row (PLEASE HELP ME) |
Previous Message | Charles Tassell | 2001-04-25 01:52:45 | Re: Problem with postgreSQL (number of backends) |
From | Date | Subject | |
---|---|---|---|
Next Message | Horst Herb | 2001-04-25 06:23:01 | MS Windows libpq++ |
Previous Message | wsmuir | 2001-04-24 18:52:09 | SPI |