Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION add_entry(_user_name text)
- RETURNS bigint AS
- $BODY$
- DECLARE
- user_name text := '#' || $1;
- user_id bigint;
- BEGIN
- -- get the ID from the sequence
- SELECT nextval('my_sequence') INTO user_id;
- -- insert the name (and some other data not shown here) 5x
- FOR item IN 1..5
- LOOP
- INSERT INTO mytable
- (id,index,username)
- VALUES (user_id,item,user_name);
- END LOOP;
- -- send notify that an insertion took place
- notify my_notify;
- RETURN id;
- END;
- $BODY$
- LANGUAGE plpgsql VOLATILE
- COST 100;
- select * from mytable where id = (select add_entry('MyTestUser'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement