vertical-blank / sql-formatter

SQL formatter written with only Java Standard Library, without dependencies.
MIT License
227 stars 47 forks source link

Add @@SESSION as reserved word for MySQL #59

Closed zendesk-jjtheo closed 2 years ago

zendesk-jjtheo commented 2 years ago

@@SESSION is a reserved word in MySQL. https://dev.mysql.com/doc/refman/8.0/en/session-state-tracking.html The formatter is currently adding a space after the first @ as it's considering it as a special word char.

Maybe a same fix as #42 would work? although it's not an operator in MySQL

vertical-blank commented 2 years ago

@zendesk-jjtheo As a workaround, try this.

String sql = SqlFormatter.extend(cfg -> cfg.plusReservedWords("@@SESSION"))
            .format("SET @@SESSION.session_track_transaction_info='CHARACTERISTICS';");
System.out.println(sql);

output:

SET
  @@SESSION.session_track_transaction_info = 'CHARACTERISTICS';
zendesk-jjtheo commented 2 years ago

@vertical-blank Thank you!