From c9d260125a66d44bdcbc475c828ec73ba0697741 Mon Sep 17 00:00:00 2001 From: Eric Duong Date: Tue, 23 Jul 2024 15:24:33 -0400 Subject: [PATCH] chore(data-warehouse): use sql alchemy format for executing queries (#23927) --- .../data_imports/pipelines/sql_database/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/posthog/temporal/data_imports/pipelines/sql_database/__init__.py b/posthog/temporal/data_imports/pipelines/sql_database/__init__.py index 700e3af65b99e2..04fb8885701dac 100644 --- a/posthog/temporal/data_imports/pipelines/sql_database/__init__.py +++ b/posthog/temporal/data_imports/pipelines/sql_database/__init__.py @@ -16,6 +16,7 @@ from urllib.parse import quote from posthog.warehouse.types import IncrementalFieldType +from sqlalchemy.sql import text from .helpers import ( table_rows, @@ -150,14 +151,13 @@ def sql_database( def get_column_hints(engine: Engine, schema_name: str, table_name: str) -> dict[str, TColumnSchema]: with engine.connect() as conn: - execute_result: CursorResult | None = conn.execute( - "SELECT column_name, data_type, numeric_precision, numeric_scale FROM information_schema.columns WHERE table_schema = %(schema_name)s AND table_name = %(table_name)s", + execute_result: CursorResult = conn.execute( + text( + "SELECT column_name, data_type, numeric_precision, numeric_scale FROM information_schema.columns WHERE table_schema = :schema_name AND table_name = :table_name" + ), {"schema_name": schema_name, "table_name": table_name}, ) - if execute_result is None: - return {} - cursor_result = cast(CursorResult, execute_result) results = cursor_result.fetchall()