88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.179 2005/04/23 22:09:58 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.180 2005/05/31 01:03:23 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
2525#include "parser/parse_expr.h"
2626#include "parser/parse_func.h"
2727#include "parser/parse_relation.h"
28+ #include "parser/parse_target.h"
2829#include "parser/parse_type.h"
2930#include "utils/builtins.h"
3031#include "utils/fmgroids.h"
@@ -957,6 +958,9 @@ ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg)
957958 * function. A bonus is that we avoid generating an unnecessary
958959 * FieldSelect; our result can omit the whole-row Var and just be a
959960 * Var for the selected field.
961+ *
962+ * This case could be handled by expandRecordVariable, but it's
963+ * more efficient to do it this way when possible.
960964 */
961965 if (IsA (first_arg , Var ) &&
962966 ((Var * ) first_arg )-> varattno == InvalidAttrNumber )
@@ -971,12 +975,18 @@ ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg)
971975 }
972976
973977 /*
974- * Else do it the hard way. Note that if the arg is of RECORD type,
975- * and isn't resolvable as a function with OUT params, we will never
976- * be able to recognize a column name here.
978+ * Else do it the hard way with get_expr_result_type().
979+ *
980+ * If it's a Var of type RECORD, we have to work even harder: we have
981+ * to find what the Var refers to, and pass that to get_expr_result_type.
982+ * That task is handled by expandRecordVariable().
977983 */
978- if (get_expr_result_type (first_arg , NULL , & tupdesc ) != TYPEFUNC_COMPOSITE )
984+ if (IsA (first_arg , Var ) &&
985+ ((Var * ) first_arg )-> vartype == RECORDOID )
986+ tupdesc = expandRecordVariable (pstate , (Var * ) first_arg , 0 );
987+ else if (get_expr_result_type (first_arg , NULL , & tupdesc ) != TYPEFUNC_COMPOSITE )
979988 return NULL ; /* unresolvable RECORD type */
989+ Assert (tupdesc );
980990
981991 for (i = 0 ; i < tupdesc -> natts ; i ++ )
982992 {
0 commit comments