Skip to content

Fix null named parameters in raw SQL queries (GH-3045)#4127

Merged
jeremydmiller merged 1 commit intomasterfrom
GH3045
Feb 11, 2026
Merged

Fix null named parameters in raw SQL queries (GH-3045)#4127
jeremydmiller merged 1 commit intomasterfrom
GH3045

Conversation

@jeremydmiller
Copy link
Member

Summary

  • Fixes Marten 7 Command Failure: 42P08: could not determine data type of parameter $1 #3045 — using named parameters with null values in QueryAsync/AdvancedSqlAsync caused PostgreSQL error 42P08: could not determine data type of parameter
  • Root cause: when an anonymous object property has a null value, NpgsqlDbType was never set on the parameter, so PostgreSQL couldn't infer the type
  • New NamedParameterHelper converts :paramName references to positional $N parameters with NpgsqlDbType inferred from the property's declared type (handling Nullable<T> via GetUnderlyingType)

Test plan

  • New test query_with_null_named_parameter_GH_3045 covers the exact reported scenario (:param is null or ... pattern)
  • Existing named parameter tests (query_by_one_named_parameter, query_by_two_named_parameters, query_two_fields_by_one_named_parameter) still pass
  • Handles edge cases: :: type casts, single-quoted strings, unknown parameter names

🤖 Generated with Claude Code

When using anonymous objects for named parameters in QueryAsync/AdvancedSqlAsync,
null values caused PostgreSQL error 42P08 because NpgsqlDbType was not set.
New NamedParameterHelper converts :paramName references to positional parameters
with proper NpgsqlDbType inferred from the property's declared type.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Marten 7 Command Failure: 42P08: could not determine data type of parameter $1

1 participant