Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 00400634408 for ; Mon, 27 Apr 2009 13:36:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 43582-03 for ; Mon, 27 Apr 2009 13:36:18 -0300 (ADT) X-Greylist: delayed 00:06:46.294148 by SQLgrey-1.7.6 Received: from mail.gmx.com (mail.gmx.com [213.165.64.42]) by mail.postgresql.org (Postfix) with SMTP id E80B9634432 for ; Mon, 27 Apr 2009 13:36:18 -0300 (ADT) Received: (qmail invoked by alias); 27 Apr 2009 16:29:29 -0000 Received: from 93-103-130-13.static.t-2.net (EHLO 93-103-130-13.static.t-2.net) [93.103.130.13] by mail.gmx.com (mp-eu001) with SMTP; 27 Apr 2009 18:29:29 +0200 X-Authenticated: #55513569 X-Provags-ID: V01U2FsdGVkX1+3XL11HM+3HDPYL52Sm9KMcXYKAFV6MTsI8Q/ZxJ llgePZRoPxyyqn From: Jure Kobal To: pgsql-sql@postgresql.org, landsharkdaddy Subject: Re: Query with Parameters and Wildcards Date: Mon, 27 Apr 2009 18:29:26 +0200 User-Agent: KMail/1.9.9 References: <23248274.post@talk.nabble.com> <23257346.post@talk.nabble.com> <487E9B6FF30F43DFB2DC0B00E81DAF7A@dayatPC> In-Reply-To: <487E9B6FF30F43DFB2DC0B00E81DAF7A@dayatPC> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904271829.26557.j.kobal@gmx.com> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.51 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/126 X-Sequence-Number: 32472 In the original select you missed a small part. The operation || needs a value on every side and you missed the value on the left side. You had it as: WHERE (customerlastname ILIKE || '%') instead of WHERE (customerlastname ILIKE 'lastname' || '%'). And that is the reason for the error you got. The function from dayat has a small mistake. It should be: CREATE OR REPLACE FUNCTION TEST(lastname VARCHAR) else it will result in an error because of the missing space. On Monday 27 of April 2009 16:47:40 dayat wrote: > Do you run this code in the function? If so, the following example function > with LANGUAGE SQL function: > > CREATE OR REPLACE FUNCTION TEST(lastnameVARCHAR) > RETURNS SETOF lanemanager.customers > AS $$ > SELECT customercellphone, customercity, customerdatecreated, > customerdatelastmodified, customeremail, customerfax, customerfirstname, > customerid, customerlastname, customermiddleinitial, customerphone, > customerreferredby, customerstateabbr, customerstreet1, customerstreet2, > customersuffix, customertitle, customerworkphone, customerworkphoneext, > customerzip FROM lanemanager.customers WHERE (customerlastname ILIKE $1 || > '%') > $$ > LANGUAGE SQL; > > Please tell me is it work for you. > > Regards > Hidayat > > ----- Original Message ----- > From: "landsharkdaddy" > To: > Sent: Monday, April 27, 2009 9:19 PM > Subject: Re: [SQL] Query with Parameters and Wildcards > > > When I try the following like you suggested I get an error that says > > "operator does not exist: || unknown > > > > > > > > SELECT customercellphone, customercity, customerdatecreated, > > customerdatelastmodified, customeremail, customerfax, customerfirstname, > > customerid, customerlastname, customermiddleinitial, customerphone, > > customerreferredby, customerstateabbr, customerstreet1, customerstreet2, > > customersuffix, customertitle, customerworkphone, customerworkphoneext, > > customerzip FROM lanemanager.customers WHERE (customerlastname ILIKE || > > '%') > > > > landsharkdaddy wrote: > >> I have a query that works on SQL Server to return customers that contain > >> the string entered by the user by accepting parameters and using the > >> LIKE keyword. I would like to move this to postgreSQL but I'm just not > >> sure how > >> to get it done. This is the query > >> > >> SELECT * FROM Customers WHERE FirstName LIKE @custfirst + '%'; > >> > >> This works great on SQL Server but not on postgreSQL. Any help would be > >> appreciated. > > __________________________________________________ > Apakah Anda Yahoo!? > Lelah menerima spam? Surat Yahoo! memiliki perlindungan terbaik terhadap > spam http://id.mail.yahoo.com