8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
25
25
#include "parser/parse_expr.h"
26
26
#include "parser/parse_func.h"
27
27
#include "parser/parse_relation.h"
28
+ #include "parser/parse_target.h"
28
29
#include "parser/parse_type.h"
29
30
#include "utils/builtins.h"
30
31
#include "utils/fmgroids.h"
@@ -957,6 +958,9 @@ ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg)
957
958
* function. A bonus is that we avoid generating an unnecessary
958
959
* FieldSelect; our result can omit the whole-row Var and just be a
959
960
* 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.
960
964
*/
961
965
if (IsA (first_arg , Var ) &&
962
966
((Var * ) first_arg )-> varattno == InvalidAttrNumber )
@@ -971,12 +975,18 @@ ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg)
971
975
}
972
976
973
977
/*
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().
977
983
*/
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 )
979
988
return NULL ; /* unresolvable RECORD type */
989
+ Assert (tupdesc );
980
990
981
991
for (i = 0 ; i < tupdesc -> natts ; i ++ )
982
992
{
0 commit comments