Re: Simple function

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: Christine Penner <christine(at)ingenioussoftware(dot)com>
Cc: Postgres-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Simple function
Date: 2009-12-23 17:15:33
Message-ID: 396486430912230915k2ebdb7f9x4dac2b3526e35c22@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 23, 2009 at 9:03 AM, Christine Penner
<christine(at)ingenioussoftware(dot)com> wrote:
> Hi,
>
> I'm trying to create a simple function but having a bit of trouble. This is
> what I want to do.
>
> I want to pass a key as a parameter (BKEY integer)
> the code in the function should be
> count(*) from F_BUILDINGS where B_PRIMARY_SEQ=BKEY
>
> I want to return the count from the select statement.

It works for me:

postgres=# CREATE OR REPLACE FUNCTION countertest(integer) RETURNS
bigint AS $$ SELECT COUNT(*) FROM test WHERE nbr = $1; $$ LANGUAGE
SQL;
CREATE FUNCTION
postgres=# select countertest(24);
countertest
-------------
1
(1 row)

http://www.postgresql.org/docs/8.4/interactive/xfunc-sql.html

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rajan, Pavithra 2009-12-23 17:15:55 How to get a list of tables that have a particular column value?
Previous Message Adrian Klaver 2009-12-23 17:14:38 Re: Simple function