Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE mytable (id SERIAL, name VARCHAR(10) PRIMARY KEY)
- INSERT INTO mytable (name) VALUES ('Jonas') RETURNING id
- CREATE OR REPLACE FUNCTION upsert_tableName(arg1 type, arg2 type) RETURNS VOID AS $$
- DECLARE
- BEGIN
- UPDATE tableName SET col1 = value WHERE colX = arg1 and colY = arg2;
- IF NOT FOUND THEN
- INSERT INTO tableName values (value, arg1, arg2);
- END IF;
- END;
- $$ LANGUAGE 'plpgsql';
- BEGIN
- INSERT INTO db_table (tbl_column) VALUES (v_tbl_column);
- EXCEPTION WHEN unique_violation THEN
- -- Ignore duplicate inserts.
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement