Jump to content

Recommended Posts

I have the following SQL I am trying to run from pgadmin III

INSERT 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. Thanks

Its not as easy a regular old IF NOT EXISTS...
Link to comment
https://forums.phpfreaks.com/topic/21205-insert-problem/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/21205-insert-problem/#findComment-94339
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.