Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DROP FUNCTION IF EXISTS insert_node(CHARACTER VARYING,INTEGER,INTEGER);
- CREATE OR REPLACE FUNCTION insert_node(TABLE_NAME VARCHAR, id INT, pid INT) RETURNS void LANGUAGE PLPGSQL AS $$
- BEGIN
- EXECUTE format(
- 'INSERT INTO %I_relation(ancestor, descendant, distance)
- SELECT ancestor, $1 as descendant, distance + 1
- FROM %I_relation WHERE descendant = $2
- UNION ALL SELECT $3, $4, 0',
- TABLE_NAME, TABLE_NAME
- ) USING id, pid, id, id;
- END;
- $$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement