Skip to content

Question about GUID and isIn #113

Description

@hkirk

Thanks for the project, seems really nice. Was fidling around yesterday with the isIn and the Guid data type.

So having two tables with a relationship between them

CREATE TABLE Groups (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    group_no SMALLINT,
    semester VARCHAR(5) NOT NULL,
    pattern UUID
);
CREATE TABLE Students (
    id UUID PRIMARY KEY,  
    fullname VARCHAR(100),
    auid VARCHAR(10),
    group_id UUID,
    CONSTRAINT fk_group
      FOREIGN KEY(group_id)
          REFERENCES Groups(id)
);

Trying to select all students that are in a list of groups like

let groupIds: Guid list = groups |> Seq.map _.id |> Seq.toList 

// Get all students for these groups
let! students = 
    select {
        for s in studentsTable do
        where (isIn s.group_id groupIds)
    }
    |> conn.SelectAsync<Models.Student> |> Async.AwaitTask

This compiles and seems like it should work, you have a test case (

) here that looks much like what im trying to get to work.

But when using this with PostgresSQL it throws an execption

api-1         | info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
api-1         |       Request starting HTTP/1.1 GET http://api:5100/api/pattern/available - - -
api-1         | Generated SQL: DELETE FROM "students" WHERE "students"."group_id" <> ALL (@Where_students_group_id1) ---- map [(Where_students_group_id1, System.Object[])]
api-1         | fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
api-1         |       An unhandled exception has occurred while executing the request.
api-1         |       System.AggregateException: One or more errors occurred. (Writing values of 'System.Object[]' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..)
api-1         |        ---> System.InvalidCastException: Writing values of 'System.Object[]' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..
api-1         |          at Npgsql.Internal.AdoSerializerHelpers.<GetTypeInfoForWriting>g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable`1 pgTypeId, Nullable`1 npgsqlDbType, Exception inner)
api-1         |          at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable`1 pgTypeId, PgSerializerOptions options, Nullable`1 npgsqlDbType)
api-1         |          at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options, IDbTypeResolver dbTypeResolver)
api-1         |          at Npgsql.NpgsqlParameterCollection.ProcessParameters(ReloadableState reloadableState, Boolean validateValues, CommandType commandType)
api-1         |          at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
api-1         |          at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
api-1         |          at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
api-1         |          at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 434

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions