Re: AFTER INSERT trigger INSERT into another table-B are ignoring Table-B constraints

From: wolters(dot)k(at)web(dot)de
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: AFTER INSERT trigger INSERT into another table-B are ignoring Table-B constraints
Date: 2024-05-22 22:38:41
Message-ID: trinity-df545866-e250-4a4d-a113-c9f6e3cd3fca-1716417521384@msvc-mesg-web003
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

<html style="background-color:transparent"><head><meta charset="utf-8" name="viewport" content="width=device-width">


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body contenteditable="false" style="margin-left:10px;">
<div id="8787634986986720895ty" contenteditable="false">
<div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">Hi,</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">getting trigger and functions over several tables&nbsp;smooth at work is sometimes difficult, as there are many points for unecpexted stuff. Maybe some of the following hints are helpful?&nbsp;</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">maybe you can check the unique constraint&nbsp;at first with a&nbsp;simple insert of several rows in your table&nbsp;<span style="font-family: Aptos, serif; font-size: 10.666667px;">bx.test_part_details_all_mcm_</span><b style="font-family: Aptos, serif; font-size: 10.666667px;">mid</b>&nbsp;if everything works as expected.&nbsp;</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">Does your constraint&nbsp;<span style="font-family: Aptos, serif; font-size: 10.666667px;">cons_unique_for_concatenated_view</span>&nbsp;&nbsp;include all columns of the table (the comparision works for the whole table&nbsp;or a few columns)?&nbsp;</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">Are there any further update- /insert-, etc. trigger or functions that operate at the some table (&nbsp;<span style="font-family: Aptos, serif; font-size: 10.666667px;">bx.test_part_details_all_mcm_</span><b style="font-family: Aptos, serif; font-size: 10.666667px;">mid</b>) - in worst case at the same time?&nbsp;</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">Are&nbsp;the duplicated rows containg&nbsp;NULL- values in a column?&nbsp;</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">„<span style="caret-color: rgb(243, 245, 249); color: rgb(243, 245, 249); font-family: &quot;Open Sans&quot;, sans-serif; font-size: 14.4px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-text-size-adjust: 100%; background-color: rgb(33, 33, 33);">&nbsp;By default, two null values are not considered equal in this comparison. That means even in the presence of a unique constraint it is possible to store duplicate rows that contain a null value in at least one of the constrained columns“ (</span><a href="https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-UNIQUE-CONSTRAINTS">https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-UNIQUE-CONSTRAINTS</a>)&nbsp;</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">Then you could solve the Problem by adding&nbsp;<span style="caret-color: rgb(243, 245, 249); color: rgb(243, 245, 249); font-family: monospace, monospace; font-size: 14.4px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-text-size-adjust: 100%; background-color: rgb(74, 74, 74);">NULLS NOT DISTINCT</span>&nbsp;(compare&nbsp;further down same link)</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">Good luck!&nbsp;</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">kind&nbsp;regards,</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;">Katrin</div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><span style="caret-color: rgb(243, 245, 249); color: rgb(243, 245, 249); font-family: monospace, monospace; font-size: 14.4px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-text-size-adjust: 100%; background-color: rgb(74, 74, 74);"></span></div><div id="338317EditableDivID--xx--yy--42" style="font-family: Verdana;font-size:17px; color:black;"><br>Am 22.05.24 um 23:15 schrieb M Sarwar
<br><br>
</div>
<div style="border-left:2px solid gray;padding-left:10px;width:100%%">
<div style="font-family: Verdana;font-size:17px; color:black;">
Von: "M Sarwar" &lt;sarwarmd02(at)outlook(dot)com&gt;<br>Datum: 22. Mai 2024<br>An: "pgsql-admin(at)lists(dot)postgresql(dot)org" &lt;pgsql-admin(at)lists(dot)postgresql(dot)org&gt;<br>Cc: <br>Betreff: AFTER INSERT trigger INSERT into another table-B are ignoring Table-B constraints
</div>

<div class="elementToProof" style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, serif; font-size: 8pt; color: rgb(0, 0, 0);">
Hello All,</div>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">This is a trigger related question.</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">&nbsp;</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">Table, test_part_details_all_mcm_init &nbsp;has a trigger, tr_test_part_details_all_mcm_init.</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">&nbsp;</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">CREATE TRIGGER tr_test_part_details_all_mcm_init</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">&nbsp;&nbsp;&nbsp; AFTER INSERT</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">&nbsp;&nbsp;&nbsp; ON bx.test_part_details_all_mcm_<b>init</b></span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">&nbsp;&nbsp;&nbsp; FOR EACH ROW</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">&nbsp;&nbsp;&nbsp; EXECUTE FUNCTION bx.tr_fn_test_part_details_all_mcm_init();</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;">&nbsp;</p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">Function, bx.tr_fn_test_part_details_all_mcm_init() INSERTs a row into another table, bx.test_part_details_all_mcm_<b>mid</b></span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;">&nbsp;</p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">Table, bx.test_part_details_all_mcm_<b>mid
</b>has a constraint,</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">CONSTRAINT cons_unique_for_concatenated_view UNIQUE (start_time_numeric, stop_time_numeric, test_action, part_type, fixture_id, run_id, auxid1_build_id, auxid2_asic_id,
serial_number, part_pf)</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">&nbsp;</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">When I INSERT a data into the table Table, test_part_details_all_mcm_init &nbsp;, trigger is not checking CONSTRAINT cons_unique_for_concatenated_view while INSERTing
the data in bx.test_part_details_all_mcm_<b>mid. </b>I am expecting that anything violating the constraint cons_unique_for_concatenated_view will throw an error. Instead of that it is allowing to INSERT the data.</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;">&nbsp;</p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;"><span style="font-size: 8pt;">What is that I am missing here?</span></p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;">Thanks,</p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;">Sarwar</p>
<p style="margin: 0in; font-family: Aptos, serif; font-size: 11pt;">&nbsp;</p>

</div>
</div>

</body></html>

Attachment Content-Type Size
unknown_filename text/html 9.2 KB

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message M Sarwar 2024-05-23 00:29:16 Re: AFTER INSERT trigger INSERT into another table-B are ignoring Table-B constraints
Previous Message M Sarwar 2024-05-22 21:14:46 AFTER INSERT trigger INSERT into another table-B are ignoring Table-B constraints