Skip to content

Commit db38be3

Browse files
committed
fix: ignore double colon cast operators in SQL parameter substitution
1 parent cfe0ca8 commit db38be3

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

awswrangler/_sql_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _format_parameters(params: dict[str, Any], engine: _Engine) -> dict[str, Any
155155
return processed_params
156156

157157

158-
_PATTERN = re.compile(r":([A-Za-z0-9_]+)(?![A-Za-z0-9_])")
158+
_PATTERN = re.compile(r"(?<!:):([A-Za-z0-9_]+)(?![A-Za-z0-9_])")
159159

160160

161161
def _create_engine(engine_type: _EngineTypeLiteral) -> _Engine:

tests/unit/test_sql_params_formatter.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
import pytest
66

7-
from awswrangler._sql_formatter import _Engine, _format_parameters, _HiveEngine, _PrestoEngine
7+
from awswrangler._sql_formatter import (
8+
_Engine,
9+
_format_parameters,
10+
_HiveEngine,
11+
_PrestoEngine,
12+
_process_sql_params,
13+
)
814

915
_hive_engine_param = pytest.param(_HiveEngine(), id="hive")
1016
_presto_engine_param = pytest.param(_PrestoEngine(), id="presto")
@@ -118,3 +124,11 @@ class Point:
118124
{"point": Point(7, 1)},
119125
engine=engine,
120126
)
127+
128+
129+
def test_process_sql_params_double_colon_cast() -> None:
130+
sql = "SELECT col::text, col::timestamp FROM table WHERE id = :id AND status = :text"
131+
params = {"id": 1, "text": "active"}
132+
processed_sql = _process_sql_params(sql, params)
133+
expected_sql = "SELECT col::text, col::timestamp FROM table WHERE id = 1 AND status = 'active'"
134+
assert processed_sql == expected_sql

0 commit comments

Comments
 (0)