Probably something dumb, but I just can't make it work. I have this table:
Table "public.office"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+-------------------------------
id | integer | | not null | generated by default as identity
name | text | | not null |
url | text | | |
domain | text | | |
...
Triggers:
updated_save_domain_from_url AFTER UPDATE OF url ON office FOR EACH ROW EXECUTE PROCEDURE save_domain_from_url()
And this trigger function:
-- TRIGGER FUNCTION
CREATE OR REPLACE FUNCTION public.save_domain_from_url()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
new.domain := substring(new.url from '(?:.*://)?(?:www\.)?([^/]*)');
RETURN new;
END;
$function$
Example row:
id | name | url | domain
-----+---------------------------------+--------+--------
425 | Van Halewyck & Marco Architects | [NULL] | [NULL]
When I update the URL:
update office set url = 'http://vanhalewyck-marco.com/en' where id = 425;
The domain is still null, trigger did not work:
id | name | url | domain
-----+---------------------------------+---------------------------------+--------
425 | Van Halewyck & Marco Architects | http://vanhalewyck-marco.com/en | [NULL]
Any hints of what might be going on, please help!!
Thanks