Skip to content

format() emits CREATE OR REPLACE ROW POLICY, which ClickHouse rejects #38

Description

@vapongit

format() re-prints a parsed CREATE ROW POLICY OR REPLACE policy_name ... statement as CREATE OR REPLACE ROW POLICY policy_name ..., which the ClickHouse server rejects — the documented syntax only allows OR REPLACE after POLICY, never after CREATE.

Reproduction

const { parse, format } = require('@clickhouse/parser');

const sql = 'CREATE ROW POLICY OR REPLACE p ON db.table USING db.table.tenant_id = 1';

parse(sql)[0].or_replace; // true — parses correctly

format(parse(sql));
// => CREATE OR REPLACE ROW POLICY p ON db.table USING db.table.tenant_id = 1;
// invalid: https://clickhouse.com/docs/reference/statements/create/row-policy
// only accepts CREATE [ROW] POLICY [IF NOT EXISTS | OR REPLACE] policy_name ...

The parser also accepts that same invalid form as input, without error:

const bad = 'CREATE OR REPLACE ROW POLICY p ON db.table USING db.table.tenant_id = 1';

parse(bad)[0].or_replace; // true — accepted, though the server would reject this syntax

Suggested fixes

  1. Fix parser to accept OR REPLACE in correct position.
  2. Fix format() to emit OR REPLACE in the correct position.

Environment

@clickhouse/parser 0.3.0

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions