I have a query in oracle that basically updates activate flag to yes if exists and add's new entry with active flag yes if not exists. This query does not play well with my postgres transition work I am doing. I tried looking but could not find a query that would work for both cases.
Does someone have an example of this that would work on both postgres and oracle ?
Some Context:
oracle sql: update if exists else insert
here is my existing Oracle only query in java
private static final String SQL_UPDATE_OR_INSERT_USER ="
DECLARE
u_name users.name%type := (:name);
u_key users.ukey%type := (:ukey);
BEGIN
UPDATE users SET ACTIVE=1 WHERE ukey IN (u_key) and lower(name) = lower(u_name);
IF ( sql%rowcount = 0 ) THEN
INSERT INTO users(user_id, ukey, name, ACTIVE) VALUES
(hibernate_sequence.nextval, u_key, u_name, 1);
END IF;
END;";
This does not work with postgres and postgres one looks very different from this one.