@@ -1369,3 +1369,42 @@ func TestConnDeallocateInvalidatedCachedStatementsWhenCanceled(t *testing.T) {
1369
1369
require .EqualValues (t , 1 , n )
1370
1370
})
1371
1371
}
1372
+
1373
+ // https://github.com/jackc/pgx/issues/1847
1374
+ func TestConnDeallocateInvalidatedCachedStatementsInTransactionWithBatch (t * testing.T ) {
1375
+ t .Parallel ()
1376
+
1377
+ ctx := context .Background ()
1378
+
1379
+ connString := os .Getenv ("PGX_TEST_DATABASE" )
1380
+ config := mustParseConfig (t , connString )
1381
+ config .DefaultQueryExecMode = pgx .QueryExecModeCacheStatement
1382
+ config .StatementCacheCapacity = 2
1383
+
1384
+ conn , err := pgx .ConnectConfig (ctx , config )
1385
+ require .NoError (t , err )
1386
+
1387
+ tx , err := conn .Begin (ctx )
1388
+ require .NoError (t , err )
1389
+ defer tx .Rollback (ctx )
1390
+
1391
+ _ , err = tx .Exec (ctx , "select $1::int + 1" , 1 )
1392
+ require .NoError (t , err )
1393
+
1394
+ _ , err = tx .Exec (ctx , "select $1::int + 2" , 1 )
1395
+ require .NoError (t , err )
1396
+
1397
+ // This should invalidate the first cached statement.
1398
+ _ , err = tx .Exec (ctx , "select $1::int + 3" , 1 )
1399
+ require .NoError (t , err )
1400
+
1401
+ batch := & pgx.Batch {}
1402
+ batch .Queue ("select $1::int + 1" , 1 )
1403
+ err = tx .SendBatch (ctx , batch ).Close ()
1404
+ require .NoError (t , err )
1405
+
1406
+ err = tx .Rollback (ctx )
1407
+ require .NoError (t , err )
1408
+
1409
+ ensureConnValid (t , conn )
1410
+ }
0 commit comments