Dienstag, 27. Februar 2024

PL/pgSQL function trigger does not insert/update/delete records even though it is inteded and ought to

Lately, I developed an insert trigger that was supposed to check whether for specific cases a column of the new was filled or not and raise an exception if appropriate. However, it did not. It turns out that PL/pgSQL functions need to return a record, if one wants the original operation to happen. If NULL is returned, the operation is not carried out. Coming from Oracle, I missed it, even though it is quite clearly documented.

In hhe PostgreSQL way, it is easy to write a trigger that just does nothing if necessary. I would not know by heart how to do that in Oracle.

Syntax error at "%" … "invalid type name" error in variable declaration of PL/pgSQL

There I was hunting down the cause mentioned error message, being quite clueless. Thankfully, the PostgreSQL e-mail list was helpful, nudging me in the right direction. The message was a bit obfuscated by my use of unusual characters in the names of my objects and variables, in my case: ⠒

I was believing that for some strange reason, PL/pgSQL was unable to handle this character in the type clause, e.g.

variable⠒name  table⠒name.column⠒name%TYPE;

The point was, that I had messed up the order of installation of the things. The table, I was trying to copy the type from, had not been recreated by the installation script yet. I would expect that the parser would return with a missing table/view message, but "invalid type name" is not wrong, if not so straight forward as it could be. The developers of that part actually were aware of a problem there. Maybe the will get around to improve the error message.