Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Bug fixes:
created by ``uv venv``.
* Read ``alias_map_file`` as UTF-8 (with or without a BOM) instead of the
locale encoding, which made non-ASCII aliases fail on Windows.
* Double single quotes in values written by ``\T sql-insert`` and
``sql-update``, so a value like ``O'Brien`` gives valid SQL.

Internal:
---------
Expand Down
2 changes: 1 addition & 1 deletion pgcli/packages/formatter/sqlformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def escape_for_sql_statement(value):
if isinstance(value, bytes):
return f"X'{value.hex()}'"

return "'{}'".format(value)
return "'{}'".format(str(value).replace("'", "''"))


def adapter(data, headers, table_format=None, **kwargs):
Expand Down
4 changes: 4 additions & 0 deletions tests/formatter/test_sqlformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def test_escape_for_sql_statement_str():
assert escaped_bytes == "'example str'"


def test_escape_for_sql_statement_str_with_quote():
assert escape_for_sql_statement("O'Brien") == "'O''Brien'"


def test_output_sql_insert():
global formatter
formatter = TabularOutputFormatter
Expand Down
Loading