Re: BUG #5001: can not prepare for where $1 is null - Mailing list pgsql-bugs

From Pavel Stehule
Subject Re: BUG #5001: can not prepare for where $1 is null
Date
Msg-id 162867790908210952j6572e589o1e23fa77aa703316@mail.gmail.com
Whole thread Raw
In response to BUG #5001: can not prepare for where $1 is null  ("" <94487509@qq.com>)
List pgsql-bugs
Hello

2009/8/21  <94487509@qq.com>:
>
> The following bug has been logged online:
>
> Bug reference: =C2=A0 =C2=A0 =C2=A05001
> Logged by:
> Email address: =C2=A0 =C2=A0 =C2=A094487509@qq.com
> PostgreSQL version: 8.3.3
> Operating system: =C2=A0 linux
> Description: =C2=A0 =C2=A0 =C2=A0 =C2=A0can not prepare for where $1 is n=
ull
> Details:
>
> why can not prepare like this? thanks!
> =C2=A0prepare ssss as select * from test where $1 is null;
> =C2=A0ERROR: =C2=A0could not determine data type of parameter $1

Probably you are thinking, so first parameter is name of column. But
this is wrong idea. You cannot parametrize column or table names. In
this case - first parameter will be constant expression - with null
value it returns all rows, with not null value - it returns no row.

If you wont to do filter query via some name you have to use dynamic sql:

create or replace function ssss(_name varchar)
returns setof test as $$
declare _r record;
begin
  for _r in execute 'select * from test where ' || quote_ident(_name)
|| ' is null'
  loop
    return next r;
  end loop;
  return;
end;
$$ language plpgsql;

regards
Pavel Stehule



>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

pgsql-bugs by date:

Previous
From: Radoslaw Zielinski
Date:
Subject: Re: 8.4.0 data loss / HOT-related bug
Next
From: Tom Lane
Date:
Subject: Re: BUG #5004: pg_freespacemap make a SegFault