Skip to content

Conversation

@marshall-lerner
Copy link

@marshall-lerner marshall-lerner commented Feb 2, 2026

Why make this change?

This PR is to address #3094, which is a bug that happens because the default type conversion for C# to Npgsql is to convert a string to a TEXT field, but this doesn't work when trying to compare a DATE type for PostgreSql databases.

What is this change?

  • My change passes the column name of the Postgres column attempting to be filtered through to the filtering context, and then we override PopulateDbTypeForParameter to pass the DBType value through to Npgsql, much like how this is done for MsSql. This hopefully means that Npgsql knows to convert the C# string into something that works with the DATE (and every other) column type.

How was this tested?

(Currently untested)

  • Integration Tests
  • Unit Tests

Sample Request(s)

  • Example REST and/or GraphQL request to demonstrate modifications
  • Example of CLI usage to demonstrate modifications

With query:

query {
  todos(filter: { dueDate: { gte: "2024-01-01T00:00:00.000Z" } }) {
    items {
      dueDate
    }
  }
}

Before:

SELECT * FROM public."Todos"
WHERE "Todos"."dueDate" >= '2025-01-01T00:00:00Z'::text;

(Hopefully After):

SELECT * FROM public."Todos"
WHERE "Todos"."dueDate" >= '2025-01-01T00:00:00Z';

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request attempts to fix issue #3094 where PostgreSQL date filters fail with "operator does not exist: date >= text" errors. The PR tries to pass column names through the filtering pipeline to enable proper type conversion for PostgreSQL parameters, similar to the existing MsSQL implementation.

Changes:

  • Modified GraphQL filter parsing to pass column names through to the parameter creation logic
  • Added a PopulateDbTypeForParameter method to PostgreSqlExecutor (incomplete implementation)
  • Updated documentation comments to reflect PostgreSQL support

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Core/Models/GraphQLFilterParsers.cs Adds columnName parameter to GenerateRightOperand and passes it through to processLiterals for proper type resolution
src/Core/Resolvers/PostgreSqlExecutor.cs Adds static PopulateDbTypeForParameter method, but implementation is incomplete and non-functional
src/Core/Resolvers/IQueryExecutor.cs Updates documentation to indicate PostgreSQL support
src/Core/Resolvers/QueryExecutor.cs Updates documentation to indicate PostgreSQL support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@marshall-lerner
Copy link
Author

@copilot, please rereview the PR

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@JerryNixon
Copy link
Contributor

Recommendations

  1. Fix the method signature:
// Change from static to override
public override void PopulateDbTypeForParameter(KeyValuePair<string, DbConnectionParam> parameterEntry, DbParameter parameter)
{
    if (parameterEntry.Value is not null && parameterEntry.Value.DbType is not null)
    {
        parameter.DbType = (DbType)parameterEntry.Value.DbType;
    }
}
  1. Verify PrepareDbCommand calls it: Ensure your PrepareDbCommand override in PostgreSqlExecutor properly calls PopulateDbTypeForParameter for each parameter.

  2. Update comments only after testing: The comments in IQueryExecutor.cs and QueryExecutor.cs should only mention PostgreSQL once the implementation is confirmed working.

  3. Add tests: This PR needs integration tests to validate:

    • DATE type filtering works
    • TIMESTAMP filtering works
    • Other type conversions aren't broken
  4. Testing checklist: Update the PR description to check off the testing boxes once tests are added.

🔍 What to Test

Based on issue #3094, ensure these queries work:

query {
  todos(filter: { dueDate: { gte: "2024-01-01T00:00:00.000Z" } }) {
    items { dueDate }
  }
}

The generated SQL should not have ::text casting:

-- Should generate:
WHERE "Todos"."dueDate" >= $1  -- with DbType.Date

-- NOT:
WHERE "Todos"."dueDate" >= $1::text

Summary

This PR is on the right track but needs the method signature fix before it will work. The Copilot review caught a critical issue that must be addressed. Once fixed and tested, this should resolve the PostgreSQL date filtering problem.

@Alekhya-Polavarapu
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

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.

4 participants