diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 09c86aa4c676f93bae92fcad65fdb41f5c636379..a385b9a82a20ef1b6dbb83c35f8df8e286f24d59 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -1447,17 +1447,9 @@ exec_stmt_getdiag(PLpgSQL_execstate *estate, PLpgSQL_stmt_getdiag *stmt)
 	foreach(lc, stmt->diag_items)
 	{
 		PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc);
-		PLpgSQL_datum *var;
+		PLpgSQL_datum *var = estate->datums[diag_item->target];
 		bool		isnull = false;
 
-		if (diag_item->target <= 0)
-			continue;
-
-		var = estate->datums[diag_item->target];
-
-		if (var == NULL)
-			continue;
-
 		switch (diag_item->kind)
 		{
 			case PLPGSQL_GETDIAG_ROW_COUNT: