Skip to content

Commit

Permalink
Postgres: treat GENERATE_SERIES as a value table function (#3463)
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb authored Jun 16, 2022
1 parent 6e8ce43 commit 8aa74a4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/sqlfluff/core/rules/analysis/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _has_value_table_function(table_expr, dialect):
# Other rules can increase whitespace in the function name, so use strip to
# remove
# See: https://github.com/sqlfluff/sqlfluff/issues/1304
if function_name.raw.lower().strip() in dialect.sets("value_table_functions"):
if function_name.raw.upper().strip() in dialect.sets("value_table_functions"):
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion src/sqlfluff/dialects/dialect_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@

# In BigQuery, UNNEST() returns a "value table".
# https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#value_tables
bigquery_dialect.sets("value_table_functions").update(["unnest"])
bigquery_dialect.sets("value_table_functions").update(["UNNEST"])

# Bracket pairs (a set of tuples). Note that BigQuery inherits the default
# "bracket_pairs" set from ANSI. Here, we're adding a different set of bracket
Expand Down
2 changes: 1 addition & 1 deletion src/sqlfluff/dialects/dialect_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
postgres_dialect.sets("date_part_function_name").clear()

# In Postgres, UNNEST() returns a "value table", similar to BigQuery
postgres_dialect.sets("value_table_functions").update(["unnest"])
postgres_dialect.sets("value_table_functions").update(["UNNEST", "GENERATE_SERIES"])

postgres_dialect.add(
JsonOperatorSegment=NamedParser(
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/rules/std_rule_cases/L025.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ test_ignore_postgres_value_table_functions:
core:
dialect: postgres

test_ignore_postgres_value_table_functions_generate_series:
# L025 fix with https://github.com/sqlfluff/sqlfluff/issues/3462
pass_str: |
SELECT
date_trunc('day', dd):: timestamp with time zone
FROM generate_series (
'2022-02-01'::timestamp , NOW()::timestamp , '1 day'::interval
) dd ;
configs:
core:
dialect: postgres

test_fail_table_alias_not_referenced_2:
# Similar to test_1, but with implicit alias.
fail_str: SELECT * FROM my_tbl foo
Expand Down

0 comments on commit 8aa74a4

Please sign in to comment.