Wie erhalte ich das Protokoll abgelehnter Zeilen in einer Kopieranforderung in psycopg2?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie erhalte ich das Protokoll abgelehnter Zeilen in einer Kopieranforderung in psycopg2?

by Anonymous » 29 Dec 2024, 06:40

Als Datenbank wird die Postgresql 17-Version verwendet.
Ich verwende Parameter in der Kopieranforderung: ON_ERROR, LOG_VERBOSITY

Code: Select all

COPY PUBLIC.TEST_TABLE(
TEST
)
FROM STDIN
WITH (
FORMAT CSV,
ON_ERROR IGNORE,
LOG_VERBOSITY VERBOSE
Wenn die Zeilen abgelehnt werden, erhalte ich dieses Protokoll.
Beispiel:

Code: Select all

skipping row due to data type incompatibility at line 1 for column "TEST": "'1abcdefg'
1 rows were skipped due to data type incompatibility
Wie erhalte ich dieses Protokoll, wenn ich Python psycopg2 aufrufe?

Code: Select all

from psycopg2 import connect
conn = connect(**conn_config)
curs = conn.cursor()
sql = """COPY PUBLIC.TEST_TABLE(
TEST
)
FROM STDIN
WITH (
FORMAT CSV,
ON_ERROR IGNORE,
LOG_VERBOSITY VERBOSE
)"""
curs.copy_expert(sql, csv)
conn.commit()

Top