Re:

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Max <xdmaxx(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re:
Date: 2006-08-15 17:07:23
Message-ID: 1155661643.11726.115.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2006-08-15 at 18:46 +0200, Max wrote:
> Thx.
> But I know how to write procedure and function, but my problem is to
> know how to access the current row fields during a SELECT inside a
> function:
>
> So, in a function, can I write :
>
> /* ... */ permission (/* ... */)
> /* ... */
> IF (ROW.perm_field1 = 1)
> statement
> IF (some_operation(ROW.perm_field2))
> statement
> /* ... */
> RETURN TRUE or FALSE;
> /* ... */
>

What you want to do is pass each "perm_field" as a parameter.

So, you'd do something like:

CREATE OR REPLACE FUNCTION permission(perm_field1 int, perm_field2 int,
perm_field3 int) RETURNS BOOLEAN LANGUAGE plpgsql STABLE AS $$
BEGIN
IF perm_field1 = 2 THEN
RETURN FALSE;
ELSIF perm_field2 = perm_field3 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END;
$$;

And then:

SELECT * FROM tablename WHERE permission
(perm_field1,perm_field2,perm_field3);

Hope this helps,
Jeff Davis

In response to

  • Re: at 2006-08-15 16:46:18 from Max

Responses

  • Re: at 2006-08-15 19:54:50 from Tom Lane

Browse pgsql-general by date

  From Date Subject
Next Message Curtis Scheer 2006-08-15 17:22:06 plpgsql dynamic queries and optional arguments
Previous Message Ludwig Isaac Lim 2006-08-15 17:03:22 Re: Unable to Start PostgreSQL 8.1.4 on Windows XP