Re: Help with SQL Function

From: Alex Pilosov <alex(at)pilosoft(dot)com>
To: Jeff Eckermann <jeckermann(at)verio(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Help with SQL Function
Date: 2001-01-06 21:40:15
Message-ID: Pine.BSO.4.10.10101061639420.4224-100000@spider.pilosoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Simpler than you think:
select count (*) from dedcolo where equip_type = $1

(note the space between = and $)

On Wed, 3 Jan 2001, Jeff Eckermann wrote:

> I'm falling at the first hurdle. Can someone tell me how to pass an
> attribute value into a function, as I'm trying to do below? I've studied
> the docs every which way, but can't seem to find the cause of my problem.
> Thanks in advance for ignorance relief.
>
> 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
> extracts=# select testfunc('Dialup');
> testfunc
> ----------
> 0
> (1 row)
> extracts=# create function testfunc() returns int4 as '
> extracts'# select count (*) from dedcolo where equip_type = ''Dialup'' ---
> Doubled single quotes, again
> extracts'# ' language 'sql';
> CREATE
> extracts=# select testfunc();
> testfunc
> ----------
> 3453
> (1 row)
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-01-06 21:40:35 Re: Help with SQL Function
Previous Message Robert B. Easter 2001-01-06 20:45:17 Re: Are triggers part of the transaction block that triggered the trigger?