Skip to content

Fix grouping of datetime cast timezone suffixes - #912

Open
SAY-5 wants to merge 1 commit into
andialbrecht:masterfrom
SAY-5:say5/fix-datetime-cast-timezone-20260928
Open

SAY-5 wants to merge 1 commit into
andialbrecht:masterfrom
SAY-5:say5/fix-datetime-cast-timezone-20260928

Conversation

@SAY-5

@SAY-5 SAY-5 commented Sep 29, 2026

Copy link
Copy Markdown

Fixes #811.

SELECT '2020-01-01'::timestamp WITH TIME ZONE AS moment, ARRAY(SELECT 1) AS items; currently leaves the timezone suffix outside the cast. The SELECT list then starts at the alias, and reindent places ARRAY 49 spaces from the left edge instead of 7.

Extend :: casts of TIME/TIMESTAMP, including optional precision, through a complete WITH/WITHOUT TIME ZONE suffix. Preserve the original tokens and keep unaliased casts from reporting the operand or type name as an alias. The regression tests cover formatting, comments, explicit and implicit aliases, chained casts, custom types, CTEs, and subsequent AT TIME ZONE conversion.

This change is limited to PostgreSQL-style :: casts. It does not change CAST expressions, typed literals, or AT TIME ZONE tokenization.

Validation on macOS with Python 3.13.0: 570 passed, 2 xfailed, 1 xpassed; Ruff passed. The 64 focused cases produce 45 failures and 19 passes on untouched master, then all pass with the fix. The grouping benchmark and bounded datetime-cast parsing/formatting benchmarks report linear scaling. Other Python versions and platforms were not run locally.

This change was developed with AI assistance.

Thanks for contributing!

Before submitting your pull request please have a look at the
following checklist:

  • ran the tests (pytest)
  • all style issues addressed (ruff)
  • your changes are covered by tests
  • your changes are documented, if needed

In addition, please take care to provide a proper description
on what your change does, fixes or achieves when submitting the
pull request.


Note: This repository has automated AI code reviews enabled to help catch
potential issues early and provide suggestions. This is an experimental
feature to support maintainers and contributors – your feedback is welcome!

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.

Indentation problems with ARRAY clause after ::timestamp WITH TIMEZONE AS

1 participant