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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:41:59+00:00 2026-05-29T14:41:59+00:00

Table defintion is create table users ( serial_no integer PRIMARY KEY DEFAULT nextval(‘serial’), uid

  • 0

Table defintion is

create table users (
serial_no integer PRIMARY KEY DEFAULT nextval('serial'),
uid bigint NOT NULL,
username varchar(32),
name text,
CONSTRAINT production UNIQUE(uid)
);

I used this query

INSERT INTO users (uid) values(123) ;

It says duplicate key value violates unique constraint. So I googled it and found this link

So I tried

INSERT INTO users (uid) values(123) 
where 1 in (select 1 from users where uid = 123) ;

It says yntax error at or near “WHERE”.

How to use a statement of insert into using the where clause so that when I run the same query using php it does not return an error

column uid is unique

  • 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-29T14:42:00+00:00Added an answer on May 29, 2026 at 2:42 pm

    The INSERT statement doesn’t support a WHERE clause. Run this.

    create table test (
      n integer primary key
    );
    
    insert into test values (1);
    insert into test values (2) where true;
    

    That will give you a syntax error because of the WHERE clause.

    SELECT statements can have a WHERE clause, though. This will insert 2 into the test table one time. Run it as many times as you want; it won’t raise an error. (But it will insert only one row at the most.)

    insert into test (n) 
    select 2 where 2 not in (select n from test where n = 2);
    

    So your query, assuming you’re trying to avoid raising an error on a duplicate key, should be something like this.

    INSERT INTO users (uid) 
    SELECT 123 WHERE 123 not in (SELECT uid FROM users WHERE uid = 123) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table definition is: CREATE TABLE Product (ProID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
In this MySQL table definition: CREATE TABLE groups ( ug_main_grp_id smallint NOT NULL default
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
How to set a composite primary key for a All in One approach (grid
Here is a table in MySQL 5.3.X+ db: CREATE TABLE members` ( `id` int(11)
Database is MySQL with MyISAM engine. Table definition: CREATE TABLE IF NOT EXISTS matches
'Create field in table Public Sub createField(ByVal tableName As String, ByVal fieldName As String,
I am creating table with sqlalchemy. user = Table('users', Metadata, Column('datecreated', TIMESTAMP, server_default=text('CURRENT_TIMESTAMP')), Column('datemodified',
I am trying to create a sequelize model for a table that has an
I have the following table definition for journal CREATE TABLE public.journal ( id public.inc_journal

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.