plpgsql question
mwaples@optusnet.com.au
From: mwaples@optusnet.com.au
To:
Cc: pgsql-novice@postgresql.org
Date: 2000-12-10T14:48:35Z
Lists: pgsql-hackers
Can I use table as a variable in a function ? eg the following does what I need, (I have a trigger using it after an insert on another table) but there will be a number of threads_whatever tables and I thought it might be neater just using one function. If it can be done - can I use a table as a variable in a sql function ? Also bsides the docs and the pdf book - is there any other info around on plpgsql ? /* function to update threads table */ CREATE FUNCTION add_post_php() RETURNS OPAQUE AS ' BEGIN IF (SELECT count(*) FROM threads_php WHERE thread_id = NEW.thread_id) < 1 THEN INSERT INTO threads_php (thread_id,date,user_name,last_post,last_user_name,posts,thread) VALUES (NEW.thread_id,NEW.date,NEW.user_name,NEW.date,NEW.user_name,count_posts_thread_php(NEW.thread_id),NEW.thread); ELSE UPDATE threads_php set last_post = New.date, last_user_name = NEW.user_name, posts = count_posts_thread_php(NEW.thread_id) WHERE thread_id = NEW.thread_id; END IF; RETURN NEW; END; ' LANGUAGE 'plpgsql';