Skip to content

Commit

Permalink
Postgres: Fix UNNEST for L025 (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Apr 8, 2022
1 parent 93bc838 commit 3c47c45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/sqlfluff/dialects/dialect_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
# It quotes dateparts. So don't need this.
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.add(
JsonOperatorSegment=NamedParser(
"json_operator", SymbolSegment, name="json_operator", type="binary_operator"
Expand Down
15 changes: 14 additions & 1 deletion test/fixtures/rules/std_rule_cases/L025.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_pass_unaliased_table_referenced:
# L025 fix with https://github.com/sqlfluff/sqlfluff/issues/449
pass_str: select ps.*, pandgs.blah from ps join pandgs using(moo)

test_ignore_value_table_functions:
test_ignore_bigquery_value_table_functions:
# L025 fix with https://github.com/sqlfluff/sqlfluff/issues/356
pass_str: |
select *
Expand All @@ -31,6 +31,19 @@ test_ignore_value_table_functions:
core:
dialect: bigquery

test_ignore_postgres_value_table_functions:
# L025 fix with https://github.com/sqlfluff/sqlfluff/issues/3051
pass_str: |
SELECT json_build_object(
'name', 'ticket_status',
'type', 'enum',
'values', json_agg(status_name)
)
FROM unnest(enum_range(NULL::my_enum)) AS status_name;
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 3c47c45

Please sign in to comment.