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 1huVy8-0004kn-O6 for pgsql-general@arkaria.postgresql.org; Mon, 05 Aug 2019 05:55:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1huVy5-0004ow-G5 for pgsql-general@arkaria.postgresql.org; Mon, 05 Aug 2019 05:55:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1huVy5-0004kH-3Z for pgsql-general@lists.postgresql.org; Mon, 05 Aug 2019 05:55:37 +0000 Received: from mout.kundenserver.de ([217.72.192.74]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1huVy2-00027j-AR for pgsql-general@lists.postgresql.org; Mon, 05 Aug 2019 05:55:35 +0000 Received: from [10.8.0.6] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.145]) with ESMTPSA (Nemesis) id 1MX0TX-1hs2393DM9-00XKwJ for ; Mon, 05 Aug 2019 07:55:30 +0200 Subject: Re: How to check if a field exists in NEW in trigger To: pgsql-general@lists.postgresql.org References: <0cc87310-590f-740e-977d-bcdde57eef1b@lucee.org> From: Thomas Kellerer Message-ID: <37107788-df16-ca5f-3193-6176fe40f282@gmx.net> Date: Mon, 5 Aug 2019 07:55:29 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: <0cc87310-590f-740e-977d-bcdde57eef1b@lucee.org> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Enco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JCSlQV5fAdeODo3DIv57xtOCFozDRIdB0= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Igal @ Lucee.org schrieb am 05.08.2019 um 00:52: > I have the following statement in a trigger: > >     new.email = lower(new.email); > > When I try to update a record without setting the email column however, I get an error: > > SQL Error [42703]: ERROR: record "new" has no field "email" >   Where: SQL statement "SELECT lower(new.email)" > PL/pgSQL function on_record_modified() line 26 at assignment > > I have seen some hacks suggesting TRY/CATCH or converting to a JSON > and checking if the field exists, but I would think that there's a > better way to check if the field is in the NEW record, no? I assume using to_jsonb(new) and then check for the key in the json value will be faster than checking e.g. information_schema.column or pg_catalog.pg_attribute