Skip to content

Commit 8a808a6

Browse files
committed
Factor out condition in strposition_sql
1 parent 35923e9 commit 8a808a6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sqlglot/dialects/dialect.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,8 @@ def strposition_sql(
10851085
if supports_occurrence and occurrence and supports_position and not position:
10861086
position = one
10871087

1088-
if position and not supports_position:
1088+
transpile_position = position and not supports_position
1089+
if transpile_position:
10891090
string = exp.Substring(this=string, start=position)
10901091

10911092
if func_name == "POSITION" and use_ansi_position:
@@ -1101,7 +1102,7 @@ def strposition_sql(
11011102
self.unsupported(f"{func_name} does not support the occurrence parameter.")
11021103
func = exp.Anonymous(this=func_name, expressions=args)
11031104

1104-
if position and not supports_position:
1105+
if transpile_position:
11051106
func_with_offset = exp.Sub(this=func + position, expression=one)
11061107
func_wrapped = exp.If(this=func.eq(zero), true=zero, false=func_with_offset)
11071108
return self.sql(func_wrapped)

0 commit comments

Comments
 (0)