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