Fix core dump due to null-pointer dereference in to_char() when datetime format codes are misapplied to a numeric argument.  (The code still produces a pretty bogus error message in such cases, but I'll settle for stopping the crash for now.)  Per bug #4700 from Sergey Burladyan.
Fix core dump due to null-pointer dereference in to_char() when datetime
format codes are misapplied to a numeric argument.  (The code still produces
a pretty bogus error message in such cases, but I'll settle for stopping the
crash for now.)  Per bug #4700 from Sergey Burladyan.

Problem exists in all supported branches, so patch all the way back.
In HEAD, also clean up some ugly coding in the nearby cache management
code.

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