Here's a simple example to write a simple parameterized function in PostgreSQL.
CREATE OR REPLACE FUNCTION myFunction(integer, integer) RETURNS integer AS $$
update ref_table set employee_id = $2 where owner_id = $1;
select 1;
$$ LANGUAGE SQL;
Now to call this function, just run:
select myFunction(123,33);
This will update all the records with owner_id = 123.
This is just one little function! You can use this after a cursor to perform certain functionality for all the entries in the cursor or any other place where you think it can be helpful. World is your Oyster.
Please let me know if you have any better ideas or if the above content is incorrect.
Thank you.
Wednesday, July 1, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment