I've a table with various columns - some of them can be NULL (there is no default value for them).
So I've created a trigger and each time I've a new value inserted in the table I want to trigger a pg_notify. (Hint: I'm a total noob about SQL).
The problem is that if just one of the column that can be null have a void value, then all the payload emitted by pg_notify is null.
A really simple example:
postgres=# create table example(id serial, name varchar);
CREATE TABLE
postgres=# create function new_example() RETURNS trigger AS $$
DECLARE
BEGIN
PERFORM pg_notify('example', 'id: ' || NEW.id || ' name: ' || NEW.name);
RETURN new;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# create trigger new_ex AFTER INSERT ON example FOR EACH ROW EXECUTE PROCEDURE new_example();
CREATE TRIGGER
postgres=# LISTEN example;
LISTEN
postgres=# INSERT into example(name) VALUES ('a');
INSERT 0 1
Asynchronous notification "example" with payload "id : 1 name: a" received from server process with PID 22349.
This is correct - I've inserted a new row and the notify is exactly what I expect
postgres=# INSERT into example(name) VALUES (NULL);
INSERT 0 1
Asynchronous notification "example" received from server process with PID 22349.
This does not make any sense. I would expect something like Asynchronous notification "example" with payload "id : 1 name: NULL" received from server process with PID 22349. or Asynchronous notification "example" with payload "id : 1 name:" received from server process with PID 22349.
What do I do wrong?