Force the second argument of SUBSTRING(foo FOR bar) to be int4, to avoid surprising results when it's some other numeric type.  This doesn't solve the generic problem of surprising implicit casts to text, but it's a low-impact way of making sure this particular case behaves sanely. Per gripe from Harald Fuchs and subsequent discussion.
Force the second argument of SUBSTRING(foo FOR bar) to be int4, to avoid
surprising results when it's some other numeric type.  This doesn't solve
the generic problem of surprising implicit casts to text, but it's a
low-impact way of making sure this particular case behaves sanely.
Per gripe from Harald Fuchs and subsequent discussion.

Chibin/gpdb,randomtask1155/gpdb,tangp3/gpdb,lpetrov-pivotal/gpdb,randomtask1155/gpdb,edespino/gpdb,greenplum-db/gpdb,postmind-net/postgres-xl,kmjungersen/PostgresXL,rvs/gpdb,randomtask1155/gpdb,chrishajas/gpdb,rvs/gpdb,rvs/gpdb,postmind-net/postgres-xl,greenplum-db/gpdb,foyzur/gpdb,50wu/gpdb,xinzweb/gpdb,pavanvd/postgres-xl,atris/gpdb,CraigHarris/gpdb,pavanvd/postgres-xl,yuanzhao/gpdb,jmcatamney/gpdb,50wu/gpdb,zaksoup/gpdb,tpostgres-projects/tPostgres,0x0FFF/gpdb,ahachete/gpdb,rubikloud/gpdb,CraigHarris/gpdb,foyzur/gpdb,Chibin/gpdb,Postgres-XL/Postgres-XL,lpetrov-pivotal/gpdb,yuanzhao/gpdb,yuanzhao/gpdb,royc1/gpdb,randomtask1155/gpdb,kmjungersen/PostgresXL,edespino/gpdb,ahachete/gpdb,50wu/gpdb,lpetrov-pivotal/gpdb,50wu/gpdb,0x0FFF/gpdb,kaknikhil/gpdb,CraigHarris/gpdb,royc1/gpdb,jmcatamney/gpdb,lpetrov-pivotal/gpdb,rvs/gpdb,lintzc/gpdb,foyzur/gpdb,foyzur/gpdb,xinzweb/gpdb,Chibin/gpdb,kaknikhil/gpdb,zaksoup/gpdb,ovr/postgres-xl,tangp3/gpdb,randomtask1155/gpdb,yuanzhao/gpdb,zaksoup/gpdb,xuegang/gpdb,royc1/gpdb,postmind-net/postgres-xl,chrishajas/gpdb,arcivanov/postgres-xl,yuanzhao/gpdb,yuanzhao/gpdb,janebeckman/gpdb,tpostgres-projects/tPostgres,xinzweb/gpdb,adam8157/gpdb,ahachete/gpdb,chrishajas/gpdb,jmcatamney/gpdb,adam8157/gpdb,Quikling/gpdb,xinzweb/gpdb,oberstet/postgres-xl,Quikling/gpdb,yuanzhao/gpdb,ovr/postgres-xl,Quikling/gpdb,ahachete/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,Postgres-XL/Postgres-XL,CraigHarris/gpdb,edespino/gpdb,zeroae/postgres-xl,foyzur/gpdb,0x0FFF/gpdb,yuanzhao/gpdb,lintzc/gpdb,kmjungersen/PostgresXL,greenplum-db/gpdb,ashwinstar/gpdb,cjcjameson/gpdb,janebeckman/gpdb,Chibin/gpdb,tpostgres-projects/tPostgres,ashwinstar/gpdb,0x0FFF/gpdb,xuegang/gpdb,xinzweb/gpdb,kaknikhil/gpdb,tangp3/gpdb,xuegang/gpdb,lintzc/gpdb,techdragon/Postgres-XL,pavanvd/postgres-xl,Quikling/gpdb,royc1/gpdb,xinzweb/gpdb,0x0FFF/gpdb,kmjungersen/PostgresXL,janebeckman/gpdb,xinzweb/gpdb,yuanzhao/gpdb,chrishajas/gpdb,zeroae/postgres-xl,randomtask1155/gpdb,lintzc/gpdb,royc1/gpdb,tangp3/gpdb,rubikloud/gpdb,ashwinstar/gpdb,Quikling/gpdb,janebeckman/gpdb,kmjungersen/PostgresXL,tpostgres-projects/tPostgres,tangp3/gpdb,rvs/gpdb,yuanzhao/gpdb,janebeckman/gpdb,janebeckman/gpdb,yazun/postgres-xl,ovr/postgres-xl,janebeckman/gpdb,0x0FFF/gpdb,tpostgres-projects/tPostgres,lintzc/gpdb,cjcjameson/gpdb,tangp3/gpdb,adam8157/gpdb,yazun/postgres-xl,ashwinstar/gpdb,atris/gpdb,techdragon/Postgres-XL,rubikloud/gpdb,zeroae/postgres-xl,greenplum-db/gpdb,arcivanov/postgres-xl,oberstet/postgres-xl,lisakowen/gpdb,lisakowen/gpdb,lisakowen/gpdb,royc1/gpdb,janebeckman/gpdb,yazun/postgres-xl,royc1/gpdb,atris/gpdb,xuegang/gpdb,jmcatamney/gpdb,ahachete/gpdb,50wu/gpdb,foyzur/gpdb,0x0FFF/gpdb,lisakowen/gpdb,lisakowen/gpdb,0x0FFF/gpdb,zaksoup/gpdb,arcivanov/postgres-xl,arcivanov/postgres-xl,rvs/gpdb,kaknikhil/gpdb,techdragon/Postgres-XL,edespino/gpdb,Postgres-XL/Postgres-XL,cjcjameson/gpdb,lpetrov-pivotal/gpdb,rubikloud/gpdb,tangp3/gpdb,jmcatamney/gpdb,chrishajas/gpdb,cjcjameson/gpdb,lintzc/gpdb,Quikling/gpdb,atris/gpdb,yazun/postgres-xl,postmind-net/postgres-xl,xuegang/gpdb,pavanvd/postgres-xl,rubikloud/gpdb,oberstet/postgres-xl,lintzc/gpdb,zaksoup/gpdb,Chibin/gpdb,ashwinstar/gpdb,ahachete/gpdb,lintzc/gpdb,kaknikhil/gpdb,xinzweb/gpdb,zeroae/postgres-xl,lpetrov-pivotal/gpdb,cjcjameson/gpdb,Chibin/gpdb,Chibin/gpdb,janebeckman/gpdb,rvs/gpdb,foyzur/gpdb,chrishajas/gpdb,lpetrov-pivotal/gpdb,adam8157/gpdb,techdragon/Postgres-XL,CraigHarris/gpdb,ovr/postgres-xl,greenplum-db/gpdb,rvs/gpdb,cjcjameson/gpdb,50wu/gpdb,kaknikhil/gpdb,zeroae/postgres-xl,50wu/gpdb,zaksoup/gpdb,edespino/gpdb,kaknikhil/gpdb,jmcatamney/gpdb,rvs/gpdb,kaknikhil/gpdb,atris/gpdb,ahachete/gpdb,cjcjameson/gpdb,janebeckman/gpdb,randomtask1155/gpdb,ashwinstar/gpdb,Chibin/gpdb,Postgres-XL/Postgres-XL,ovr/postgres-xl,zaksoup/gpdb,foyzur/gpdb,adam8157/gpdb,royc1/gpdb,snaga/postgres-xl,edespino/gpdb,lpetrov-pivotal/gpdb,lisakowen/gpdb,Quikling/gpdb,ashwinstar/gpdb,CraigHarris/gpdb,arcivanov/postgres-xl,CraigHarris/gpdb,Postgres-XL/Postgres-XL,edespino/gpdb,xuegang/gpdb,ahachete/gpdb,adam8157/gpdb,rvs/gpdb,Chibin/gpdb,50wu/gpdb,xuegang/gpdb,Quikling/gpdb,Chibin/gpdb,snaga/postgres-xl,cjcjameson/gpdb,Quikling/gpdb,xuegang/gpdb,snaga/postgres-xl,xuegang/gpdb,lisakowen/gpdb,tangp3/gpdb,edespino/gpdb,cjcjameson/gpdb,atris/gpdb,edespino/gpdb,rubikloud/gpdb,arcivanov/postgres-xl,lintzc/gpdb,Quikling/gpdb,lisakowen/gpdb,ashwinstar/gpdb,edespino/gpdb,postmind-net/postgres-xl,oberstet/postgres-xl,randomtask1155/gpdb,snaga/postgres-xl,cjcjameson/gpdb,atris/gpdb,snaga/postgres-xl,greenplum-db/gpdb,kaknikhil/gpdb,rubikloud/gpdb,jmcatamney/gpdb,atris/gpdb,jmcatamney/gpdb,pavanvd/postgres-xl,kaknikhil/gpdb,oberstet/postgres-xl,rubikloud/gpdb,adam8157/gpdb,chrishajas/gpdb,CraigHarris/gpdb,adam8157/gpdb,techdragon/Postgres-XL,CraigHarris/gpdb,chrishajas/gpdb,zaksoup/gpdb,yazun/postgres-xl