Broken handling of NULLs in TG_ARGV

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Broken handling of NULLs in TG_ARGV
Date: 2015-04-30 23:26:23
Message-ID: 5542BA1F.40501@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

plpgsql's handling of NULLs in TG_ARGV turns actual nulls into text
'null'. Hopefully we can all agree that's broken. I'd like to fix it,
but wonder how to handle existing user code.

My suspicion is that most users will never notice this and I can just
fix it.

I could also add a plpgsql option to provide the old behavior.

What I'd prefer not to do is keep defaulting to the current behavior.
Users are unlikely to notice that, keep using the broken behavior, and
still complain when we change the default.

decibel(at)decina(dot)local=# create temp table t(t text);
CREATE TABLE
decibel(at)decina(dot)local=# create function tg() returns trigger language
plpgsql as $$BEGIN RAISE '"%" is null? %', tg_argv[0], tg_argv[0] is
null; end$$;
CREATE FUNCTION
decibel(at)decina(dot)local=# create trigger t before insert on t for each row
execute procedure tg(NULL);
CREATE TRIGGER
decibel(at)decina(dot)local=# insert into t values('a');
ERROR: "null" is null? f
decibel(at)decina(dot)local=# drop trigger t on t;
DROP TRIGGER
decibel(at)decina(dot)local=# create trigger t before insert on t for each row
execute procedure tg();
CREATE TRIGGER
decibel(at)decina(dot)local=# insert into t values('a');
ERROR: "<NULL>" is null? t
decibel(at)decina(dot)local=# drop trigger t on t;
DROP TRIGGER
decibel(at)decina(dot)local=# create trigger t before insert on t for each row
execute procedure tg('null');
CREATE TRIGGER
decibel(at)decina(dot)local=# insert into t values('a');
ERROR: "null" is null? f
decibel(at)decina(dot)local=#

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-04-30 23:44:39 Re: Broken handling of NULLs in TG_ARGV
Previous Message Bruce Momjian 2015-04-30 23:16:12 Re: collations in shared catalogs?