Skip to content

config.show_chart = true fails with postgres #42

Description

@davidtolsma

PG::UndefinedFunction: ERROR: function unix_timestamp(timestamp without time zone) does not exist
SELECT FLOOR((UNIX_TIMESTAMP(created_at) - 1783457675) / 3600) ..

UNIX_TIMESTAMP(created_at)
What UNIX_TIMESTAMP() Does (MySQL)
In MySQL, UNIX_TIMESTAMP() converts a DATETIME or TIMESTAMP column into a Unix timestamp (number of seconds since 1970-01-01 00:00:00 UTC).
Example in MySQL:
SQLSELECT UNIX_TIMESTAMP(created_at) FROM jobs;
-- Returns something like: 1720458000
This is very commonly used for time-based calculations and bucketing (e.g., grouping records by hour or day).
Why It Fails in PostgreSQL
PostgreSQL does not have a function called UNIX_TIMESTAMP().
When solid_queue_monitor runs this query on your production PostgreSQL database:
SQLSELECT FLOOR((UNIX_TIMESTAMP(created_at) - 1783457675) / 3600) ...
PostgreSQL throws:
PG::UndefinedFunction: ERROR: function unix_timestamp(timestamp without time zone) does not exist
Correct Equivalent in PostgreSQL
In PostgreSQL, the proper way to get a Unix timestamp is:
SQLEXTRACT(EPOCH FROM created_at)
So the equivalent of the failing query would be:
SQL-- MySQL (broken on Postgres)
FLOOR((UNIX_TIMESTAMP(created_at) - 1783457675) / 3600)

-- PostgreSQL (correct)
FLOOR((EXTRACT(EPOCH FROM created_at) - 1783457675) / 3600)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions