Re: COALESCE not filtering well.

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Mohan Raj B <brightmohan(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: COALESCE not filtering well.
Date: 2009-07-06 12:54:12
Message-ID: 407d949e0907060554v88667c1h4fa803a1041aed71@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jul 6, 2009 at 6:37 AM, Mohan Raj B<brightmohan(at)gmail(dot)com> wrote:

> CREATE OR REPLACE FUNCTION sp_item(itemid integer, itemname character
> varying)

>   WHERE ( ( COALESCE($1,0)=0 OR  itemid=$1) AND (COALESCE($2, '')='' OR
> itemname LIKE '%'||$2||'%') ) LOOP

itemid and itemname are your parameters, they're being substituted in
the query so you're getting 10=10 and NULL LIKE '%'||NULL||'%'

--
greg
http://mit.edu/~gsstark/resume.pdf

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-07-06 14:59:03 Re: Postgres 8.3.7 Server Crash: failed to add item to the right sibling in index
Previous Message Sebastien FLAESCH 2009-07-06 12:25:40 Re: Normalize INTERVAL ouput format in a db driver