Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow StringCodec registration for CITEXT usage #551

Closed
tobq opened this issue Sep 20, 2022 · 6 comments
Closed

Allow StringCodec registration for CITEXT usage #551

tobq opened this issue Sep 20, 2022 · 6 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@tobq
Copy link

tobq commented Sep 20, 2022

Bug Report

select 'text'::citext = :param fails when :param is set to (String) "TEST".

This seems to be an issue with the driver explicitly setting the type of the string parameter - as noted here: https://stackoverflow.com/a/23721681/7759514

For hibernate, this can be fixed using the properties: spring.datasource.hikari.data-source-properties.stringtype=unspecified / spring.datasource.tomcat.connection-properties.stringtype=unspecified
However these properties seem to have no effect with r2dbc

Versions

  • Driver: 0.8.10.RELEASE
  • Database: postgres 14
  • Java: 17
@tobq tobq added the status: waiting-for-triage An issue we've not yet triaged label Sep 20, 2022
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 20, 2022
@mp911de
Copy link
Collaborator

mp911de commented Sep 20, 2022

Leaving https://github.com/pgjdbc/pgjdbc/blob/5c78edb1412467636f996416ad37118f651db86e/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java#L253-L255 here as reference.

Can you upgrade to at least 0.9.2.RELEASE and bind the parameter value using Parameters.in(PostgresqlObjectId.UNSPECIFIED, "…")? Alternatively, rewrite the SQL to apply parameter casting to ::citext.

It would make sense to use the same binding customization mechanism as in pgjdbc.

@tobq
Copy link
Author

tobq commented Sep 20, 2022

I had already tried select 'text'::citext = :param::citext - I'll try Parameters.in(PostgresqlObjectId.UNSPECIFIED, "…")

@tobq
Copy link
Author

tobq commented Sep 20, 2022

@mp911de 0.9.2 doesn't seem to exist - the latest on maven is 0.8.13
https://search.maven.org/search?q=a:r2dbc-postgresql

@mp911de
Copy link
Collaborator

mp911de commented Sep 20, 2022

We switched to a different group Id, org.postgresql, see https://search.maven.org/artifact/org.postgresql/r2dbc-postgresql

@tobq
Copy link
Author

tobq commented Sep 20, 2022

@mp911de for query.bind("param", Parameters.in(PostgresqlObjectId.UNSPECIFIED, param)) I get Cannot encode parameter of type io.r2dbc.spi.Parameters$InParameter

@mp911de
Copy link
Collaborator

mp911de commented Sep 21, 2022

I'm not able to reproduce the issue that you've reported.

Here's my reproducer code that shows what currently works and what not:

SERVER.getJdbcOperations().execute("CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public");

SERVER.getJdbcOperations().execute("DROP TABLE IF EXISTS test");
SERVER.getJdbcOperations().execute("CREATE TABLE test ( ci CITEXT, cs VARCHAR )");

this.connection.createStatement("INSERT INTO test VALUES($1, $1)").bind("$1", "HeLlO")
    .execute()
    .flatMap(PostgresqlResult::getRowsUpdated)
    .as(StepVerifier::create)
    .expectNext(1)
    .verifyComplete();

this.connection.createStatement("SELECT ci FROM test WHERE ci = $1::citext")
    .bind("$1", "Hello")
    .execute()
    .flatMap(it -> it.map(r -> r.get("ci")))
    .as(StepVerifier::create)
    .expectNext("HeLlO")
    .verifyComplete();

this.connection.createStatement("SELECT ci FROM test WHERE ci = $1")
    .bind("$1", Parameters.in(PostgresqlObjectId.UNSPECIFIED, "Hello"))
    .execute()
    .flatMap(it -> it.map(r -> r.get("ci")))
    .as(StepVerifier::create)
    .expectNext("HeLlO")
    .verifyComplete();

// CITEXT comparison against UNSPECIFIED works
this.connection.createStatement("SELECT cs::citext = $1 FROM test")
    .bind("$1", Parameters.in(PostgresqlObjectId.UNSPECIFIED, "Hello"))
    .execute()
    .flatMap(it -> it.map(r -> r.get(0)))
    .as(StepVerifier::create)
    .expectNext(true)
    .verifyComplete();

// CITEXT != VARCHAR
this.connection.createStatement("SELECT cs::citext = $1 FROM test")
    .bind("$1", "Hello")
    .execute()
    .flatMap(it -> it.map(r -> r.get(0)))
    .as(StepVerifier::create)
    .expectNext(false)
    .verifyComplete();

@mp911de mp911de added this to the 0.9.3.RELEASE milestone Sep 21, 2022
mp911de added a commit that referenced this issue Sep 21, 2022
We now allow registration of the StringCodec for CITEXT usage through the UNSPECIFIED OID.

[resolves #551]

Signed-off-by: Mark Paluch <mpaluch@vmware.com>
mp911de added a commit that referenced this issue Sep 21, 2022
[#551]

Signed-off-by: Mark Paluch <mpaluch@vmware.com>
mp911de added a commit that referenced this issue Sep 21, 2022
[#551]

Signed-off-by: Mark Paluch <mpaluch@vmware.com>
@mp911de mp911de changed the title CITEXT equality failing Allow StringCodec registration for CITEXT usage Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants