Re: How to check if a field exists in NEW in trigger

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: How to check if a field exists in NEW in trigger
Дата
Msg-id 37107788-df16-ca5f-3193-6176fe40f282@gmx.net
обсуждение исходный текст
Ответ на How to check if a field exists in NEW in trigger  ("Igal @ Lucee.org" <igal@lucee.org>)
Ответы Re: How to check if a field exists in NEW in trigger  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-general
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



В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: How to check if a field exists in NEW in trigger
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: How to check if a field exists in NEW in trigger