{"action":"closed","issue":{"url":"https://api.github.com/repos/sequelize/cli/issues/306","repository_url":"https://api.github.com/repos/sequelize/cli","labels_url":"https://api.github.com/repos/sequelize/cli/issues/306/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/cli/issues/306/comments","events_url":"https://api.github.com/repos/sequelize/cli/issues/306/events","html_url":"https://github.com/sequelize/cli/issues/306","id":156954975,"number":306,"title":"Support postgresql 9.5 ON CONFLICT when upsert.","user":{"login":"ncwhale","id":1552933,"avatar_url":"https://avatars.githubusercontent.com/u/1552933?v=3","gravatar_id":"","url":"https://api.github.com/users/ncwhale","html_url":"https://github.com/ncwhale","followers_url":"https://api.github.com/users/ncwhale/followers","following_url":"https://api.github.com/users/ncwhale/following{/other_user}","gists_url":"https://api.github.com/users/ncwhale/gists{/gist_id}","starred_url":"https://api.github.com/users/ncwhale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncwhale/subscriptions","organizations_url":"https://api.github.com/users/ncwhale/orgs","repos_url":"https://api.github.com/users/ncwhale/repos","events_url":"https://api.github.com/users/ncwhale/events{/privacy}","received_events_url":"https://api.github.com/users/ncwhale/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-26T10:41:12Z","updated_at":"2016-05-26T10:42:15Z","closed_at":"2016-05-26T10:42:14Z","body":"When do a object upsert, Such as  `Models.Lexicon.upsert({content: 'Key Word', group: ['Group'], deleted_at: null})`\r\n\r\nRight now the SQL looks like this:\r\n\r\n```SQL\r\nCREATE OR REPLACE FUNCTION pg_temp.sequelize_upsert() RETURNS integer AS $func$ \r\nBEGIN \r\nINSERT INTO \"Lexicons\" (\"id\",\"content\",\"group\",\"use_count\",\"deleted_at\",\"created_at\",\"updated_at\") VALUES ('3b730685-6e3c-4d30-94ce-97b41eea3029','Key Word',ARRAY['Group']::VARCHAR(255)[],0,NULL,'2016-05-26 10:03:58.747 +00:00','2016-05-26 10:03:58.747 +00:00'); RETURN 1; \r\nEXCEPTION WHEN unique_violation THEN \r\nUPDATE \"Lexicons\" SET \"content\"='Key Word',\"group\"=ARRAY['Group']::VARCHAR(255)[],\"deleted_at\"=NULL,\"updated_at\"='2016-05-26 10:03:58.747 +00:00' WHERE (\"id\" = '3b730685-6e3c-4d30-94ce-97b41eea3029' OR \"content\" = 'Marvel'); RETURN 2; \r\nEND; $func$ LANGUAGE plpgsql; \r\nSELECT * FROM pg_temp.sequelize_upsert();\r\n```\r\nbut when PostgreSQL 9.5 support ON CONFLICT keyword when INSERT, it can be simple done like this:\r\n\r\n```SQL\r\nINSERT INTO \"Lexicons\" (\"id\",\"content\",\"group\",\"use_count\",\"deleted_at\",\"created_at\",\"updated_at\") \r\nVALUES ('3b730685-6e3c-4d30-94ce-97b41eea3029','Key Word',ARRAY['Group']::VARCHAR(255)[],0,NULL,'2016-05-26 10:03:58.747 +00:00','2016-05-26 10:03:58.747 +00:00') \r\nON CONFLICT (\"content\") DO UPDATE SET \"deleted_at\" = null, \"group\" = EXCLUDED.\"group\"\r\nRETURN *; \r\n```"}}
{"actor":{"display_login":"mickhansen"}}