@@ -164,6 +164,7 @@ export class PostgresServer {
164164// TODO: Remove this code once https://github.com/electric-sql/pglite/pull/294 is released in PGLite
165165export class PGliteExtendedQueryPatch {
166166 isExtendedQuery = false ;
167+ eqpErrored = false ;
167168
168169 constructor ( public connection : PostgresConnection ) { }
169170
@@ -184,16 +185,21 @@ export class PGliteExtendedQueryPatch {
184185 // 'Sync' indicates the end of an extended query
185186 if ( message [ 0 ] === FrontendMessageCode . Sync ) {
186187 this . isExtendedQuery = false ;
188+ this . eqpErrored = false ;
187189
188190 // Manually inject 'ReadyForQuery' message at the end
189191 return this . connection . createReadyForQuery ( ) ;
190192 }
191193
192194 // A PGlite response can contain multiple messages
193195 for await ( const message of getMessages ( response ) ) {
194- // If a prepared statement leads to an error message, we need to end the pipeline.
195- if ( message [ 0 ] === BackendMessageCode . ErrorMessage ) {
196- this . isExtendedQuery = false ;
196+ // After an ErrorMessage in extended query protocol, we should throw away messages until the next Sync
197+ // (per https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY:~:text=When%20an%20error,for%20each%20Sync.))
198+ if ( this . eqpErrored ) {
199+ continue ;
200+ }
201+ if ( this . isExtendedQuery && message [ 0 ] === BackendMessageCode . ErrorMessage ) {
202+ this . eqpErrored = true ;
197203 }
198204 // Filter out incorrect `ReadyForQuery` messages during the extended query protocol
199205 if ( this . isExtendedQuery && message [ 0 ] === BackendMessageCode . ReadyForQuery ) {
0 commit comments