Saturday, January 20, 2007

plpgsql function to move from usercomments to comments

-- Function: usercomments_to_comments()

-- DROP FUNCTION usercomments_to_comments();

CREATE OR REPLACE FUNCTION usercomments_to_comments()
RETURNS int4 AS
$BODY$
declare
c usercomments%rowtype;
_count integer;
begin
_count := 0;
for c in
select * from usercomments
loop
insert into comments (comment, postid, created, ip, email, user_id, username, type_id) values (c.comment, c.user_id, c.created, c.ip, c.friend_email,c.friend_id,c.friend_name,2);
_count := _count + 1;
end loop;


return _count;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION usercomments_to_comments() OWNER TO postgres;

No comments: