I have been looking at this SO post as a basis for this trigger.
I need to do a large import of several tables with several UUID fields, which were formerly stored as char(35)
in MySQL, some of which are blank ('').
I'd like to automatically change blanks to nil UUIDs using a BEFORE INSERT TRIGGER.
Currently I have the trigger function simplified to this:
CREATE OR REPLACE FUNCTION trg_uc_on_insert()
RETURNS trigger AS
$func$
BEGIN
RAISE NOTICE 'in function';
NEW.id=uuid_generate_v1();
RETURN NEW;
END
$func$ LANGUAGE plpgsql;
And I'm running
create table uuidtest (id uuid);
insert into uuidtest values ('');
but I am still getting
[Err] ERROR: invalid input syntax for uuid: ""
LINE 1: insert into uuidtest values ('');
I have too much data to import and I would much rather let PostgreSQL change the values before the insert than do it myself.
Is this possible using this mechanism, and if so, what am I doing wrong?