NpgsqlTsQueryEmpty cannot roundtrip to C#
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)
@ljani Thanks for reporting this. I'm able to reproduce this (and a related bug) in our test suite. Looking into a patch shortly.
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
Thanks for looking into this. One request though: maybe release 2.2.3 soon? 😄