Skip to content

Conversation

ljluestc
Copy link

This PR resolves Issue #1149 by fixing the inability to insert or update TIMESTAMP values in immudb using PostgreSQL-compatible SQL syntax, which caused errors like org.postgresql.util.PSQLException: ERROR: value is not a timestamp. The issue stemmed from immudb’s SQL engine not handling PostgreSQL timestamp formats (e.g., YYYY-MM-DD HH:MM:SS) or implicit casts, unlike PostgreSQL. The fix enhances the SQL engine and JDBC driver integration to support PostgreSQL-compatible timestamp formats, CURRENT_TIMESTAMP, and epoch milliseconds.

Key changes:

  • Updated pkg/database/sql.go to parse PostgreSQL timestamp formats (YYYY-MM-DD HH:MM:SS, ISO 8601, epoch milliseconds) in ParseSQLValue.
  • Added support for CURRENT_TIMESTAMP and NOW() in SQL statements.
  • Modified pkg/client/jdbc/immudb_driver.go to handle time.Time parameters in JDBC, converting to YYYY-MM-DD HH:MM:SS.
  • Added tests in pkg/database/sql_test.go and pkg/client/jdbc/immudb4j_test.go to verify timestamp insertion and querying.
  • Addressed write: broken pipe errors by ensuring robust parameter handling.

What are the main choices made to get to this solution?

  • Timestamp Parsing: Implemented multiple format parsing (YYYY-MM-DD HH:MM:SS, ISO 8601, epoch) to align with PostgreSQL’s flexibility [].
  • JDBC Integration: Converted time.Time to string format in the JDBC driver to ensure compatibility with immudb’s SQL engine [].
  • CURRENT_TIMESTAMP Support: Replaced CURRENT_TIMESTAMP and NOW() with formatted timestamps to simplify SQL processing.
  • Error Handling: Added detailed error messages for invalid timestamps to improve debugging [].
  • Minimal Changes: Focused on SQL engine and JDBC driver, avoiding changes to core storage to maintain stability.

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.

Update/Insert Timestamp doesn't work with PostgreSQL SQL syntax.
1 participant