CREATE OR REPLACE FUNCTION myschema.user_data_ups(uuid, timestamp with time zone, text, text, text, text, date, smallint, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, double precision, boolean, boolean, boolean, text) RETURNS void LANGUAGE plpgsql SECURITY DEFINER AS $function$ BEGIN WITH upsert AS (UPDATE user_data SET last_update = $2::timestamp with time zone, email_address = $3::text, password_salt = $4::text, password_hash = $5::text, display_name = $6::text, dob = $7::date, gender = $8::smallint, city = $10::text, state = $11::text, street_address = $9::text, zipcode = $12::text, profile_photo = $13::text, ptp = $14::text, ftp = $15::text, grv = $16::integer, pp = $17::boolean, gr = $18::boolean, nes = $19::boolean, np = $20::boolean, nnf = $21::boolean, nbc = $22::boolean, nnr = $23::boolean, nsr = $24::boolean, nws = $25::boolean, signup_date = coalesce(to_timestamp($26::double precision)::timestamp at time zone 'GMT',transaction_timestamp()), uhc = $27::boolean, email_verified = coalesce($28::boolean, false::boolean), active = $29::boolean, code = $30::text WHERE user_guid = $1::uuid RETURNING user_guid) INSERT INTO user_data (user_guid, last_update, email_address, password_salt, password_hash, display_name, dob, gender, street_address, city, state, zipcode, profile_photo, ptp, ftp, grv, pp, gr, nes, np, nnf, nbc, nnr, nsr, nws, signup_date, uhc, email_verified, active, code) SELECT $1::uuid, $2::timestamp with time zone, $3::text, $4::text, $5::text, $6::text, $7::date, $8::smallint, $9::text, $10::text, $11::text, $12::text, $13::text, $14::text, $15::text, $16::integer, $17::boolean, $18::boolean, $19::boolean, $20::boolean, $21::boolean, $22::boolean, $23::boolean, $24::boolean, $25::boolean, coalesce(to_timestamp($26::double precision)::timestamp at time zone 'GMT',transaction_timestamp()), $27::boolean, coalesce($28::boolean, false::boolean), $29::boolean, $30::text WHERE NOT EXISTS (SELECT true FROM upsert); -- EXCEPTION -- WHEN unique_violation THEN -- RAISE LOG 'UNIQUE KEY VIOLATION FOR user_guid %', $1; -- WHEN foreign_key_violation THEN -- RAISE LOG 'FOREIGN KEY VIOLATION FOR user_guid %', $1; -- WHEN not_null_violation THEN -- RAISE LOG 'NOT NULL VIOLATION FOR user_guid %', $1; -- WHEN check_violation THEN -- RAISE LOG 'CHECK VIOLATION FOR user_guid %', $1; END; $function$