Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ and missing syntax gets added on demand — [open an issue](https://github.com/J
| **MySQL utility statements** | `EXPLAIN`/`DESCRIBE [ANALYZE] FORMAT = …` · `EXPLAIN FOR CONNECTION` · `DESCRIBE t col` · `PREPARE … FROM` · `EXECUTE … USING` · `DROP PREPARE` · `DO` |
| **PostgreSQL administration** | `CREATE`/`ALTER EVENT TRIGGER` · `REINDEX` · `SECURITY LABEL` |
| **PostgreSQL types and rules** | `CREATE TYPE` (shell, composite, enum, range and base types) · `ALTER TYPE` · `CREATE RULE` · `ALTER RULE` |
| **PostgreSQL operators and aggregates** | `CREATE`/`ALTER OPERATOR` · `CREATE`/`ALTER OPERATOR CLASS` · `CREATE`/`ALTER OPERATOR FAMILY` · `CREATE`/`ALTER AGGREGATE` |
| **Informix constraints** | `ALTER TABLE … ADD CONSTRAINT` with trailing constraint names for primary, unique, foreign and check constraints; enable with `parser.withDialect(Dialect.INFORMIX)` |
| **Salesforce SOQL** | `INCLUDES` · `EXCLUDES` |

Expand Down
48 changes: 48 additions & 0 deletions src/main/java/net/sf/jsqlparser/parser/feature/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,54 @@ public enum Feature {
* @see net.sf.jsqlparser.statement.alter.AlterRule
*/
alterRule,
/**
* PostgreSQL "CREATE OPERATOR" statement is allowed
*
* @see net.sf.jsqlparser.statement.create.operator.CreateOperator
*/
createOperator,
/**
* PostgreSQL "CREATE OPERATOR CLASS" statement is allowed
*
* @see net.sf.jsqlparser.statement.create.operator.CreateOperatorClass
*/
createOperatorClass,
/**
* PostgreSQL "CREATE OPERATOR FAMILY" statement is allowed
*
* @see net.sf.jsqlparser.statement.create.operator.CreateOperatorFamily
*/
createOperatorFamily,
/**
* PostgreSQL "CREATE AGGREGATE" statement is allowed
*
* @see net.sf.jsqlparser.statement.create.aggregate.CreateAggregate
*/
createAggregate,
/**
* PostgreSQL "ALTER OPERATOR" statement is allowed
*
* @see net.sf.jsqlparser.statement.alter.AlterOperator
*/
alterOperator,
/**
* PostgreSQL "ALTER OPERATOR CLASS" statement is allowed
*
* @see net.sf.jsqlparser.statement.alter.AlterOperatorClass
*/
alterOperatorClass,
/**
* PostgreSQL "ALTER OPERATOR FAMILY" statement is allowed
*
* @see net.sf.jsqlparser.statement.alter.AlterOperatorFamily
*/
alterOperatorFamily,
/**
* PostgreSQL "ALTER AGGREGATE" statement is allowed
*
* @see net.sf.jsqlparser.statement.alter.AlterAggregate
*/
alterAggregate,
/**
* SQL block starting with "BEGIN" and ends with "END" statement is allowed
*
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/net/sf/jsqlparser/statement/DefinitionElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

/**
* One element of a PostgreSQL definition list, {@code name [= value]}, as in
* {@code CREATE TYPE name (INPUT = fn, PASSEDBYVALUE)} or
* {@code ALTER TYPE name SET (SEND = NONE)}. The name keeps its spelling and quoting.
* {@code CREATE TYPE name (INPUT = fn, PASSEDBYVALUE)}, {@code ALTER TYPE name SET (SEND = NONE)},
* {@code CREATE OPERATOR} or {@code CREATE AGGREGATE}. The name keeps its spelling and quoting.
*/
public class DefinitionElement implements Serializable {
private String name;
Expand Down Expand Up @@ -62,6 +62,18 @@ public static String toString(List<DefinitionElement> elements) {
return elements.stream().map(Object::toString).collect(Collectors.joining(", ", "(", ")"));
}

/**
* Finds an element of a definition list by its name, ignoring case.
*
* @param elements the elements
* @param name the name, such as {@code INPUT}
* @return the first element of that name, or {@code null}
*/
public static DefinitionElement find(List<DefinitionElement> elements, String name) {
return elements.stream().filter(element -> name.equalsIgnoreCase(element.getName()))
.findFirst().orElse(null);
}

@Override
public String toString() {
return argument == null ? name : name + " = " + argument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
import net.sf.jsqlparser.statement.alter.AlterPolicy;
import net.sf.jsqlparser.statement.alter.AlterPublication;
import net.sf.jsqlparser.statement.alter.AlterRelation;
import net.sf.jsqlparser.statement.create.operator.CreateOperator;
import net.sf.jsqlparser.statement.create.operator.CreateOperatorClass;
import net.sf.jsqlparser.statement.create.operator.CreateOperatorFamily;
import net.sf.jsqlparser.statement.create.aggregate.CreateAggregate;
import net.sf.jsqlparser.statement.alter.AlterOperator;
import net.sf.jsqlparser.statement.alter.AlterOperatorClass;
import net.sf.jsqlparser.statement.alter.AlterOperatorFamily;
import net.sf.jsqlparser.statement.alter.AlterAggregate;
import net.sf.jsqlparser.statement.alter.AlterRule;
import net.sf.jsqlparser.statement.alter.AlterServer;
import net.sf.jsqlparser.statement.alter.AlterSession;
Expand Down Expand Up @@ -1557,4 +1565,44 @@ public <S> Void visit(CreateCollation statement, S context) {
public <S> Void visit(AlterRule statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(CreateOperator statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(CreateOperatorClass statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(CreateOperatorFamily statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(CreateAggregate statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(AlterOperator statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(AlterOperatorClass statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(AlterOperatorFamily statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(AlterAggregate statement, S context) {
return schemaOnly();
}
}
72 changes: 72 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
import net.sf.jsqlparser.statement.notify.NotifyStatement;
import net.sf.jsqlparser.statement.create.collation.CreateCollation;
import net.sf.jsqlparser.statement.alter.AlterCollation;
import net.sf.jsqlparser.statement.create.operator.CreateOperator;
import net.sf.jsqlparser.statement.create.operator.CreateOperatorClass;
import net.sf.jsqlparser.statement.create.operator.CreateOperatorFamily;
import net.sf.jsqlparser.statement.create.aggregate.CreateAggregate;
import net.sf.jsqlparser.statement.alter.AlterOperator;
import net.sf.jsqlparser.statement.alter.AlterOperatorClass;
import net.sf.jsqlparser.statement.alter.AlterOperatorFamily;
import net.sf.jsqlparser.statement.alter.AlterAggregate;
import net.sf.jsqlparser.statement.alter.AlterRule;
import net.sf.jsqlparser.statement.alter.AlterRoutine;
import net.sf.jsqlparser.statement.alter.AlterTrigger;
Expand Down Expand Up @@ -1182,4 +1190,68 @@ default <S> T visit(AlterRule statement, S context) {
default void visit(AlterRule statement) {
visit(statement, null);
}

default <S> T visit(CreateOperator statement, S context) {
return null;
}

default void visit(CreateOperator statement) {
visit(statement, null);
}

default <S> T visit(CreateOperatorClass statement, S context) {
return null;
}

default void visit(CreateOperatorClass statement) {
visit(statement, null);
}

default <S> T visit(CreateOperatorFamily statement, S context) {
return null;
}

default void visit(CreateOperatorFamily statement) {
visit(statement, null);
}

default <S> T visit(CreateAggregate statement, S context) {
return null;
}

default void visit(CreateAggregate statement) {
visit(statement, null);
}

default <S> T visit(AlterOperator statement, S context) {
return null;
}

default void visit(AlterOperator statement) {
visit(statement, null);
}

default <S> T visit(AlterOperatorClass statement, S context) {
return null;
}

default void visit(AlterOperatorClass statement) {
visit(statement, null);
}

default <S> T visit(AlterOperatorFamily statement, S context) {
return null;
}

default void visit(AlterOperatorFamily statement) {
visit(statement, null);
}

default <S> T visit(AlterAggregate statement, S context) {
return null;
}

default void visit(AlterAggregate statement) {
visit(statement, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.alter;

import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.RoutineReference;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;

/**
* PostgreSQL {@code ALTER AGGREGATE name (arguments)} with one of {@code RENAME TO new_name},
* {@code OWNER TO role} and {@code SET SCHEMA schema}.
*/
public class AlterAggregate extends ASTNodeAccessImpl implements Statement {
public enum Action {
RENAME, OWNER, SET_SCHEMA
}

private RoutineReference aggregate;
private Action action;
private String newName;

/**
* The name and the argument signature, read as in DROP AGGREGATE.
*
* @return the aggregate
*/
public RoutineReference getAggregate() {
return aggregate;
}

public void setAggregate(RoutineReference aggregate) {
this.aggregate = aggregate;
}

public Action getAction() {
return action;
}

public void setAction(Action action) {
this.action = action;
}

/**
* The new name of {@code RENAME TO}, the role of {@code OWNER TO} or the schema of
* {@code SET SCHEMA}.
*
* @return the name, or {@code null} for another action
*/
public String getNewName() {
return newName;
}

public void setNewName(String newName) {
this.newName = newName;
}

@Override
public StringBuilder appendTo(StringBuilder builder) {
builder.append("ALTER AGGREGATE ").append(aggregate);
switch (action) {
case RENAME:
return builder.append(" RENAME TO ").append(newName);
case OWNER:
return builder.append(" OWNER TO ").append(newName);
case SET_SCHEMA:
return builder.append(" SET SCHEMA ").append(newName);
default:
throw new IllegalStateException("Unknown aggregate alteration: " + action);
}
}

@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}

@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
}
Loading
Loading