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
- Fix parser to accept
OR REPLACE in correct position.
- Fix
format() to emit OR REPLACE in the correct position.
Environment
@clickhouse/parser 0.3.0
format()re-prints a parsedCREATE ROW POLICY OR REPLACE policy_name ...statement asCREATE OR REPLACE ROW POLICY policy_name ..., which the ClickHouse server rejects — the documented syntax only allowsOR REPLACEafterPOLICY, never afterCREATE.Reproduction
The parser also accepts that same invalid form as input, without error:
Suggested fixes
OR REPLACEin correct position.format()to emitOR REPLACEin the correct position.Environment
@clickhouse/parser0.3.0