Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9D7n-0002U1-MY for pgsql-general@arkaria.postgresql.org; Sat, 14 Sep 2019 18:50:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9D7m-0002LC-9B for pgsql-general@arkaria.postgresql.org; Sat, 14 Sep 2019 18:50:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9D7k-0002Kg-KC for pgsql-general@lists.postgresql.org; Sat, 14 Sep 2019 18:50:22 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9D7c-0002tf-CL for pgsql-general@lists.postgresql.org; Sat, 14 Sep 2019 18:50:20 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id C930420E7B; Sat, 14 Sep 2019 14:50:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 14 Sep 2019 14:50:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=q bBauhnpm1Jtr5k9VB6MzmE39iQXc2LL0ALaS5TBTv4=; b=S1VeUY9GUZ5l3oBdG xtmOLfr994jf8lNWI+jbO3gsJT1NhVE2paV2iZfTASD+uj8kScQwtAtTeVfVpX32 uFD0+37fLU6fdOoQNrg4ihWZml3SUrtbckGzdKds6YAV/htkuqfoR6ulSHJ4adlU bdTtWFx5VtVy0hfrlv1R4bOCFA/3NoFd1cJ0qFnJ8qpq2eaHO4cnlZn1CFWvKDIZ l46dM4nGKa0ntV4WyLTmQ60YDlCGUklQUcdcDZbMtv51OoYKsEkhJmJxE23T9SDk P79CsvjglL0JRtV5AQhmuVuq93nvFCc1Fy/Yuz64vl+8lmF1D18n9vPG0UjseKGW 31fdw== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=qbBauhnpm1Jtr5k9VB6MzmE39iQXc2LL0ALaS5TBT v4=; b=ajb4DF+fqVet23JL9cO9tqgmcc/9ikRxpHurDi6UJd/nkcnKfwx6magwG bt+OVfs6M2e10WvxjvLpdVVEpxkqk3DhcZCSVuGYvirKf8YEe0vM5kHXF7boxam/ fyvIAhxZf7gMoK/J8BLQYeXwAPLptv/fXivVRFWxuFp8/GDJRkuRmczjEHszKbDR mvTeBQO/emGhvuOS8x/enwaMWUbUHquVEXoVqQsvBacWOGSA0XxUj72FCIqYxhw+ 2AFlnSin0FIpqLxiBp8PmQpIg3eJMXPqSz/nEhdn+/9kPCSZVgHcegusw9H9MxRy afF1RdlQHtjvnif7hXqyPsGs3FiTw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrtdelgddufeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppedujeegrddvuddruddvledrud ejheenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghk lhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.3] (174-21-129-175.tukw.qwest.net [174.21.129.175]) by mail.messagingengine.com (Postfix) with ESMTPA id EFE308005B; Sat, 14 Sep 2019 14:50:08 -0400 (EDT) Subject: Re: Can I wrtie a function that has a BEFORE trigger that is not column name dpendent? To: stan , pgsql-general@lists.postgresql.org References: <20190914183350.GA3904@panix.com> From: Adrian Klaver Message-ID: <076f1857-e2d2-0d91-7520-cd2f2b57a2df@aklaver.com> Date: Sat, 14 Sep 2019 11:50:08 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190914183350.GA3904@panix.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 9/14/19 11:33 AM, stan wrote: > I would like to write a generic function that I can place as a BEFORE trigger > on several tables. It would do a max() on the column it was triggered for, and > return(max + 1) unless max returns a NULL, in which case it would return one. > > Yes, I know this looks a lot like a sequence, but normally this value would > be provided manually at row input time, I just want to allow for some > automated updates. > > The trick is hat the function needs to work for any numeric column I place it n > as a trigger. > What procedural language? Triggers are placed on tables not columns so you will need some way of identifying the column(s) in the table. Trigger functions can take arguments even though they are not declared in the function creation. So that is one way of defining the column. > -- Adrian Klaver adrian.klaver@aklaver.com