Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8757851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:24:06+00:00 2026-06-13T14:24:06+00:00

All, I am trying to bulk insert some data in a table using the

  • 0

All,

I am trying to bulk insert some data in a table using the COPY TO command and I can’t seem to get around the unique key error. Here’s my workflow.

Create a dump of the data I want to move to another server

COPY (
  SELECT *
  FROM mytable
  WHERE created_at >= '2012-10-01')
    TO 'D:\tmp\file.txt'

Create a new “temp” table in the target DB then COPY the data like so.

COPY temp FROM 'D:\tmp\file.txt'

I now want to move the data from the “temp” table in to the master table in the target DBlike so.

 INSERT INTO master SELECT * FROM temp 
                WHERE id NOT IN (SELECT id FROM master)

This runs fine but nothing gets inserted and no fields are updated. Does anyone have a clue what might be going on here? The schemas for temp and master are identical. Any help on this matter would be great! I am using Postgresql 9.2

Adam

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:24:08+00:00Added an answer on June 13, 2026 at 2:24 pm

    This can happen if there’s a null value in the IN list.

    In SQL, the presence of a null when making comparisons is always false (you need the special IN NULL test to get a match). This has the unfortunate consequence of making the entire list not match if there’s any null values returned from SELECT id FROM master.

    See if there are any rows returned from this query:

    SELECT id
    FROM master
    WHERE id is null;
    

    If not, then this isn’t your problem.

    If there are values, then the fix is to exclude null ids from the list:

    INSERT INTO master
    SELECT *
    FROM temp 
    WHERE id NOT IN (SELECT id FROM master where id is not null)
    

    The other thing to consider is that there are simply no values not already inserted!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying all day to get some data properly formatted in a
I'm trying to insert some data from a XML document into a variable table.
Hi all I am trying to get contact information from the contact database using
I'm trying to bulk load around 12m records into a InnoDB table in a
I am currently trying to use a bulk insert from a temporary table with
I'm trying to create a table in a database using SQL. The data is
I have been trying all afternoon to get the jQuery Sifr Plugin ( http://jquery.thewikies.com/sifr/
I have been struggling all afternoon trying to get a simple mailto: tag to
I'm trying to write Windows app to get data from From Fox Pro DB,
I am trying to bulk disable all the submit buttons present in my form.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.