By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Writing a user defined function

P: 3
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();
Jul 18 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 700
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?
Jul 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.