Skip to content

Conversation

@jeremylevy
Copy link
Contributor

Hello,

When running the SQL query included in the getTime() function on PostgreSQL 13.18, I got the following result:

date_part
1755534822.917985

This causes the function to return NaN since the extract property does not exist.

When the getTime function returns NaN, both the incremental and full cleanup operations remove all added documents, rendering the indexing feature unusable:

{ numAdded: 1, numDeleted: 1, numUpdated: 0, numSkipped: 0 }

This PR fixes the issue by always adding an alias using the AS SQL keyword.

@vercel
Copy link

vercel bot commented Aug 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
langchainjs-docs Ready Ready Preview Comment Sep 1, 2025 6:11am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchainjs-api-refs Ignored Ignored Sep 1, 2025 6:11am

@hntrl
Copy link
Member

hntrl commented Aug 18, 2025

@jeremylevy thanks for the PR!

Is this a regression between postgres versions? (i.e. was there once an additional extract property that came back from that query?) If so I think we'd want to have guards that cover both cases.

@jeremylevy
Copy link
Contributor Author

Hey @hntrl,

The query always returns only one property, but it was rewritten to date_part in older versions of PostgreSQL. See, for example:
https://stackoverflow.com/questions/38442340/difference-between-extractyear-from-timestamp-function-and-date-partyear-t

This behavior changed in PostgreSQL 14: http://postgresql.org/docs/release/14.0/

Change EXTRACT() to return type numeric instead of float8 (Peter Eisentraut)
This avoids loss-of-precision issues in some usages. The old behavior can still be obtained by using the old underlying function date_part().
Also, EXTRACT(date) now throws an error for units that are not part of the date data type.

When running the same query on PostgreSQL 14, it returns the expected extract property name:

      extract      
-------------------
 1755551254.164705
(1 row)

Adding an alias does not change this behavior:

SELECT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) AS extract;
      extract      
-------------------
 1755551254.164705
(1 row)

@hntrl hntrl merged commit 7bcc76d into langchain-ai:main Sep 1, 2025
32 checks passed
hntrl added a commit that referenced this pull request Oct 14, 2025
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.

2 participants