Re: Help with SQL Function - Mailing list pgsql-general

From Tom Lane
Subject Re: Help with SQL Function
Date
Msg-id 18661.978817235@sss.pgh.pa.us
Whole thread Raw
In response to Help with SQL Function  (Jeff Eckermann <jeff@akira.eckermann.com>)
List pgsql-general
Jeff Eckermann <jeff@akira.eckermann.com> writes:
> extracts=# create function testfunc(text) returns int4 as '
> extracts'# select count (*) from dedcolo where equip_type = ''$1''    --- That's doubled single quotes
> extracts'# ' language 'sql';
> CREATE

That's looking for rows where equip_type = '$1'  ... ie, the literal
string $1.  What you probably wanted is

create function testfunc(text) returns int4 as '
select count (*) from dedcolo where equip_type = $1
' language 'sql';

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Postgres 7.03 table describe problem
Next
From: Alex Pilosov
Date:
Subject: Re: Help with SQL Function