Skip to content

Commit 5377eeb

Browse files
committed
Make \copy case-insensitive
`\COPY` behaves exactly like `\copy` in `psql` - see [psql's slash-command-parsing function](https://github.com/postgres/postgres/blob/ea15816928c1bbcab749205a263d82daea28a3e0/src/bin/psql/command.c#L330) and note the use of `pg_strcasecmp`. So some users expect to be able to use `\COPY` in pgcli. This commit makes that happen.
1 parent 2be16ab commit 5377eeb

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Upcoming
2+
========
3+
4+
* Made `\copy` case-insensitive, as it is in `psql`.
5+
16
2.1.2 (2024-05-15)
27
==================
38

pgspecial/iocommands.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from os.path import expanduser
1111
from .namedqueries import NamedQueries
1212
from . import export
13-
from .main import show_extra_help_command, special_command
13+
from .main import show_extra_help_command, special_command, PARSED_QUERY
1414

1515
NAMED_QUERY_PLACEHOLDERS = frozenset({"$1", "$*", "$@"})
1616

@@ -132,6 +132,7 @@ def _index_of_file_name(tokenlist):
132132
"\\copy",
133133
"\\copy [tablename] to/from [filename]",
134134
"Copy data between a file and a table.",
135+
case_sensitive=False,
135136
)
136137
def copy(cur, pattern, verbose):
137138
"""Copies table data to/from files"""

tests/test_specials.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,18 @@ def test_slash_copy_from_csv(executor, connection, tmpdir):
10341034
assert row[1] == "elephant"
10351035

10361036

1037+
@dbtest
1038+
def test_slash_copy_case_insensitive(executor, tmpdir):
1039+
filepath = tmpdir.join("pycons.tsv")
1040+
executor(
1041+
r"\COPY (SELECT 'Montréal', 'Portland', 'Cleveland') TO '{0}' ".format(filepath)
1042+
)
1043+
infile = filepath.open(encoding="utf-8")
1044+
contents = infile.read()
1045+
assert len(contents.splitlines()) == 1
1046+
assert "Montréal" in contents
1047+
1048+
10371049
@dbtest
10381050
def test_slash_sf(executor):
10391051
results = executor(r"\sf func1")

0 commit comments

Comments
 (0)