Open
Description
Hello!
I was in the process of migrating a project using postgres
v2. One thing we are doing in this project to improve the performance of batch uploads to Postgres is to run multiple INSERT statements in the same execute
and it has been working great for us.
The problem we are seeing is that in v3 it throws with an error: Severity.error 42601: cannot insert multiple commands into a prepared statement
Are we missing some special configuration to support this?
Sample code:
Version 2.x
import 'package:postgres/postgres.dart';
void main(List<String> args) async {
final connection = PostgreSQLConnection(...);
await connection.open();
await connection.execute('''
CREATE TEMP TABLE todos (
id INTEGER PRIMARY KEY,
description TEXT NOT NULL
)
''');
await connection.execute(
'''
INSERT INTO todos (id, description) VALUES (@id_1, @description_1);
INSERT INTO todos (id, description) VALUES (@id_2, @description_2);
INSERT INTO todos (id, description) VALUES (@id_3, @description_3);
''',
substitutionValues: {
'id_1': 1,
'description_1': 'Buy milk',
'id_2': 2,
'description_2': 'Buy eggs',
'id_3': 3,
'description_3': 'Buy bread',
},
);
final result = await connection.query('SELECT * FROM todos');
for (final row in result) {
print('id: ${row[0]}, description: ${row[1]}');
}
await connection.close();
}
Version 3.x
import 'package:postgres/postgres.dart';
void main(List<String> args) async {
final connection = await Connection.open(
Endpoint(
...
),
);
await connection.execute('''
CREATE TEMP TABLE todos (
id INTEGER PRIMARY KEY,
description TEXT NOT NULL
)
''');
await connection.execute(
Sql.named('''
INSERT INTO todos (id, description) VALUES (@id_1, @description_1);
INSERT INTO todos (id, description) VALUES (@id_2, @description_2);
INSERT INTO todos (id, description) VALUES (@id_3, @description_3);
'''),
parameters: {
'id_1': 1,
'description_1': 'Buy milk',
'id_2': 2,
'description_2': 'Buy eggs',
'id_3': 3,
'description_3': 'Buy bread',
},
);
final result = await connection.execute('SELECT * FROM todos');
for (final row in result) {
print('id: ${row[0]}, description: ${row[1]}');
}
await connection.close();
}
Metadata
Metadata
Assignees
Labels
No labels