Skip to content

Commit 6306d45

Browse files
committed
docs: show shared column rename access
Signed-off-by: minleejae <mmj9808@gmail.com>
1 parent 563332b commit 6306d45

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/site/sphinx/usage.rst‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,32 @@ These named targets do not populate the legacy ``getPkColumns()`` list.
288288
AlterExpression checkDrop = new AlterExpression()
289289
.withOperation(AlterOperation.DROP_CHECK).withConstraintName("positive_id");
290290
291+
Edit table and view column renames
292+
----------------------------------
293+
294+
``AlterExpression.getColumnRename()`` exposes a ``ColumnRenameAction`` with
295+
``getSourceName()`` and ``getTargetName()``. Their setters update the existing
296+
AST directly, preserving the optional ``COLUMN`` keyword. Names include their
297+
written identifier quotes; include quotes in replacement names when needed.
298+
299+
.. code-block:: java
300+
301+
Alter alter = (Alter) CCJSqlParserUtil.parse(
302+
"ALTER TABLE accounts RENAME COLUMN old_id TO new_id",
303+
parser -> parser.withDialect(Dialect.MYSQL));
304+
ColumnRenameAction rename = alter.getAlterExpressions().get(0).getColumnRename();
305+
rename.getSourceName(); // old_id
306+
rename.setTargetName("customer_id");
307+
// ALTER TABLE accounts RENAME COLUMN old_id TO customer_id
308+
String sql = alter.toString();
309+
310+
Import ``ColumnRenameAction`` from ``net.sf.jsqlparser.statement.alter``.
311+
PostgreSQL table renames of columns use the same API. With ``Dialect.POSTGRESQL``,
312+
column renames on views and materialized views expose it through the entries in
313+
``AlterRelation.getActions()``. The lookup returns ``null`` for other operations,
314+
including renaming the table, view, index or constraint itself. Existing
315+
action-specific getters and setters remain available and see the same changes.
316+
291317
Inspect PostgreSQL schema statements
292318
------------------------------------
293319

0 commit comments

Comments
 (0)