From b1853bfca089b81b3e238884b68c98c1bcb0a2f2 Mon Sep 17 00:00:00 2001 From: minleejae Date: Sun, 20 Sep 2026 20:54:02 +0900 Subject: [PATCH] feat: support PostgreSQL COPY WITH options Signed-off-by: minleejae --- .../jsqlparser/statement/CopyStatement.java | 31 +++++- .../util/deparser/StatementDeParser.java | 3 +- .../net/sf/jsqlparser/parser/JSqlParserCC.jjt | 10 +- .../statement/PostgreSqlCopyTest.java | 100 ++++++++++++++++++ 4 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 src/test/java/net/sf/jsqlparser/statement/PostgreSqlCopyTest.java diff --git a/src/main/java/net/sf/jsqlparser/statement/CopyStatement.java b/src/main/java/net/sf/jsqlparser/statement/CopyStatement.java index 0dbc2892b..0e05b5863 100644 --- a/src/main/java/net/sf/jsqlparser/statement/CopyStatement.java +++ b/src/main/java/net/sf/jsqlparser/statement/CopyStatement.java @@ -16,10 +16,12 @@ import net.sf.jsqlparser.statement.select.Select; import java.util.List; +import java.util.function.Consumer; /** * {@code COPY table [(columns)] FROM path [(options)]} and - * {@code COPY {table | (query)} TO path [(options)]}, DuckDB's bulk import and export statement. + * {@code COPY {table | (query)} TO path [(options)]}, the bulk import and export statement in + * DuckDB and PostgreSQL. * * @see COPY */ @@ -30,6 +32,7 @@ public class CopyStatement implements Statement { private boolean from; private String path; private List options; + private boolean withKeyword; public Table getTable() { return table; @@ -110,10 +113,31 @@ public CopyStatement withOptions(List options) { return this; } + /** Whether the option list is introduced by the optional WITH keyword. */ + public boolean isWithKeyword() { + return withKeyword; + } + + public void setWithKeyword(boolean withKeyword) { + this.withKeyword = withKeyword; + } + + public CopyStatement withWithKeyword(boolean withKeyword) { + setWithKeyword(withKeyword); + return this; + } + public StringBuilder appendTo(StringBuilder builder) { + return appendTo(builder, builder::append); + } + + /** Renders the query through the caller's select writer. */ + public StringBuilder appendTo(StringBuilder builder, Consumer