Skip to content

time(n) with time zone is parsed as timestamp(n) with time zone #178

Open

Description

@trackoor

Parsing a time(n) with time zone (or time(n) without time zone) data type produces timestamp with time zone (or timestamp without time zone) in the AST instead of time with time zone / time without time zone. Without the precision modifier, time with time zone is parsed as expected.

const { parse, toSql } = require('pgsql-ast-parser');
const ast = parse('CREATE TABLE t (a time(2) with time zone, b time with time zone, c time(2))')[0];
console.log(JSON.stringify(ast.columns.map(c => c.dataType)));
console.log(toSql.statement(ast));
console.log(toSql.statement(parse('SELECT now()::time(0) with time zone')[0]));

Run with node repro.js:

Actual output:

[{"name":"timestamp with time zone","config":[2]},{"name":"time with time zone"},{"name":"time","config":[2]}]
CREATE TABLE t  (a timestamp(2) with time zone  , b time with time zone  , c time (2) )
SELECT ((now () )::timestamp(0) with time zone )

Expected output:
Column a should have dataType {"name":"time with time zone","config":[2]} and re-emit as time(2) with time zone (see https://www.postgresql.org/docs/current/datatype-datetime.html).

In src/syntax/base.ne, the data_type_date rule matches (%word {% anyKw('timestamp', 'time') %}) with precision (lparen int rparen) but hardcodes name: `timestamp ${toStr(x[2])} time zone` instead of using the matched keyword x[0].

Tested on pgsql-ast-parser 12.0.2 (latest npm release, matching master 69245d7), Node.js v26.13.0.

Credit: https://ucsbplse.github.io/

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