SQLALCHEMY.EXC.ProgrammingError: (psycopg.Errors.undefinedObject)
Nicht anerkannter Konfigurationsparameter "Standard_conforming_strings" < /p>
< /blockquote>
Aussieht sqlalchemy. Zeit.
Was wir versucht haben:
- SQLALCHEMY 1.4.49 → funktioniert gut mit Rotverschiebung. RedShift+redshift_connector: // → fehlschlägt immer noch, es sei denn, wir stufen auf 1.4.x
[*] Gibt es eine Möglichkeit, SQLALCHEMY 2.x mit RedShift zu verwenden. Ich möchte die neueste
[*] Verwenden ich mit der neuesten Version von SQLAlchemy und mit PSYCOPG (postgresql+psycopg) oder (postgresql+psycopg)
Kann ich die AWS -SADE -SADE -SADE -SACE -SACE -SACE -AWS -SADE -AWS -SADE -AWS -SADE -Sichtweise. Ich möchte es nicht umgehen.
Code: Select all
from sqlalchemy import create_engine, event, text
# Database credentials and connection details
engine = create_engine(
f"postgresql+psycopg2://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
)
# Set standard_conforming_strings=on if supported (PostgreSQL only, not Redshift)
@event.listens_for(engine, "connect")
def set_standard_conforming_strings(dbapi_connection, connection_record):
try:
cursor = dbapi_connection.cursor()
cursor.execute("SET standard_conforming_strings = on;")
cursor.close()
except Exception:
# Ignore if not supported (e.g., Redshift)
pass
# List of tables to query
all_tables = []
# Query row counts
with engine.connect() as conn:
for table in all_tables:
try:
query = text(f"SELECT COUNT(*) FROM {table}")
result = conn.execute(query)
count = result.scalar()
print(f"Row count for {table}: {count}")
except Exception as e:
print(f"Error querying {table}: {e}")