Skip to content

Commit a011bb6

Browse files
authored
Make \copy case-insensitive (#152)
`\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 a011bb6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Diff for: changelog.rst

+5
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

Diff for: pgspecial/iocommands.py

+1
Original file line numberDiff line numberDiff line change
@@ -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"""

Diff for: tests/test_specials.py

+12
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)