From 95473ad03d1e0d1e8086aef998d34db493037724 Mon Sep 17 00:00:00 2001
From: Joel Jacobson <joel@compiler.org>
Date: Thu, 17 Oct 2024 10:00:44 +0200
Subject: [PATCH] Correct negative tests for the COPY option FORCE_QUOTE.

The COPY option FORCE_QUOTE is valid only with COPY TO in CSV format.
The existing negative tests incorrectly used COPY FROM with FORCE_QUOTE
in non-CSV format, which is invalid regardless of the format and does
not isolate the specific invalid combinations.

This commit updates the tests to properly validate each disallowed scenario:

1. COPY TO with FORCE_QUOTE in a format other than CSV, which should be rejected
   because FORCE_QUOTE requires CSV format.
2. COPY FROM with FORCE_QUOTE in CSV format, which should be rejected because
   FORCE_QUOTE is not allowed with COPY FROM.

By testing these specific cases separately, we ensure that the appropriate
errors are raised for each invalid use of FORCE_QUOTE.
---
 src/test/regress/expected/copy2.out | 4 ++--
 src/test/regress/sql/copy2.sql      | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/test/regress/expected/copy2.out b/src/test/regress/expected/copy2.out
index 64ea33aeae..5efbe562a0 100644
--- a/src/test/regress/expected/copy2.out
+++ b/src/test/regress/expected/copy2.out
@@ -96,9 +96,9 @@ COPY x from stdin (on_error unsupported);
 ERROR:  COPY ON_ERROR "unsupported" not recognized
 LINE 1: COPY x from stdin (on_error unsupported);
                            ^
-COPY x from stdin (format TEXT, force_quote(a));
+COPY x to stdout (format TEXT, force_quote(a));
 ERROR:  COPY FORCE_QUOTE requires CSV mode
-COPY x from stdin (format TEXT, force_quote *);
+COPY x to stdout (format TEXT, force_quote *);
 ERROR:  COPY FORCE_QUOTE requires CSV mode
 COPY x from stdin (format CSV, force_quote(a));
 ERROR:  COPY FORCE_QUOTE cannot be used with COPY FROM
diff --git a/src/test/regress/sql/copy2.sql b/src/test/regress/sql/copy2.sql
index 45273557ce..087a0fea2f 100644
--- a/src/test/regress/sql/copy2.sql
+++ b/src/test/regress/sql/copy2.sql
@@ -74,8 +74,8 @@ COPY x from stdin (format BINARY, delimiter ',');
 COPY x from stdin (format BINARY, null 'x');
 COPY x from stdin (format BINARY, on_error ignore);
 COPY x from stdin (on_error unsupported);
-COPY x from stdin (format TEXT, force_quote(a));
-COPY x from stdin (format TEXT, force_quote *);
+COPY x to stdout (format TEXT, force_quote(a));
+COPY x to stdout (format TEXT, force_quote *);
 COPY x from stdin (format CSV, force_quote(a));
 COPY x from stdin (format CSV, force_quote *);
 COPY x from stdin (format TEXT, force_not_null(a));
-- 
2.45.1

