Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
PostgresSQL Insert error: duplicate key value violates unique constraint "todo_task_key"

I am trying to insert some values to my table called todo, i've Postico gui open, which I can see the table visually on my screen better. The insert query was successfully, base off the console.log, that states "Data insert successful", which it went off one time and ever since running again it's just been doing the "todo_task_key" error.

const express = require("express");

const app = express();
app.set("view engine", "ejs");

const { Client } = require("pg")
const client = new Client();
client.connect();

const dotenv = require("dotenv")
dotenv.config()

const credentials = {
    user: process.env.PGUSER,
    host: process.env.PGHOST,
    database: process.env.PGDATABASE,
    password: process.env.PGPASSWORD,
    port: process.env.PGPORT
}


async function registerPerson(person) {
    const query = `
        INSERT INTO todo (task, status)
        VALUES ('Clean Kitchen', 0)
        RETURNING id
         `;
    // const values = [person.task, person.status];
    // // return client.query(text, values);
    client.query(query, (err, res) => {
        if (err) {
            console.error(err);
            return;
        }
        console.log('Data insert successful');
        client.end();
    });
}


registerPerson();

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A duplicate key error means that you have tried to insert a row with the same key value as some other row already indexed by the todo_task_key index.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!