Skip to content

redshift dialect: support for PREPARE, EXECUTE and DEALLOCATE statements missing #3810

@6e2f61

Description

@6e2f61

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Trying to make PREPARE plan_name EXECUTE plan_name(parameter) and DEALLOCATE plan_name statements throws parsing error.

Expected Behaviour

Add support for the PREPARE plan_name, EXECUTE plan_name(parameter, [,...]) and DEALLOCATE plan_name keywords.
AWS Documentation for prepare, execute and deallocate.

Observed Behaviour

Query not currently supported, results in parse errors:

➜ sqlfluff lint example.sql
== [example.sql] FAIL
L:   1 | P:   1 |  PRS | Line 1, Position 1: Found unparsable section: 'PREPARE select_plan(DATE)\nSELECT\n CAS...'
L:   3 | P:  10 |  LXR | Unable to lex characters: '$1'
L:   6 | P:  30 | L003 | Expected 0 indentations, found 1 [compared to line 05]
L:   8 | P:   1 |  PRS | Line 8, Position 1: Found unparsable section: "EXECUTE select_plan(SYSDATE - INTERVAL '..."
L:  10 | P:   1 |  PRS | Line 10, Position 1: Found unparsable section: 'DEALLOCATE select_plan'
WARNING: Parsing errors found and dialect is set to 'redshift'. Have you configured your dialect correctly?
All Finished 📜 🎉!

How to reproduce

Create a test file containing as below and try to lint/parse with sqlfluff.

PREPARE select_plan(DATE)
SELECT
    CAST($1 AS DATE) AS some_date
    , CAST('any_val' AS VARCHAR(32)) AS col1
FROM
    some_schema.example_table;

EXECUTE select_plan(SYSDATE - INTERVAL '1 day');

DEALLOCATE select_plan;

Dialect

redshift

Version

sqlfluff, version 1.3.0
Python 3.8.10

Configuration

# https://docs.sqlfluff.com/en/stable/configuration.html#config

[sqlfluff]
dialect = redshift
templater = placeholder
rules = all
# L034: Select wildcards then simple targets before calculations and aggregates
# L046: Jinja tags should have a single whitespace on either side (we dont use jinja2)
exclude_rules = L034, L046
# Controls SQLFluff output, see max_line_length for SQL output
output_line_length = 256
ignore_templated_areas = true
sql_file_exts = .sql,.dml,.ddl

[sqlfluff:templater:placeholder]
# handling of placeholders {placeholder} in tpl.sql files
param_regex = {(?P<param_name>[\w_]+)}
# all parameters used in tpl.sql files - please sort lines alphabetically
columns = acol1, acol2, tcol1
hash_from_non_tech_columns = CAST(MD5(COALESCE(acol1, 'NULL') + '-' + COALESCE(acol2, 'NULL')) AS VARCHAR(32)) AS row_hash
iam_role_arn = arn:aws:iam::012345678901:role/ELT_SERVICE-RedshiftAllCommandsFullAccess
pk = primary_key
prepared_data_file_s3_uri = s3://somebucketname-temporary/part.filename.csv
report_name_short = report_short_name
source_non_tech_columns = acol1, acol2, tcol1
staging_tech_cols = to_add, to_delete
staging_tbl_drop_cols_stmt = ALTER TABLE schema.table DROP COLUMN t_valid_to;
source_select_statement = SELECT acol1, acol2, tcol1 FROM example1
source_select_stmt = SELECT acol1, acol2, tcol1 FROM example1
target_columns = acol1, acol2, tcol1
target_non_tech_columns = tcol1, tcol2
target_schema = target_schema
target_table = target_table
target_tech_columns = tcol1, tcol2
tech_cols_diff_src_tgt = fl_del, load_type
tech_cols_diff_tgt_tgt_hist = tcol1, tcol2, tcol3
unique_id = unique_id
tgt_bk_is_not_null = tgt.col1_sk IS NOT NULL
bk_is_not_null = col1_sk IS NOT NULL
tgt_bk_is_null = col1_sk IS NULL
stg_bk_is_null = col1_sk IS NULL
src_bk_equals_stg_bk = src.bk \= stg.bk
stg_bk_is_not_null = stg.col1_sk IS NOT NULL
tgt_bk_equals_stg_bk = tgt.col1 \= stg.col1
srh_bk_equals_stg_bk = srh.col1 \= stg.col1
alias_tgt_dot_bk_as_tgt_bk = tgt.col1 AS tgt_col1
stg_table_tgt_bk_equals_tgt_bk = schema.table1__stg_unique_id.tgt_col1 \= schema.table1.col1
stg_table_bk_equals_tgt_bk = schema.table1__stg_unique_id.col1 \= schema.table1.col1
stg_tgt_bk_equals_tgt_bk = stg.tgt_col1 = schema.table1.col1
bk_in_select_from_stg_tbl_where_bk_is_not_null = col1 IN ( SELECT tgt_col1 FROM schema.table1__stg_unique_id WHERE col1 IS NOT NULL AND tgt_col1 IS NOT NULL);

[sqlfluff:indentation]
indented_joins = false
indented_using_on = true
template_blocks_indent = true

[sqlfluff:rules]
tab_space_size = 4
max_line_length = 118
indent_unit = space
comma_style = trailing

# https://docs.sqlfluff.com/en/stable/rules.html#ruleref

[sqlfluff:rules:L003] # FIX COMPATIBLE
# Indentation must be consistent with previous lines
# Hanging indents will be considered when evaluting the indentation (true)
hanging_indents = false

[sqlfluff:rules:L007] # FIX COMPATIBLE
# Operators should follow a standard for being after newlines
operator_new_lines = after

[sqlfluff:rules:L010] # FIX COMPATIBLE
# Captialise all keywords
capitalisation_policy = upper

[sqlfluff:rules:L011] # FIX COMPATIBLE
# Aliasing of tables with AS keyword (explicit)
aliasing = explicit

[sqlfluff:rules:L012]
# Aliasing of columns with AS keyword (explicit)
aliasing = explicit

[sqlfluff:rules:L013]
# Use AS keyword for columns expression
# Do not allow single element in select without alias (false)
allow_scalar = false

[sqlfluff:rules:L014] # FIX COMPATIBLE
# Capitalisation of unquoted identifiers (lowercase)
extended_capitalisation_policy = lower

[sqlfluff:rules:L016] # FIX COMPATIBLE
# Max length of lines
ignore_comment_clauses = true
ignore_comment_lines = true
indent_unit = space
max_line_length = 160
tab_space_size = 4

[sqlfluff:rules:L019] # FIX COMPATIBLE
# Leading comma enforcement
comma_style = leading

[sqlfluff:rules:L022] # FIX COMPATIBLEs
# Blank line expected but not found after Common Table Expression closing bracket
# Leading comma enfrocement
comma_style = leading

[sqlfluff:rules:L026]
# References cannot reference objects not present in FROM clause (false)
force_enable = false

[sqlfluff:rules:L028] # FIX COMPATIBLE
# References should be consistent in statements with a single table (true)
force_enable = true
# If there is single table remove table reference (unqualified)
single_table_references = unqualified

[sqlfluff:rules:L029]
# Keywords should not be used as identifiers
# Types of quoted identifiers to flag violations for (all)
unquoted_identifiers_policy = all
# Ignored keywords (do not add sql reserved keywords)
ignore_words = character_maximum_length, column_name, columns, constraint_name, constraint_schema, data_type, description, role, status, table_name, type

[sqlfluff:rules:L030] # FIX COMPATIBLE
# Capitalisation of function names (upper)
extended_capitalisation_policy = upper

[sqlfluff:rules:L031] # FIX COMPATIBLE
# Allow table aliases in from clauses and join conditions (false)
force_enable = false

[sqlfluff:rules:L036] # FIX COMPATIBLE
# Select targets should be on a new line unless there is only one select target
# Treat wildcards as multiple targets
wildcard_policy = multiple

[sqlfluff:rules:L038] # FIX COMPATIBLE
# Forbid trailing commas within select clause
select_clause_trailing_comma = forbid

[sqlfluff:rules:L040] # FIX COMPATIBLE
# Capitalisation of boolean/null literal (upper)
capitalisation_policy = upper

# [sqlfluff:rules:L042]
# JOIN and FROM clauses should not contain subqueries, use WITH instead
# forbid_subquery_in = both

[sqlfluff:rules:L051] # FIX COMPATIBLE
# Join clauses should be fully qualified with outer/inner (both)
fully_qualify_join_types = both

[sqlfluff:rules:L052] # FIX COMPATIBLE
# Statements must end with a semi-colon
# Semi-colons to be placed on a new line after multi-line statements (false)
multiline_newline = false
# Require semi-colon at the end of statement (false) required for wrapping sql statements
require_final_semicolon = false

[sqlfluff:rules:L054]
# Explicit column references in GROUP BY/ORDER BY clauses
group_by_and_order_by_style = explicit

[sqlfluff:rules:L057]
# Do not use special characters in identifiers
# List of extra allowed characters - to use with Redshift Parameters
additional_allowed_characters = $
# Do not allow spaces in identifiers be allowed (false)
allow_space_in_identifier = false
# Types of quoted identifiers to flag violations for
quoted_identifiers_policy = all
# Types of unquoted identifiers to flag violations for
unquoted_identifiers_policy = all

[sqlfluff:rules:L059] # FIX COMPATIBLE
# Unnecessary quoted identifier
# the quotes are unnecessary, except for reserved keywords and special characters in identifiers (false)
prefer_quoted_identifiers = false

[sqlfluff:rules:L063] # FIX COMPATIBLE
# Enforce upper capitalisation of datatypes
extended_capitalisation_policy = upper

[sqlfluff:rules:L066]
# Enforce table alias lengths in from clauses and join conditions
max_alias_length = 16
min_alias_length = 4

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingredshiftIssues relating to Amazon Redshift dialect

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions