Writing a user defined function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Suresh Iyengar
    New Member
    • May 2007
    • 3

    #1

    Writing a user defined function

    Hello,
    I am trying to code a simple udf in postgres. How do I write sql commands into pl/sql ? The foll. code doesnt work.

    CREATE OR REPLACE FUNCTION udf()
    RETURNS integer AS $$
    BEGIN
    for i in 1..2000 loop
    for j in 1...10000 loop
    end loop;
    begin work;
    declare cust scroll cursor for select * from tpcd.customer;
    FETCH FORWARD 5 FROM cust;
    end loop;
    CLOSE cust;
    COMMIT work;
    return 1;
    end;
    $$ LANGUAGE plpgsql;

    select udf();
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    I do not use latest posgres release but postgres 8.1 and earlier do not support nested transactions. Running a function postgres creates a transaction so you can't write 'begin work' and 'commit work' in function body (cos doing it you try to write nested transaction). is that clear?

    Comment

    Working...