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 3937366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:03:37+00:00 2026-05-20T00:03:37+00:00

I have a SELECT query like this: SELECT id_default_value, id_type FROM ntg_attribute, ntg_module_attribute WHERE

  • 0

I have a SELECT query like this:

SELECT id_default_value, id_type FROM ntg_attribute, ntg_module_attribute 
WHERE ntg_attribute.id_module_attribute = ntg_module_attribute.id;

This returns 2 columns, id_default_value and id_type. I’d like to then use this data as the basis of an INSERT query into another table, ntg_default_value, using id_default_value as the key, and id_type as the inserted value.

The following is nearly there, but not quite:

INSERT INTO ntg_default_value (id, id_type) 
SELECT id_default_value, id_type FROM ntg_attribute, ntg_module_attribute 
WHERE ntg_attribute.id_module_attribute = ntg_module_attribute.id;

This gives me:

ERROR:  duplicate key value violates unique constraint "pk_ntg_default_value"

Is what I’m trying to do actually possible? If so, how do I construct the query?

(PostgreSQL 8.4.6)

  • 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-05-20T00:03:38+00:00Added an answer on May 20, 2026 at 12:03 am

    The name of the constraint ‘pk_ntg_default_value’ probably means you are violating the primary key constraint of the table ntg_default_value.

    Depending on your requirements you can either take away the primary key constraint. Or you can expand it to include both id & id_type if it doesn’t already and add a GROUP BY to your query, if necessary, to prevent duplicate id_devault_value & id_type pairs. Your query becomes then :

    INSERT INTO ntg_default_value (id, id_type)
    SELECT id_default_value, id_type 
    FROM ntg_attribute, ntg_module_attribute 
    WHERE ntg_attribute.id_module_attribute = 
          ntg_module_attribute.id 
    GROUP BY id_default_value, id_type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask something about query using mysql I have this table
I have several hosts from which i want to do the same query. So
I have a GridView using LinqDataSource to populate data from table Tickets . The
I have the talbe like that: CREATE TABLE UserTrans ( `id` int(10) UNSIGNED NOT
i have a commenting system where i am storing the News ID in the
I have a database where I store keywords grouped into projects and data related
I have stolen/found/used/written and edited the following widget of jQuery for a auto-completing dropdown.
that´s my first question in stackoverflow . I have two MYSQL tables: categories and
I have a table with ~30 million rows ( and growing! ) and currently
I have been working on developing some RESTful Services in Django to be used

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.