Repository navigation
Conversation
Since JSQLParser#2700, every PostgreSQL ALTER DATABASE fails to parse, while 5.4 returned an UnsupportedStatement. Model RENAME TO, OWNER TO, SET TABLESPACE, REFRESH COLLATION VERSION, the [WITH] options and SET/RESET of configuration parameters. Outside the MySQL dialect, other ALTER DATABASE forms are unsupported statements again, and ALTER SCHEMA with MySQL options no longer requires that dialect. Extract the SET/RESET state of AlterRole into ConfigurationParameterChange, which ALTER DATABASE shares; AlterRole keeps its accessors. Type each PostgreSQL CREATE DATABASE option, accept the CHAR SET and CHARSET spellings, keep CreateDatabase options in one list and drop the empty raw option that added a trailing space. Signed-off-by: minleejae <mmj9808@gmail.com>
This was referenced Oct 14, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fix a regression from #2700: every PostgreSQL
ALTER DATABASEnow throws aParseException, for exampleALTER DATABASE mydb OWNER TO apporALTER DATABASE mydb SET search_path TO app, public. JSqlParser 5.4 returned anUnsupportedStatementfor them. Without a dialect, MySQL'sALTER SCHEMA db DEFAULT ENCRYPTION = 'Y'regressed the same way.While here, give the database options the same typed treatment as the MySQL ones:
CREATE DATABASEoptions are one opaqueOTHERoption.CHARSETspelling is not recognized, andCREATE SCHEMA db DEFAULT CHARSET = utf8mb4fails.CREATE DATABASEends with an empty raw option, which adds a trailing space totoString().Current design (As-is)
Alter()sends everyALTER DATABASEtoAlterDatabase(), which accepts only MySQL options. Without the MySQL dialect,ALTER SCHEMAgoes to the PostgreSQLAlterSchema(), which accepts only RENAME and OWNER.AlterRolestores PostgreSQL'sSET/RESETof a configuration parameter in six fields: action, parameter, values,useEquals,fromCurrentanduseDefault.FROM CURRENTandDEFAULTcan both be set; rendering picks the first.CreateDatabasekeeps two representations: the option nodes, and a flat token list computed when the options are set.captureRest()always appends a raw option, even an empty one.Target design (To-be)
ConfigurationParameterChangeinnet.sf.jsqlparser.statementforSET p {TO|=} values|DEFAULT,SET p FROM CURRENTandRESET p|ALL:Action(SET,RESET), the parameter name,ValueKind(VALUES,DEFAULT,FROM_CURRENT),useEqualsand a mutableExpressionListof values;ALTER ROLEandALTER DATABASE;ALTER FUNCTION/PROCEDUREcan reuse both.AlterRolestores aConfigurationParameterChange. Its existing parameter getters and setters remain and read or edit that change.AlterDatabasegains anAction:OPTIONS(the default),RENAME,OWNER,SET_TABLESPACE,REFRESH_COLLATION_VERSIONandCONFIGURATION_PARAMETER, each with its own payload.OPTIONStakes PostgreSQL's[WITH] ALLOW_CONNECTIONS | CONNECTION LIMIT | IS_TEMPLATE ...as well as the MySQL options. PostgreSQL forms require a database name; MySQL options may still omit it.DatabaseOptiongets one kind per PostgreSQL option:OWNER,TEMPLATE,ENCODING,STRATEGY,LOCALE,LC_COLLATE,LC_CTYPE,BUILTIN_LOCALE,ICU_LOCALE,ICU_RULES,LOCALE_PROVIDER,COLLATION_VERSION,TABLESPACE,ALLOW_CONNECTIONS,CONNECTION_LIMIT,IS_TEMPLATEandOID. Values keep their SQL text.CREATE DATABASEandALTER DATABASEshare the production for these options.CHARACTER SET,CHAR SETandCHARSETare allCHARACTER_SET;getName()keeps the spelling. This also fixesCREATE SCHEMA ... DEFAULT CHARSET.CreateDatabasekeeps one live option list and anisUseWith()flag. Other option text remains one raw option, appended only if present.getDatabaseOptions()is derived from the options.Dialect.MYSQL,ALTER DATABASE/SCHEMAalways parses asAlterDatabase, as before.AlterDatabaseonly for forms it models. OtherALTER DATABASEforms, such as SQL Server'sSET RECOVERY SIMPLE, return toUnsupportedStatementas in 5.4.ALTER SCHEMAfollowed by MySQL options parses asAlterDatabasein every dialect. PostgreSQL'sALTER SCHEMA ... RENAME/OWNERremains anAlterSchema.StatementDeParser(SET values go through the expression deparser) and into validation:StatementValidatorchecks the newFeature.alterDatabase. The MySQL, MariaDB and PostgreSQL capabilities now enablecreateDatabaseandalterDatabase; no capability enabledcreateDatabasebefore. Document the API in the usage guide.Compatibility
AlterRolekeeps all public accessors, and its SQL output is unchanged.FROM CURRENTandDEFAULTare now mutually exclusive:setFromCurrent(false)andsetUseDefault(false)return to the explicit values.CreateDatabase.getOptions()is never null and returns the live list;setOptionscopies its argument.getDatabaseOptions()is now an unmodifiable snapshot that includesWITH, and still null without options. Previously, edits to it were silently ignored for parsed statements.addDatabaseOptionsnow appends a raw option instead of turning every option into raw tokens.Validation
Dialect.POSTGRESQL, withDialect.MYSQLand without a dialect, plus statement boundaries in scripts;CHARSETas an option keyword and as a database name;UnsupportedStatementwithout a dialect and with PostgreSQL, an error with MySQL; PostgreSQLALTER SCHEMAunchanged;AlterRoleandAlterDatabasesharing oneConfigurationParameterChange, and the legacyAlterRoleaccessors and setters;CreateDatabaselist ownership and the legacy token methods;spotlessApply check: 10,425 tests, 10,400 passed, 25 skipped, zero failures/errors. The grammar choice conflict check passes.master(bdf8ac31) on a corpus of 635 MySQL 8.4 and PostgreSQL 18 DDL/DCL statements, each accepted by the server, plus variants:Dialect.POSTGRESQLand without a dialect:ALTER DATABASE ... SET/RENAME TO/OWNER TO/RESET ALL/WITH ALLOW_CONNECTIONS,SET work_mem = '64MB'andOWNER TO CURRENT_USER.CREATE SCHEMA ... DEFAULT CHARSETand, without a dialect,ALTER SCHEMA ... DEFAULT ENCRYPTION.CREATE DATABASEoptions andDEFAULT CHARSETare typed, the empty raw option is gone, andALTER ROLESET/RESET moves intoparameterChange. Rendered SQL is unchanged except for the removed trailing space.toString()on a second, identical server, in the same order. All 206 MySQL and 332 PostgreSQL statements give the same result (success, or the same error).Integration validation
Applied #2806–#2819 together on
master(bdf8ac31), with the stacked PRs on top of their bases (#2806 → #2807 → #2808, #2806 → #2809 → #2810 and #2811 → #2812).master. Between the branches, conflicts are limited to adjacent additions (README/index rows, usage sections, imports, visitor and feature lists, one enum line and one alias guard).spotlessApply check: 11,494 tests, 11,469 passed, 25 skipped, zero failures/errors. The grammar choice conflict check passes.master: 206) and 363 of 364 PostgreSQL statements (master: 328). Every MySQL 8.4 non-reserved word and PostgreSQL 18 unreserved or column-name keyword parses as a column and table name.