pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tod McQuillin <devin@spamcop.net>
To: Randall Perry <rgp@systame.com>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [GENERAL] Var substitution in SELECT statements
Date: Tue, 24 Apr 2001 21:01:56 -0500 (CDT)
Message-ID: <Pine.GSO.4.31.0104242058350.4814-100000@sysadmin> (raw)
In-Reply-To: <B70A4D23.A28D%rgp@systame.com>

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





view thread (4+ messages)

Message-ID: <Pine.GSO.4.31.0104242058350.4814-100000@sysadmin>
Permalink:  ../Pine.GSO.4.31.0104242058350.4814-100000@sysadmin/
Also on:    postgresql.org/message-id/Pine.GSO.4.31.0104242058350.4814-100000@sysadmin

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: devin@spamcop.net, rgp@systame.com
  Subject: Re: [GENERAL] Var substitution in SELECT statements
  In-Reply-To: <Pine.GSO.4.31.0104242058350.4814-100000@sysadmin>

* 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