Skip to content

NpgsqlTsQueryEmpty cannot roundtrip to C# #886

Closed as not planned
Closed as not planned

Description

@ljani

The following SQL clause works in PostgreSQL:

select ts_rank(to_tsvector('test'), plainto_tsquery(''));

And this works with npgsql:

    .Select(x => new
        {
            Rank = x.TsVector.RankCoverDensity(EF.Functions.PlainToTsQuery(""))
        })

However, if I try to run the following expression with npgsql, it seems to fail:

var empty = new NpgsqlTsQueryEmpty();

...

    .Select(x => new
        {
            Rank = x.TsVector.RankCoverDensity(empty)
        })

Is this a supported scenario?

Here's the exception:

Npgsql.PostgresException (0x80004005): XX000: malformed tsquery: operand not found
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 1032
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming) in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 445
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1215
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)

Activity

  1. austindrenski commented on May 17, 2019

    @austindrenski
    Contributor

    @ljani Thanks for reporting this. I'm able to reproduce this (and a related bug) in our test suite. Looking into a patch shortly.

  2. added this to the 2.2.3 milestone on May 17, 2019
  3. austindrenski commented on May 17, 2019

    @austindrenski
    Contributor

    Actually, this is reproducible with the ADO.NET driver:

    using var conn = context.Database.GetDbConnection();
    using var cmd = (NpgsqlCommand)conn.CreateCommand();
    
    cmd.CommandText = "SELECT ts_rank_cd(to_tsvector('a b c'), @p0)";
    cmd.Parameters.AddWithValue("p0", NpgsqlDbType.TsQuery, new NpgsqlTsQueryEmpty());
    cmd.ExecuteScalar();

    Though, even if that worked, it appears that this would still fail due to missing entries for NpgsqlTsQuery{Empty,And,...} in NpgsqlTypeMappingSource:

    https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/d86bd4eff553d9a65713d8a1d2e84a41791f5a8b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs#L238-L242

    Reproduced in austindrenski/Npgsql.EntityFrameworkCore.PostgreSQL/tree/issue-886.

    /cc @roji @rwasef1830

  4. ljani commented on May 17, 2019

    @ljani
    Author

    Thanks for looking into this. One request though: maybe release 2.2.3 soon? 😄

  5. modified the milestones: 2.2.4, on May 21, 2019
  6. removed this from the milestone on Sep 16, 2022
  7. added this to the Backlog milestone on Mar 9, 2023
  8. added theissue type on Jun 14, 2025
  9. assigned and unassigned on Oct 20, 2026
  10. roji commented on Oct 22, 2026

    @roji
    Member

    This actually seems to be a PostgreSQL bug; filed this as https://www.postgresql.org/message-id/flat/19778-1befc1fba593ab1b%40postgresql.org with a C libpq-only repro. Closing here.

  11. removed this from the Backlog milestone on Oct 22, 2026
  12. removed theissue type on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions