Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 45F16632612 for ; Mon, 27 Apr 2009 08:41:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 28111-05 for ; Mon, 27 Apr 2009 08:41:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from megafon.hr (megafon.hr [213.202.104.5]) by mail.postgresql.org (Postfix) with ESMTP id 2D4C86323FA for ; Mon, 27 Apr 2009 08:41:07 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by megafon.hr (Postfix) with ESMTP id E70657EC005; Mon, 27 Apr 2009 13:41:03 +0200 (CEST) X-Virus-Scanned: ClamAV at megafon.hr Received: from megafon.hr ([127.0.0.1]) by localhost (localhost.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CISImrb3h73e; Mon, 27 Apr 2009 13:40:58 +0200 (CEST) Received: from [192.168.1.94] (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: mike) by megafon.hr (Postfix) with ESMTPSA id BDD4B7EC004; Mon, 27 Apr 2009 13:40:58 +0200 (CEST) Message-ID: <49F599CB.9000701@megafon.hr> Date: Mon, 27 Apr 2009 13:40:59 +0200 From: Mario Splivalo User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: landsharkdaddy CC: pgsql-sql@postgresql.org Subject: Re: Query with Parameters and Wildcards References: <23248274.post@talk.nabble.com> <23250153.post@talk.nabble.com> In-Reply-To: <23250153.post@talk.nabble.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/123 X-Sequence-Number: 32469 landsharkdaddy wrote: > I have not tried that but I will in the morning. The @ in SQL is used to > indicate a parameter passed to the query. In PostgreSQL it seems that the : > is the same as the @ in SQL Server. I tried something like: > > SELECT * FROM Customers WHERE FirstName LIKE :custfirst + '%'; > > And it told me that the + could not be used. Not sure the exact message but > I will check again tomorrow and see what it was and post the results. T-SQL defines that variables need to start with @ (like, for instance, in PHP they star with $). In postgres you have positional parametars, $1, for instance. You could, for instance, write SQL function in postgres that would do what you need: CREATE FUNCTION get_customers_with_like (a_name_part character varying) RETURNS SETOF customers AS $$ SELECT * FROM customers WHERE firstname LIKE $1 || '%'; $$ LANGUAGE 'sql'; In postgres, you use '||' for string concatenation (instead of '+' in T-SQL). Mario