h2database / h2database/h2database

TO_TIMESTAMP in Postgresql dialect differs from definition

Open
#3,560 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.6k
Forks
1.3k
Avg merge
1d 2h
Merged PRs (30d)
9

Description

I have written a nice query in Postgresql that converts a number of seconds into a timestamp with timezone, for example something like this:

SELECT TO_TIMESTAMP(1284352323);

This should result in a value of 2010-09-13 04:32:03+00.

Unfortunately the definition within the Postgresql Dialect, here h2/src/main/org/h2/mode/FunctionsPostgreSQL.java, expects 2 parameters, and will convert the (optional) first using the format specified in the second parameter to parse it.

I can't find any documentation on the Postgresql site, where the TO_TIMESTAMP function ever worked that way. Do enlighten me if I have missed that.

This is what I can find on https://www.postgresql.org/docs/14/functions-datetime.html:

 to_timestamp ( double precision ) → timestamp with time zone
Convert Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp with time zone
to_timestamp(1284352323) → 2010-09-13 04:32:03+00

Should I look at making a PR for this change?

Cheers,
Bas de Wit

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect h2/src/main/org/h2/mode/FunctionsPostgreSQL.java and the TO_TIMESTAMP handling first. Verify the PostgreSQL one-argument Unix-epoch behavior with the query shown; done means the dialect accepts that form and returns the documented timestamp-with-time-zone result.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, postgresql
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.