Re:
От | Jeff Davis |
---|---|
Тема | Re: |
Дата | |
Msg-id | 1155661643.11726.115.camel@dogma.v10.wvs обсуждение исходный текст |
Ответ на | Re: (Max <xdmaxx@gmail.com>) |
Ответы |
Re:
|
Список | 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
В списке pgsql-general по дате отправления: