Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9dfR-00012H-UQ for pgsql-general@arkaria.postgresql.org; Fri, 20 Apr 2018 21:34:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9dfP-0000OG-LN for pgsql-general@arkaria.postgresql.org; Fri, 20 Apr 2018 21:34:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9dfN-0000O5-SL for pgsql-general@lists.postgresql.org; Fri, 20 Apr 2018 21:34:03 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9dfJ-0007Ks-OT for pgsql-general@postgresql.org; Fri, 20 Apr 2018 21:34:00 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 7EE5D21B9A; Fri, 20 Apr 2018 17:33:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 20 Apr 2018 17:33:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=/+XE4gVrvLCkgRTsnwMtw/nf5GAkm M0uCwWeMy/UzFk=; b=GyhEJDoNheGwQlqCD/prHGhpFC5MufzMc8tTWEFd0CQDe UPOAZVrYjlcyfJCKn1EpwW/+4Bxr+v6IU7Aisstp0eDoeLyG76ArSumhUnNiVwqC oKn+il6CpYUtqAagpeMmeCwamcKLf0XCNhiMHOTeRnGv0rdHUqPgJDPsitWmYRYk 6G6LSpAR1+j/BQyQDsIaqBO1C5eH+Y11bqJ3roBTmfW+uwttQurX0MWqtAR/nFKu qPL6MvnkQ/juEiYGw4lkKNZkiZf71vNre423hVc27DruuPeH3b7uqHgcksHWRXQO 3wZAYWhpW5SwhgoR4OWUdb5hxlZKVC28w3Ljb/FKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=/+XE4g VrvLCkgRTsnwMtw/nf5GAkmM0uCwWeMy/UzFk=; b=eNSsXvHIAoVD5/79CwDdzs C/Fti7ZU87438zYEo4BiSMD85jZweTZEoDnp4pVvpJpeSuf5XAVlm82AZx11fTeo J2pfYKSAVZuWuTCPEi72CYVT2zLSDXTeXlLk6FUUNFS7QIOLcl+kNUqDyEURlbAH Z63Dku53IachTtN+DwQ+I8D1Di6MrgEEdf9oKyIGaaLTs8pifugUSB9CPk8TS3Vb 6uQQgYjVYq8JSMm+sQSucsSnmo5V2IQIh+UZPN7+u/c+FINueg8NHPHbpGYw7HMY RENbon6QD/ehtZw3eiU8A3E+eXw2GhLuAxJ2xEY/4R9cSHtUN/l4IVJbb8EBBsUg == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id EC21E10253; Fri, 20 Apr 2018 17:33:55 -0400 (EDT) Subject: Re: Problem with trigger makes Detail record be invalid To: PegoraroF10 , pgsql-general@postgresql.org References: <1524160534707-0.post@n3.nabble.com> <7cb5806e-7371-5c19-1c7b-b8ac556bdfb5@aklaver.com> <24449.1524164237@sss.pgh.pa.us> <2795.1524165702@sss.pgh.pa.us> <1524188994110-0.post@n3.nabble.com> <4f528d7d-90d0-55d1-f017-b72d730080db@aklaver.com> <6b96b2ad-4c89-cf11-8dcd-78ec7300d36c@aklaver.com> <1524256246645-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: <702915d2-9558-7b82-04fe-27c400f63dbf@aklaver.com> Date: Fri, 20 Apr 2018 14:33:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1524256246645-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/20/2018 01:30 PM, PegoraroF10 wrote: > Well, talking about responsabilities, I think one of responsabilities of a > mature database is that it can only accept data it was configured for. If > you try to store a timestamp in a integer field or a huge numeric value in a Actually there have been examples on this list where folks have stored a timestamp as seconds from an epoch in an integer field. Of course then someone has to know what that field really represents. This is not nit picking on my part so much as an example of end user inventiveness. To that end Postgres has many ways of coming to a solution for a problem. Unfortunately, there are paths to a solution can trip you up. This means there is often no simple answer to a problem. Basically, more choices means more pre-thinking, testing, re-thinking, repeat as needed. > smallint field, Postgres will block you because that operation is not > acceptable. > So, it's not acceptable to break referential integrity, is it ? That is a maybe: https://www.postgresql.org/docs/10/static/sql-altertable.html " DISABLE TRIGGER [ trigger_name | ALL | USER ] ALL Disable or enable all triggers belonging to the table. (This requires superuser privilege if any of the triggers are internally generated constraint triggers such as those that are used to implement foreign key constraints or deferrable uniqueness and exclusion constraints.) ADD table_constraint [ NOT VALID ] This form adds a new constraint to a table using the same syntax as CREATE TABLE, plus the option NOT VALID, which is currently only allowed for foreign key and CHECK constraints. If the constraint is marked NOT VALID, the potentially-lengthy initial check to verify that all rows in the table satisfy the constraint is skipped. The constraint will still be enforced against subsequent inserts or updates (that is, they'll fail unless there is a matching row in the referenced table, in the case of foreign keys; and they'll fail unless the new row matches the specified check constraints). But the database will not assume that the constraint holds for all rows in the table, until it is validated by using the VALIDATE CONSTRAINT option. " https://www.postgresql.org/docs/10/static/sql-createtrigger.html "SQL specifies that BEFORE DELETE triggers on cascaded deletes fire after the cascaded DELETE completes. The PostgreSQL behavior is for BEFORE DELETE to always fire before the delete action, even a cascading one. This is considered more consistent. There is also nonstandard behavior if BEFORE triggers modify rows or prevent updates during an update that is caused by a referential action. This can lead to constraint violations or stored data that does not honor the referential constraint." https://www.postgresql.org/docs/10/static/plpgsql-trigger.html "Row-level triggers fired BEFORE can return null to signal the trigger manager to skip the rest of the operation for this row (i.e., subsequent triggers are not fired, and the INSERT/UPDATE/DELETE does not occur for this row). " A certain amount of this came about because folks are dealing with messy data and want to get it into the database first, do the clean up there and then apply the RI constraints. Other folks have different ways of doing it. It comes done to personal choice. That means though you have to know that dangerous paths exist and how to avoid them. A lot of this is ingrained in the code and in use in the wild, so I would not expect there would be major changes in how things work. Instead as has already been indicated there maybe better documentation on the way detailing all the above. > > > > -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > -- Adrian Klaver adrian.klaver@aklaver.com