Search code examples
postgresqlr2dbcr2dbc-postgresql

How to get results of select query in postgresql r2dbc?


I can execute this query just fine but I don't know how to extract the information returned by the select statement.

Flux<PostgresqlResult> checkTableQuery = connectionMono.flatMapMany(connection -> connection
    .createStatement("select exists(\n" +
                " select table_name from information_schema.tables\n" +
                " where table_name='sequence1'\n" +
                ");")
        .execute());
checkTableQuery.subscribe();

Solution

  • Flux<PostgresqlResult> checkTableQuery = connectionMono.flatMapMany(connection -> connection
    .createStatement("select exists(\n" +
                " select table_name from information_schema.tables\n" +
                " where table_name='sequence1'\n" +
                ");")
        .execute())
    .flatmap(result -> result.map(
      (row,rowMetadata) -> row.get("exists",Boolean.class)));
    
    checkTableQuery.subscribe();