Skip to content

Postgres-nio date handling with Swift does not appear to work as one would expect #514

Open
@duncangroenewald

Description

@duncangroenewald

Describe the issue

When fetching a date value from a database table and then using that same value to find the record containing that value the query fails to fid a matching record

Vapor version

N/A

Operating system and version

macOS 14

Swift version

Swift 5.10.0-dev

Steps to reproduce

Create a Postgres table with records having a date field e.g. "startDate"

Query the database using PostgresClient and save the value into a Swift Date variable.

Now run a query to fetch the records with "statDate" field equals the date just retrieved.

This appears to fail - perhaps because the Swift internal format is different to the Postgres format.

Outcome

If I cast the input value using to_date(value, 'yyyy-mm-dd') e.g.

SELECT * FROM DATETABLE
WHERE startDate=to_date(value, 'yyyy-mm-dd')

then it seems to work.

I would have expected that Postgres-nio would correctly handle the necessary conversion when constructing the SQL statements.

Additional notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions