Skip to content

Conversation

@elexisvenator
Copy link
Contributor

@elexisvenator elexisvenator commented Mar 5, 2025

This is one of the things I found while putting this test app together.

There is hardcoded magic to make array types work correctly as duplicate fields and indexes. But that doesnt apply to other collection types like lists.

A table with a list type as follows:

public class DocWithIndexOnList
{
    public Guid Id { get; set; }

    [DuplicateField(DbType = NpgsqlDbType.Array | NpgsqlDbType.Text, PgType = "text[]", IndexMethod = IndexMethod.gin)]
    public List<string> ListOfStrings { get; set; }
}

Will generate invalid code:

public override void ConfigureParameters(IGroupedParameterBuilder parameterBuilder, ICommandBuilder builder, DocWithIndexOnList document, IMartenSession session)
{
    builder.Append("select bugs.mt_upsert_bug_pr_xxxx_list_index_compile_error_docwithindexonlist(");

    if (document.ListOfStrings != null)
    {
        var parameter0 = parameterBuilder.AppendParameter(document.ListOfStrings);
        parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.-2147483629;

Arrays in NpgsqlDbType are a dirty hack on enums, so the best way to fix this issue is to always cast the integer to the enum.

The one thing this leaves is the magic handling of array types - its kindof ok but it will override a manually set dbType, that part doesn't feel right.

@elexisvenator
Copy link
Contributor Author

Not sure if related, but we are also having issues with the following duplicate field declaration:

[DuplicateField(IndexMethod = IndexMethod.gin)]
public string[] ChildReferenceFormIds { get; init; } 

The error we are getting is Npgsql.PostgresException: '42804: binary data has array element type 25 (text) instead of expected 1043 (character varying)', which I think is happening on either storing documents or querying documents (likely storing)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant