Skip to content

fix(pretty-print): suppress child statement semicolons in CREATE SCHEMA - #803

Open
edjubert wants to merge 1 commit into
supabase-community:mainfrom
edjubert:edjubert/pretty-print-create-schema
Open

edjubert wants to merge 1 commit into
supabase-community:mainfrom
edjubert:edjubert/pretty-print-create-schema

Conversation

@edjubert

Copy link
Copy Markdown

What

CREATE SCHEMA takes a list of schema elements.
Per the grammar (OptSchemaEltList: OptSchemaEltList schema_stmt) they are space-separated and only the outer statement carries a terminator.
The emitter printed each child statement's own ;, producing invalid SQL:

-- input
CREATE SCHEMA s1 CREATE TABLE a (f1 int) CREATE TABLE b (f2 int);

-- before: does not parse
create schema s1 create table a (f1 int);create table b (f2 int);;

-- after
create schema s1 create table a (f1 int) create table b (f2 int);

Implementation

EventEmitter gains a no_semicolon flag that makes token() drop SEMICOLON; it is set while emitting schema_elts and cleared afterwards.
The separator before the element list becomes a soft line so the renderer can wrap when the schema name and the first element do not fit.

Tests

tests/create_schema_elts.rs round-trips a CREATE SCHEMA with two elements: format, reparse, normalize, compare ASTs.

CREATE SCHEMA takes a list of schema_elements that are space-separated
and must not carry their own terminating ';'. The emitter used to emit
each child statement's ';', producing invalid SQL such as
'create schema s1 create table a (f1 int);;' whenever the statement was
parsed as a whole.

Add a no_semicolon flag to EventEmitter and set it while emitting the
schema elements, plus a regression test that round-trips a CREATE SCHEMA
with two elements.
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.

1 participant