v2-0001-minor-refactor.no-cfbot

application/octet-stream

Filename: v2-0001-minor-refactor.no-cfbot
Type: application/octet-stream
Part: 0
Message: Re: POC PATCH: copy from ... exceptions to: (was Re: VLDB Features)
From 957be936169ce66a8517974bc28fd02004a3c353 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Sat, 13 Jan 2024 18:32:44 +0800
Subject: [PATCH v2 1/1] minor refactor

make save_error_to option cannot be used with COPY TO.
add redundant test, save_error_to with COPY TO test.
---
 src/backend/commands/copy.c         |  6 ++++++
 src/test/regress/expected/copy2.out | 10 +++++++++-
 src/test/regress/sql/copy2.sql      |  4 +++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 5e5e8a5f..f903ce32 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -584,6 +584,12 @@ ProcessCopyOptions(ParseState *pstate,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 						 errmsg("COPY save_error_to \"%s\" not recognized", location),
 						 parser_errposition(pstate, defel->location)));
+
+			if (!is_from)
+				ereport(ERROR,
+						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+						 errmsg("COPY SAVE_ERROR_TO cannot be used with COPY TO"),
+						 parser_errposition(pstate, defel->location)));
 		}
 		else
 			ereport(ERROR,
diff --git a/src/test/regress/expected/copy2.out b/src/test/regress/expected/copy2.out
index 4a1777a4..97fea200 100644
--- a/src/test/regress/expected/copy2.out
+++ b/src/test/regress/expected/copy2.out
@@ -77,13 +77,21 @@ COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii');
 ERROR:  conflicting or redundant options
 LINE 1: COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii...
                                                  ^
+COPY x from stdin (save_error_to none,save_error_to none);
+ERROR:  conflicting or redundant options
+LINE 1: COPY x from stdin (save_error_to none,save_error_to none);
+                                              ^
 -- incorrect options
 COPY x to stdin (format BINARY, delimiter ',');
 ERROR:  cannot specify DELIMITER in BINARY mode
 COPY x to stdin (format BINARY, null 'x');
 ERROR:  cannot specify NULL in BINARY mode
-COPY x to stdin (format BINARY, save_error_to none);
+COPY x from stdin (format BINARY, save_error_to none);
 ERROR:  cannot specify SAVE_ERROR_TO in BINARY mode
+COPY x to stdin (save_error_to none);
+ERROR:  COPY SAVE_ERROR_TO cannot be used with COPY TO
+LINE 1: COPY x to stdin (save_error_to none);
+                         ^
 COPY x to stdin (format TEXT, force_quote(a));
 ERROR:  COPY FORCE_QUOTE requires CSV mode
 COPY x from stdin (format CSV, force_quote(a));
diff --git a/src/test/regress/sql/copy2.sql b/src/test/regress/sql/copy2.sql
index 17c5764b..fda46f86 100644
--- a/src/test/regress/sql/copy2.sql
+++ b/src/test/regress/sql/copy2.sql
@@ -66,11 +66,13 @@ COPY x from stdin (force_not_null (a), force_not_null (b));
 COPY x from stdin (force_null (a), force_null (b));
 COPY x from stdin (convert_selectively (a), convert_selectively (b));
 COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii');
+COPY x from stdin (save_error_to none,save_error_to none);
 
 -- incorrect options
 COPY x to stdin (format BINARY, delimiter ',');
 COPY x to stdin (format BINARY, null 'x');
-COPY x to stdin (format BINARY, save_error_to none);
+COPY x from stdin (format BINARY, save_error_to none);
+COPY x to stdin (save_error_to none);
 COPY x to stdin (format TEXT, force_quote(a));
 COPY x from stdin (format CSV, force_quote(a));
 COPY x to stdout (format TEXT, force_not_null(a));
-- 
2.34.1