|
7 | 7 | * Copyright (c) 2002-2005, PostgreSQL Global Development Group
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $PostgreSQL: pgsql/src/backend/utils/fmgr/funcapi.c,v 1.21 2005/04/25 20:59:44 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/utils/fmgr/funcapi.c,v 1.22 2005/05/28 05:10:47 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -235,6 +235,36 @@ get_expr_result_type(Node *expr,
|
235 | 235 | NULL,
|
236 | 236 | resultTypeId,
|
237 | 237 | resultTupleDesc);
|
| 238 | +elseif (expr&&IsA(expr,Const)&& |
| 239 | + ((Const*)expr)->consttype==RECORDOID&& |
| 240 | + !((Const*)expr)->constisnull) |
| 241 | +{ |
| 242 | +/* |
| 243 | + * Pull embedded type info from a RECORD constant. We have to be |
| 244 | + * prepared to handle this case in the wake of constant-folding of |
| 245 | + * record-returning functions. |
| 246 | + */ |
| 247 | +HeapTupleHeadertd; |
| 248 | +int32typmod; |
| 249 | + |
| 250 | +td=DatumGetHeapTupleHeader(((Const*)expr)->constvalue); |
| 251 | +Assert(HeapTupleHeaderGetTypeId(td)==RECORDOID); |
| 252 | +typmod=HeapTupleHeaderGetTypMod(td); |
| 253 | +if (resultTypeId) |
| 254 | +*resultTypeId=RECORDOID; |
| 255 | +if (typmod >=0) |
| 256 | +{ |
| 257 | +if (resultTupleDesc) |
| 258 | +*resultTupleDesc=lookup_rowtype_tupdesc(RECORDOID,typmod); |
| 259 | +result=TYPEFUNC_COMPOSITE; |
| 260 | +} |
| 261 | +else |
| 262 | +{ |
| 263 | +if (resultTupleDesc) |
| 264 | +*resultTupleDesc=NULL; |
| 265 | +result=TYPEFUNC_RECORD; |
| 266 | +} |
| 267 | +} |
238 | 268 | else
|
239 | 269 | {
|
240 | 270 | /* handle as a generic expression; no chance to resolve RECORD */
|
|