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 1i9Crt-0001qj-S9 for pgsql-general@arkaria.postgresql.org; Sat, 14 Sep 2019 18:33:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9Crs-0000PH-P9 for pgsql-general@arkaria.postgresql.org; Sat, 14 Sep 2019 18:33:56 +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 1i9Crs-0000PA-FX for pgsql-general@lists.postgresql.org; Sat, 14 Sep 2019 18:33:56 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9Crp-0002id-RF for pgsql-general@lists.postgresql.org; Sat, 14 Sep 2019 18:33:55 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46W1Nv1t5fz1YWd for ; Sat, 14 Sep 2019 14:33:51 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46W1Nv0Q1wz1ZVT; Sat, 14 Sep 2019 14:33:51 -0400 (EDT) Date: Sat, 14 Sep 2019 14:33:50 -0400 From: stan To: pgsql-general@lists.postgresql.org Subject: Can I wrtie a function that has a BEFORE trigger that is not column name dpendent? Message-ID: <20190914183350.GA3904@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Editor: gVim User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin