Skip to content

Commit

Permalink
Modify a bit how partition by clause handles BindParameter and Execut…
Browse files Browse the repository at this point in the history
…able objects
  • Loading branch information
sfc-gh-lcalderonachio committed Nov 19, 2024
1 parent ed31c9f commit c8dee12
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/snowflake/sqlalchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
from typing import List

from sqlalchemy import Executable
from sqlalchemy import exc as sa_exc
from sqlalchemy import inspect, sql
from sqlalchemy import util as sa_util
Expand All @@ -16,7 +17,7 @@
from sqlalchemy.schema import Sequence, Table
from sqlalchemy.sql import compiler, expression, functions
from sqlalchemy.sql.base import CompileState
from sqlalchemy.sql.elements import quoted_name
from sqlalchemy.sql.elements import BindParameter, quoted_name
from sqlalchemy.sql.selectable import Lateral, SelectState

from snowflake.sqlalchemy._constants import DIALECT_NAME
Expand Down Expand Up @@ -576,11 +577,17 @@ def visit_copy_into(self, copy_into, **kw):
else:
from_ = f"({copy_into.from_._compiler_dispatch(self, **kw)})"

partition_by = ""
if isinstance(copy_into.partition_by, str):
partition_by = f"PARTITION BY '{copy_into.partition_by}'"
partition_by_value = ""
if isinstance(copy_into.partition_by, (BindParameter, Executable)):
partition_by_value = copy_into.partition_by.compile(
compile_kwargs={"literal_binds": True}
)
elif copy_into.partition_by is not None:
partition_by = f"PARTITION BY {copy_into.partition_by}"
partition_by_value = copy_into.partition_by

partition_by = (
f"PARTITION BY {partition_by_value}" if partition_by_value != "" else ""
)

credentials, encryption = "", ""
if isinstance(into, tuple):
Expand Down

0 comments on commit c8dee12

Please sign in to comment.