package com.sqlephant.test.schema.gen; import java.util.List; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.alter.Alter; import net.sf.jsqlparser.statement.alter.AlterExpression; public class PrimaryKeyExtractorTest { public static void main(String[] args) throws Exception { String sql = "ALTER TABLE ONLY public.film_category ADD CONSTRAINT film_category_pkey PRIMARY KEY (film_id, category_id);"; Statement statement = CCJSqlParserUtil.parse(sql); if (statement instanceof Alter) { Alter alter = (Alter) statement; System.out.println("alter : " + alter); System.out.println("getTable: " + alter.getTable()); for (AlterExpression alterExpression : alter.getAlterExpressions()) { System.out.println("alterExpression : " + alterExpression.toString()); System.out.println("getConstraintName : " + alterExpression.getConstraintName()); List pkColumns = alterExpression.getPkColumns(); System.out.println("pkColumns : " + pkColumns); } } } }