Fix plpgsql's exec_eval_expr() to ensure it returns a sane type OID even when the expression is a query that returns no rows.
Fix plpgsql's exec_eval_expr() to ensure it returns a sane type OID
even when the expression is a query that returns no rows.

So far as I can tell, the only caller that actually fails when a garbage
OID is returned is exec_stmt_case(), which is new in 8.4 --- in all other
cases, we might make a useless trip through casting logic, but we won't
fail since the isnull flag will be set.  Hence, backpatch only to 8.4,
just in case there are apps out there that aren't expecting an error to
be thrown if the query returns more or less than one column.  (Which seems
unlikely, since the error would be thrown if the query ever did return a
row; but it's possible there's some never-exercised code out there.)

Per report from Mario Splivalo.

(cherry picked from commit f7c5ff3d6d003a33fb12d77cc4057af6e8279c84)

Chibin/gpdb,jmcatamney/gpdb,edespino/gpdb,greenplum-db/gpdb,xinzweb/gpdb,lisakowen/gpdb,greenplum-db/gpdb,adam8157/gpdb,yuanzhao/gpdb,yuanzhao/gpdb,xinzweb/gpdb,Chibin/gpdb,yuanzhao/gpdb,jmcatamney/gpdb,50wu/gpdb,50wu/gpdb,50wu/gpdb,adam8157/gpdb,jmcatamney/gpdb,lisakowen/gpdb,50wu/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,yuanzhao/gpdb,50wu/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,lisakowen/gpdb,Chibin/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,yuanzhao/gpdb,lisakowen/gpdb,edespino/gpdb,Chibin/gpdb,edespino/gpdb,adam8157/gpdb,xinzweb/gpdb,xinzweb/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,xinzweb/gpdb,Chibin/gpdb,Chibin/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,Chibin/gpdb,xinzweb/gpdb,ashwinstar/gpdb,50wu/gpdb,50wu/gpdb,edespino/gpdb,lisakowen/gpdb,edespino/gpdb,jmcatamney/gpdb,lisakowen/gpdb,Chibin/gpdb,adam8157/gpdb,adam8157/gpdb,yuanzhao/gpdb,50wu/gpdb,edespino/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,edespino/gpdb,yuanzhao/gpdb,xinzweb/gpdb,adam8157/gpdb,adam8157/gpdb,edespino/gpdb,edespino/gpdb,lisakowen/gpdb,Chibin/gpdb,yuanzhao/gpdb,xinzweb/gpdb,Chibin/gpdb,ashwinstar/gpdb,yuanzhao/gpdb,ashwinstar/gpdb,yuanzhao/gpdb,jmcatamney/gpdb,adam8157/gpdb,edespino/gpdb,greenplum-db/gpdb,lisakowen/gpdb