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