Skip to content

Commit

Permalink
fix: $$ not considered a variable
Browse files Browse the repository at this point in the history
fixes:
Session variable '$GENERATES' does not exist
  • Loading branch information
tekumara committed Jul 10, 2024
1 parent 96ba682 commit 235fbc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions fakesnow/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def inline_variables(self, sql: str) -> str:
for name, value in self._variables.items():
sql = re.sub(rf"\${name}", value, sql, flags=re.IGNORECASE)

remaining_variables = re.search(r"\$\w+", sql)
if remaining_variables:
if remaining_variables := re.search(r"(?<!\$)\$\w+", sql):
raise snowflake.connector.errors.ProgrammingError(
msg=f"Session variable '{remaining_variables.group().upper()}' does not exist"
)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,12 @@ def test_sfqid(cur: snowflake.connector.cursor.SnowflakeCursor):
assert cur.sfqid == "fakesnow"


def test_string_constant(cur: snowflake.connector.cursor.SnowflakeCursor):
assert cur.execute("""
select $$hello
world$$""").fetchall() == [("hello\nworld",)]


def test_tags_noop(cur: snowflake.connector.cursor.SnowflakeCursor):
cur.execute("CREATE TABLE table1 (id int)")
cur.execute("ALTER TABLE table1 SET TAG foo='bar'")
Expand Down

0 comments on commit 235fbc1

Please sign in to comment.