0
votes

I use the postgres library to work with the database. I have a very large database. I need to change the character in the column. I do it like this:

  void replace(String col, String from, String to) async {
    String queryStr = "UPDATE $tab SET $col = replace($col, '$from', '$to');";
    await connection.query(queryStr);
  }

If the database has more than 1,000,000 rows, I get an error:

Unhandled exception: TimeoutException after 0:00:30.000000: Future not completed 0 _PostgreSQLConnection&Object&_PostgreSQLExecutionContextMixin._enqueue (package:postgres/src/connection.dart:402:24) 1 _PostgreSQLConnection&Object&_PostgreSQLExecutionContextMixin.query (package:postgres/src/connection.dart:318:12) 2 PG.replace (file:///home/vas/IdeaProjects/infovizion_platform/pg/bin/pg.dart:50:22) 3 main (file:///home/vas/IdeaProjects/infovizion_platform/pg/bin/main.dart:81:14) 4 _startIsolate. (dart:isolate/runtime/libisolate_patch.dart:287:32) 5 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

When I do the same requests manually there is no error.

How can I fix this?

1
You have to increase or set the timeout - comrad
@comrad how to set the execution limit in dart? - VINET
Let you method return a Future. Future.timeout(new Duration(seconds: 100000),...); - comrad

1 Answers

0
votes

You might try this version:

UPDATE $tab
    SET $col = replace($col, '$from', '$to')
    WHERE $col LIKE '%' || '$from' || '%';

That is, only update columns where the value actually appears, instead of all column.

Reducing the number of columns that actually change may speed the query.