hc Posted September 18, 2006 Share Posted September 18, 2006 I have the following SQL I am trying to run from pgadmin IIIINSERT INTO master.employment(employer_id, employee_id, status_id,imported_by) SELECT (SELECT id FROM businesses.employers WHERE sport_id=1 AND employer=imports.menssoccer.client) as employer_id ,(SELECT id FROM users.employees WHERE tax_id=imports.menssoccer.ssn AND SSN Is Not Null) as employee_id ,1 ,'test' FROM imports.menssoccer WHERE SSN Is Not Null The problem is that sometimes it violate a Unique Constraint on the item. Is there a way I can just insert the rows that dont't exist? Or can I ignore the errors somehow and just go to the next row. ThanksIts not as easy a regular old IF NOT EXISTS... Quote Link to comment https://forums.phpfreaks.com/topic/21205-insert-problem/ Share on other sites More sharing options...
btherl Posted September 19, 2006 Share Posted September 19, 2006 Which unique constraint is being violated? Can you paste the error message?If you're getting "duplicate" rows from a query, you can use 'select distinct on ( ... )' to make them unique according to certain conditions. The particular row you get will be random unless you order your results.By "duplicate" I mean that the rows are not identical, but they still violate some kind of uniqueness constraint that you want to enforce. Quote Link to comment https://forums.phpfreaks.com/topic/21205-insert-problem/#findComment-94339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.