Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7c5ff3

Browse files
committed
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 garbageOID is returned is exec_stmt_case(), which is new in 8.4 --- in all othercases, we might make a useless trip through casting logic, but we won'tfail 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 tobe thrown if the query returns more or less than one column. (Which seemsunlikely, since the error would be thrown if the query ever did return arow; but it's possible there's some never-exercised code out there.)Per report from Mario Splivalo.
1 parent73981cb commitf7c5ff3

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.256 2010/02/26 02:01:34 momjian Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.257 2010/04/14 23:52:10 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4158,7 +4158,24 @@ exec_eval_expr(PLpgSQL_execstate *estate,
41584158
errmsg("query \"%s\" did not return data",expr->query)));
41594159

41604160
/*
4161-
* If there are no rows selected, the result is NULL.
4161+
* Check that the expression returns exactly one column...
4162+
*/
4163+
if (estate->eval_tuptable->tupdesc->natts!=1)
4164+
ereport(ERROR,
4165+
(errcode(ERRCODE_SYNTAX_ERROR),
4166+
errmsg_plural("query \"%s\" returned %d column",
4167+
"query \"%s\" returned %d columns",
4168+
estate->eval_tuptable->tupdesc->natts,
4169+
expr->query,
4170+
estate->eval_tuptable->tupdesc->natts)));
4171+
4172+
/*
4173+
* ... and get the column's datatype.
4174+
*/
4175+
*rettype=SPI_gettypeid(estate->eval_tuptable->tupdesc,1);
4176+
4177+
/*
4178+
* If there are no rows selected, the result is a NULL of that type.
41624179
*/
41634180
if (estate->eval_processed==0)
41644181
{
@@ -4167,26 +4184,17 @@ exec_eval_expr(PLpgSQL_execstate *estate,
41674184
}
41684185

41694186
/*
4170-
* Check that the expression returnedone single Datum
4187+
* Check that the expression returnedno more than one row.
41714188
*/
4172-
if (estate->eval_processed>1)
4189+
if (estate->eval_processed!=1)
41734190
ereport(ERROR,
41744191
(errcode(ERRCODE_CARDINALITY_VIOLATION),
41754192
errmsg("query \"%s\" returned more than one row",
41764193
expr->query)));
4177-
if (estate->eval_tuptable->tupdesc->natts!=1)
4178-
ereport(ERROR,
4179-
(errcode(ERRCODE_SYNTAX_ERROR),
4180-
errmsg_plural("query \"%s\" returned %d column",
4181-
"query \"%s\" returned %d columns",
4182-
estate->eval_tuptable->tupdesc->natts,
4183-
expr->query,
4184-
estate->eval_tuptable->tupdesc->natts)));
41854194

41864195
/*
4187-
* Return the resultand its type
4196+
* Return thesingleresultDatum.
41884197
*/
4189-
*rettype=SPI_gettypeid(estate->eval_tuptable->tupdesc,1);
41904198
returnSPI_getbinval(estate->eval_tuptable->vals[0],
41914199
estate->eval_tuptable->tupdesc,1,isNull);
41924200
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp