From: | mwaples(at)optusnet(dot)com(dot)au |
---|---|
To: | |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | plpgsql question |
Date: | 2000-12-10 14:48:35 |
Message-ID: | 3A3397C3.3BD05F12@optusnet.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-novice |
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';
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2000-12-10 17:12:50 | Re: [COMMITTERS] pgsql/src/backend/commands (command.c vacuum.c) |
Previous Message | Hiroshi Inoue | 2000-12-10 13:48:12 | RE: [COMMITTERS] pgsql/src/backend/commands (command.c vacuum.c) |
From | Date | Subject | |
---|---|---|---|
Next Message | The Hermit Hacker | 2000-12-10 17:15:34 | Re: Re: [BUGS] 7.1beta1 JDBC Nested cursor problem |
Previous Message | Robert B. Easter | 2000-12-10 14:22:16 | Re: Function overloading |