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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:14:39+00:00 2026-06-13T12:14:39+00:00

I have two tables with same schema , and primary key as noc for

  • 0

I have two tables with same schema , and primary key as noc for both,

whenever insert is made in table 1 , its noc must be checked in TABLE2, if exist then complete row must be compared and if there is any difference an exception must be raised .
and if noc does not exist in TABLE2 then simple insertion must follow

this is my trigger function

          CREATE OR REPLACE FUNCTION ac_val()
           RETURNS trigger AS
           $BODY$

            BEGIN

           IF NEW.acop IS NULL THEN

                           INSERT INTO exception_detail( noc,exception) 
    VALUES (new.noc,'number cannot be empty');


    END IF;


    RETURN NEW;
           END;
   $BODY$
       LANGUAGE plpgsql VOLATILE

this is my trigger

             CREATE TRIGGER acut_val
           AFTER INSERT OR UPDATE
             ON acut
          FOR EACH ROW
         EXECUTE PROCEDURE ac_val();

this is perfectly ok for one table,
but now according to requirement on every insert it must check if noc exists in other table, TABLE2 ,
if exist then comparison must be made, otherwise insertion

I think I can not perform that check on each insert because data to be inserted in acuit is to be copied from csv, and that will require copy from csv, and if i do copy it gives error u must be super user, but if i copy from console its ok.
So can i do something like after data is copied in acuit making a check row by row

             SELECT q1.* FROM acut q1
             INNER JOIN TABLE2 q2 ON (q1.noc = q2.noc);

it will give records of acut which exists in TABLE2

and then

              foreach row of above output{

      if (q1.name != q2.name)
      Do something ;

    if (q2.address < q1.address)
     Do something ;

     } 
  • 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-13T12:14:40+00:00Added an answer on June 13, 2026 at 12:14 pm

    The simplest solution I can think of is to use a trigger on table1.

    Don’t use the trigger to check uniqueness because you can’t see uncommitted data from other users.

    Instead use the trigger to INSERT the data into table2 — which should have a unique constraint on all the columns you want to check.

    If you insert data into table1 that already exists in table2, the unique constraint on table2 will be violated, raising an exception which you can catch in your front end.

    The big advantage to this approach is that it will also work correctly for multi-user situations where your transaction can’t see uncommitted data in table2 but the DBMS will still prevent the insert from continuing (the transaction will hang until the other transaction either commits or rollbacks).

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

Sidebar

Related Questions

I have two tables both have same schema, one will have previous day records
I have two tables with exactly the same fields. Table A contains 7160 records
I have two classes generated by LINQ2SQL both from the same table so they
I have two tables with the exact same schema in SQL Server 2008 Standard
I'm working on mysql and have two tables with the same schema: preTrial |id|accusedId|articleid|
I have two tables, they are called MASTER and NEWDATA. The schema on both
I have two tables auth_user and temp These are their schema: CREATE TABLE auth_user
I have two tables (with the same schema) Table1 id title D0 D1 D2
i have two database A,B with same number of tables and schema in sql
I have two tables with exactly the same schema. I would like to have

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.