plpgsql's exec_simple_cast_value() mistakenly supposed that it could bypass casting effort whenever the input value was NULL.  However this prevents application of not-null domain constraints in the cases that use this function, as illustrated in bug #4741.  Since this function isn't meant for use in performance-critical paths anyway, this certainly seems like another case of "premature optimization is the root of all evil".
plpgsql's exec_simple_cast_value() mistakenly supposed that it could bypass
casting effort whenever the input value was NULL.  However this prevents
application of not-null domain constraints in the cases that use this
function, as illustrated in bug #4741.  Since this function isn't meant
for use in performance-critical paths anyway, this certainly seems like
another case of "premature optimization is the root of all evil".

Back-patch as far as 8.2; older versions made no effort to enforce
domain constraints here anyway.

jmcatamney/gpdb,Chibin/gpdb,arcivanov/postgres-xl,Postgres-XL/Postgres-XL,greenplum-db/gpdb,50wu/gpdb,tpostgres-projects/tPostgres,oberstet/postgres-xl,ovr/postgres-xl,zeroae/postgres-xl,ashwinstar/gpdb,pavanvd/postgres-xl,xinzweb/gpdb,Chibin/gpdb,50wu/gpdb,yuanzhao/gpdb,zeroae/postgres-xl,ovr/postgres-xl,oberstet/postgres-xl,techdragon/Postgres-XL,techdragon/Postgres-XL,adam8157/gpdb,lisakowen/gpdb,tpostgres-projects/tPostgres,50wu/gpdb,edespino/gpdb,yuanzhao/gpdb,postmind-net/postgres-xl,xinzweb/gpdb,yazun/postgres-xl,Chibin/gpdb,snaga/postgres-xl,edespino/gpdb,snaga/postgres-xl,postmind-net/postgres-xl,edespino/gpdb,lisakowen/gpdb,yazun/postgres-xl,ashwinstar/gpdb,Chibin/gpdb,yuanzhao/gpdb,arcivanov/postgres-xl,greenplum-db/gpdb,adam8157/gpdb,Chibin/gpdb,yuanzhao/gpdb,tpostgres-projects/tPostgres,yuanzhao/gpdb,50wu/gpdb,zeroae/postgres-xl,Postgres-XL/Postgres-XL,ovr/postgres-xl,xinzweb/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,arcivanov/postgres-xl,edespino/gpdb,lisakowen/gpdb,xinzweb/gpdb,greenplum-db/gpdb,xinzweb/gpdb,snaga/postgres-xl,Chibin/gpdb,Chibin/gpdb,xinzweb/gpdb,edespino/gpdb,50wu/gpdb,lisakowen/gpdb,xinzweb/gpdb,Postgres-XL/Postgres-XL,50wu/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,oberstet/postgres-xl,greenplum-db/gpdb,lisakowen/gpdb,Chibin/gpdb,adam8157/gpdb,yazun/postgres-xl,zeroae/postgres-xl,greenplum-db/gpdb,xinzweb/gpdb,edespino/gpdb,oberstet/postgres-xl,pavanvd/postgres-xl,pavanvd/postgres-xl,zeroae/postgres-xl,jmcatamney/gpdb,ovr/postgres-xl,pavanvd/postgres-xl,edespino/gpdb,techdragon/Postgres-XL,yazun/postgres-xl,yuanzhao/gpdb,tpostgres-projects/tPostgres,postmind-net/postgres-xl,oberstet/postgres-xl,kmjungersen/PostgresXL,Chibin/gpdb,edespino/gpdb,lisakowen/gpdb,jmcatamney/gpdb,yuanzhao/gpdb,adam8157/gpdb,kmjungersen/PostgresXL,pavanvd/postgres-xl,postmind-net/postgres-xl,lisakowen/gpdb,kmjungersen/PostgresXL,kmjungersen/PostgresXL,ashwinstar/gpdb,lisakowen/gpdb,adam8157/gpdb,50wu/gpdb,Postgres-XL/Postgres-XL,arcivanov/postgres-xl,tpostgres-projects/tPostgres,adam8157/gpdb,postmind-net/postgres-xl,ashwinstar/gpdb,yuanzhao/gpdb,snaga/postgres-xl,arcivanov/postgres-xl,techdragon/Postgres-XL,ovr/postgres-xl,arcivanov/postgres-xl,greenplum-db/gpdb,yazun/postgres-xl,edespino/gpdb,Postgres-XL/Postgres-XL,Chibin/gpdb,snaga/postgres-xl,jmcatamney/gpdb,50wu/gpdb,yuanzhao/gpdb,edespino/gpdb,greenplum-db/gpdb,kmjungersen/PostgresXL,adam8157/gpdb,greenplum-db/gpdb,techdragon/Postgres-XL,adam8157/gpdb,yuanzhao/gpdb,jmcatamney/gpdb,jmcatamney/gpdb