@@ -162,33 +162,38 @@ public async Task Merge_RecordsAffected_and_Rows()
162162 await reader . CloseAsync ( ) ;
163163
164164 var command = batch . BatchCommands [ 0 ] ;
165+ Assert . That ( command . StatementType , Is . EqualTo ( StatementType . Merge ) ) ;
165166 Assert . That ( command . RecordsAffected , Is . EqualTo ( 2 ) ) ;
166167 Assert . That ( command . Rows , Is . EqualTo ( 2 ) ) ;
167168
168169 command = batch . BatchCommands [ 1 ] ;
170+ Assert . That ( command . StatementType , Is . EqualTo ( StatementType . Merge ) ) ;
169171 Assert . That ( command . RecordsAffected , Is . EqualTo ( 1 ) ) ;
170172 Assert . That ( command . Rows , Is . EqualTo ( 1 ) ) ;
171173
172174 command = batch . BatchCommands [ 2 ] ;
175+ Assert . That ( command . StatementType , Is . EqualTo ( StatementType . Merge ) ) ;
173176 Assert . That ( command . RecordsAffected , Is . EqualTo ( 1 ) ) ;
174177 Assert . That ( command . Rows , Is . EqualTo ( 1 ) ) ;
175178
176179 command = batch . BatchCommands [ 3 ] ;
180+ Assert . That ( command . StatementType , Is . EqualTo ( StatementType . Merge ) ) ;
177181 Assert . That ( command . RecordsAffected , Is . EqualTo ( 1 ) ) ;
178182 Assert . That ( command . Rows , Is . EqualTo ( 1 ) ) ;
179183
180184 command = batch . BatchCommands [ 4 ] ;
185+ Assert . That ( command . StatementType , Is . EqualTo ( StatementType . Merge ) ) ;
181186 Assert . That ( command . RecordsAffected , Is . EqualTo ( 0 ) ) ;
182187 Assert . That ( command . Rows , Is . EqualTo ( 0 ) ) ;
183188 }
184189
185190 [ Test ]
186- public async Task NpgsqlBatchCommand_StatementType ( )
191+ public async Task StatementTypes ( )
187192 {
188193 await using var conn = await OpenConnectionAsync ( ) ;
189194 await using var _ = await CreateTempTable ( conn , "name TEXT" , out var table ) ;
190- var sproc = await GetTempProcedureName ( conn ) ;
191195
196+ var sproc = await GetTempProcedureName ( conn ) ;
192197 await conn . ExecuteNonQueryAsync ( @$ "CREATE PROCEDURE { sproc } () LANGUAGE sql AS ''") ;
193198
194199 await using var batch = new NpgsqlBatch ( conn )
@@ -201,14 +206,10 @@ public async Task NpgsqlBatchCommand_StatementType()
201206 new ( "BEGIN" ) ,
202207 new ( $ "SELECT name FROM { table } ") ,
203208 new ( $ "DELETE FROM { table } ") ,
204- new ( $ "CALL { sproc } ()") ,
205209 new ( "COMMIT" )
206210 }
207211 } ;
208212
209- if ( conn . PostgreSqlVersion . IsGreaterOrEqual ( 15 ) )
210- batch . BatchCommands . Add ( new ( $ "MERGE INTO { table } S USING (SELECT 'b' as name) T ON T.name = S.name WHEN NOT MATCHED THEN DO NOTHING") ) ;
211-
212213 await using var reader = await batch . ExecuteReaderAsync ( Behavior ) ;
213214
214215 // Consume SELECT result set to parse the CommandComplete
@@ -220,11 +221,50 @@ public async Task NpgsqlBatchCommand_StatementType()
220221 Assert . That ( batch . BatchCommands [ 3 ] . StatementType , Is . EqualTo ( StatementType . Other ) ) ;
221222 Assert . That ( batch . BatchCommands [ 4 ] . StatementType , Is . EqualTo ( StatementType . Select ) ) ;
222223 Assert . That ( batch . BatchCommands [ 5 ] . StatementType , Is . EqualTo ( StatementType . Delete ) ) ;
223- Assert . That ( batch . BatchCommands [ 6 ] . StatementType , Is . EqualTo ( StatementType . Call ) ) ;
224- Assert . That ( batch . BatchCommands [ 7 ] . StatementType , Is . EqualTo ( StatementType . Other ) ) ;
224+ Assert . That ( batch . BatchCommands [ 6 ] . StatementType , Is . EqualTo ( StatementType . Other ) ) ;
225+ }
226+
227+ [ Test ]
228+ public async Task StatementType_Call ( )
229+ {
230+ await using var conn = await OpenConnectionAsync ( ) ;
231+ MinimumPgVersion ( conn , "11.0" , "Stored procedures are supported starting with PG 11" ) ;
232+
233+ var sproc = await GetTempProcedureName ( conn ) ;
234+ await conn . ExecuteNonQueryAsync ( $ "CREATE PROCEDURE { sproc } () LANGUAGE sql AS ''") ;
235+
236+ await using var batch = new NpgsqlBatch ( conn )
237+ {
238+ BatchCommands = { new ( $ "CALL { sproc } ()") }
239+ } ;
240+
241+ await using var reader = await batch . ExecuteReaderAsync ( Behavior ) ;
242+
243+ // Consume SELECT result set to parse the CommandComplete
244+ await reader . CloseAsync ( ) ;
245+
246+ Assert . That ( batch . BatchCommands [ 0 ] . StatementType , Is . EqualTo ( StatementType . Call ) ) ;
247+ }
248+
249+ [ Test ]
250+ public async Task StatementType_Merge ( )
251+ {
252+ await using var conn = await OpenConnectionAsync ( ) ;
253+ MinimumPgVersion ( conn , "15.0" , "Stored procedures are supported starting with PG 11" ) ;
254+
255+ await using var _ = await CreateTempTable ( conn , "name TEXT" , out var table ) ;
256+
257+ await using var batch = new NpgsqlBatch ( conn )
258+ {
259+ BatchCommands = { new ( $ "MERGE INTO { table } S USING (SELECT 'b' as name) T ON T.name = S.name WHEN NOT MATCHED THEN DO NOTHING") }
260+ } ;
261+
262+ await using var reader = await batch . ExecuteReaderAsync ( Behavior ) ;
263+
264+ // Consume SELECT result set to parse the CommandComplete
265+ await reader . CloseAsync ( ) ;
225266
226- if ( conn . PostgreSqlVersion . IsGreaterOrEqual ( 15 ) )
227- Assert . That ( batch . BatchCommands [ 8 ] . StatementType , Is . EqualTo ( StatementType . Merge ) ) ;
267+ Assert . That ( batch . BatchCommands [ 0 ] . StatementType , Is . EqualTo ( StatementType . Merge ) ) ;
228268 }
229269
230270 [ Test ]
0 commit comments