© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
2 replies
Lloyd

Postgres.js type error string/date

I'm running the following where clause in a select query:

.where(
  and(
    gt(
      sql`${e.originalStartTime} + (${p.endTime} - ${p.startTime})::interval`, 
      ${endingAfter},
    ),
    lt(e.originalStartTime, ${startingBefore),
  ),
)
.where(
  and(
    gt(
      sql`${e.originalStartTime} + (${p.endTime} - ${p.startTime})::interval`, 
      ${endingAfter},
    ),
    lt(e.originalStartTime, ${startingBefore),
  ),
)


When printing out the query with parameters, the value for endingAfter is a Date, and has not been turned into a string:

[
   2024-01-01T00:00:00Z // endingAfter
   '2024-12-31T00:00:00Z' // startingBefore works fine
]
[
   2024-01-01T00:00:00Z // endingAfter
   '2024-12-31T00:00:00Z' // startingBefore works fine
]

...with the error:
The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date
The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date


This works fine when I perform
.toISOString()
.toISOString()
on
endingAfter
endingAfter
, but it doesn't seem to do that automatically in this case, I assume because it doesn't have the column information because the first arguments is an
SQL<unknown>.
SQL<unknown>.
I've tried various things to get this right; using a type parameter for the sql, using
.mapWith()
.mapWith()
with a timestamp column, but haven't managed to come up with the correct magic.

I've noted the postgres-js breaking changes in 0.3 around strings/Dates, which is why I have just used .toISOString() for now, but this feels like it should work because it works in the other examples where there is column information present

Thanks!
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

daterange postgres column type handled as unknown
Drizzle TeamDTDrizzle Team / help
2y ago
How to use custom date (1082) type parser in postgres.js for >0.30.0?
Drizzle TeamDTDrizzle Team / help
2y ago
Changing postgres timestamp mode (string -> date) isn't reflected in migrations
Drizzle TeamDTDrizzle Team / help
13mo ago
Timestamp from Postgres returns date object despite schema using string mode?
Drizzle TeamDTDrizzle Team / help
3y ago