Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DD39DB5DBD0 for ; Tue, 5 Jul 2011 11:31:57 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 46758-01 for ; Tue, 5 Jul 2011 14:31:51 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zql.com (zql.com [206.222.31.58]) by mail.postgresql.org (Postfix) with ESMTP id 5B1E9B5DBE6 for ; Tue, 5 Jul 2011 11:31:51 -0300 (ADT) Received: from localhost ([127.0.0.1]) by zql.com with smtp (Exim 4.68) (envelope-from ) id 1Qe6fH-0005OD-KK; Tue, 05 Jul 2011 10:31:51 -0400 From: "Greg Sabino Mullane" To: pgsql-interfaces@postgresql.org Subject: Re: DBD::Pg - question on using LIKE operator with bind variable X-PGP-Key: 2529 DF6A B8F7 9407 E944 45B4 BC9B 9067 1496 4AC8 X-Request-PGP: http://www.biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 In-Reply-To: <55377.71.167.232.56.1309786189.squirrel@webmail.brama.com> Date: Tue, 5 Jul 2011 14:31:51 -0000 X-Mailer: JoyMail 2.4.0 Message-ID: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201107/3 X-Sequence-Number: 6961 -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 > I would like to use a bind variable with a LIKE operator. > > An example of the query that I'm trying to use is the following: > SELECT ? , aa.f1, aa.f2, aa.f3, aa.f4 FROM orgs aa WHERE aa.f1 LIKE '%?%' > How do I get the conditional part of the query (WHERE aa.f1 LIKE '%?%') to > accept a bind variable? (What did you try? What did you get?) It's not clear why you have a question mark in the SELECT clause, but you can solve the WHERE clause part by making the placeholder cover the entire condition, rather than try to pass in only part of it via the arguments. So try this instead: $SQL = 'SELECT relname FROM pg_class WHERE relname LIKE ?'; $sth = $dbh->prepare($SQL); $count = $sth->execute('%a%'); print "Count is $count\n"; - -- Greg Sabino Mullane greg@turnstep.com End Point Corporation http://www.endpoint.com/ PGP Key: 0x14964AC8 201107051030 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -----BEGIN PGP SIGNATURE----- iEYEAREDAAYFAk4TIEIACgkQvJuQZxSWSsgLCQCgtD6CdcTr8mpKeoBzYtaKtPjH tfgAnA68obgfGN5dcORG4rZfqvejjkkC =QZaM -----END PGP SIGNATURE-----