Skip to content

CAST to timestamp works in Postgres but breaks in Cube when the timestamp has a UTC offset without minutes #10405

@rolodato

Description

@rolodato

Describe the bug

The following query breaks in Cube's Postgres SQL API, but works in regular Postgres:

SELECT CAST('2026-01-26 00:00:00+00' AS timestamp)

returns:

[XX000] ERROR: Post-processing Error: Cast error: Error parsing '2026-01-26 00:00:00+00' as timestamp

This only happens when the UTC offset in the timestamp only has hours and not minutes. For example, these do work in both Cube and Postgres:

SELECT CAST('2026-01-26 00:00:00+0000' AS timestamp)
SELECT CAST('2026-01-26 00:00:00+00:00' AS timestamp)

This is possibly happening because Cube interprets this timestamp as RFC 3339, which does require 4 digits for the UTC offset: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6

In contrast, Postgres uses ISO 8601 and other formats which do admit a UTC offset having only hours.

To Reproduce

  1. Run Cube with the Postgres-compatible API, using e.g. a Docker Compose file like so:
services:
  cube_api:
    restart: always
    image: cubejs/cube:latest
    environment:
      - CUBEJS_DB_TYPE=postgres
      - CUBEJS_API_SECRET=secret
      - CUBEJS_PG_SQL_PORT=15432
      - CUBEJS_SQL_USER=cube
      - CUBEJS_SQL_PASSWORD=secret
  1. Connect to Cube using any Postgres client
  2. Run this query: SELECT CAST('2026-01-26 00:00:00+00' AS timestamp)

Expected behavior

Return the same result as regular Postgres: 2026-01-26 00:00:00.000000

Screenshots

N/A

Minimally reproducible Cube Schema

N/A

Version:

Tested on Cube API version 1.6.3.

Additional context

Metabase generates queries in this format when connecting to Cube as a Postgres data source. This can break queries created using the GUI query builder. The only workaround is to rewrite the query using SQL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:sqlIssues related to SQL API

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions