I'm using sqlfluff to check the sql code formatting. conf of sqlfluff are here :
sqlfluff = "^0.13.2"
[tool.sqlfluff]
sql_file_exts = [
".sql",
]
[tool.sqlfluff.core]
dialect = "bigquery"
rules = "L001,L002,L003,L004,L005,L006,L008,L009,L010,L012,L013,L015,L016,L018,L019,L020,L022,L023,L024,L025,L035,L036,L037,L038,L039,L040,L041,L045,L046,L048,L049,L050,L051,L052,L053,L061,L063"
I have a sql query that uses EXECUTE IMMEDIATE (dynamic bigquery sql)
DECLARE
c_c string;
DECLARE
ps ARRAY<string>;
DECLARE
p_cc string;
DECLARE
d_cc string;
CREATE TABLE IF NOT EXISTS
`dataset.table` ( A STRING,
B STRING,
C STRING,
D STRING,
F STRING,
E STRING,
G STRING,
H STRING,
E STRING,
J timestamp,
K INT64 ) PARTITION BY
RANGE_BUCKET(K, GENERATE_ARRAY(0,100,1));
SET
c_c="code1";
SET
ps = ["project-code1",
"project-code2",
"project-code3",
"project-code4",
"project-code5",
"project-code6"];
SET
p_cc = (
WITH
ps_cte AS (
SELECT
*
FROM
UNNEST(ps) ps
WHERE
ps LIKE CONCAT('%-', c_c))
SELECT
ps
FROM
ps_cte);
SET
d_cc = CONCAT(p_cc,".sales_",c_c,".");
EXECUTE IMMEDIATE
FORMAT( """
CREATE OR REPLACE TEMP TABLE temp_table AS
SELECT
cols
FROM
`%ssat_table` sc
""",d_cc)
:
when I want to apply sqlfluff lint :
poetry run sqlfluff lint query.sql
it gives:
L: 47 | P: 1 | PRS | Line 47, Position 1: Found unparsable section: 'EXECUTE
| IMMEDIATE\n FORMAT( """ \n CREAT...'
why sqlfluff don't know execute immediate ? is there any solution?
Thanks