Found unparsable section: 'EXECUTE IMMEDIATE\n ...' sqlfuff? - google-bigquery

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

Related

Modify characters of a string to their ASCII code plus 10, SQL

I am using mariadb 10.3 and I'm trying to create a procedure that modifies all characters of a string, to each CHAR ASCII code, 10 position ahead.
I'm having trouble to find any functions to approach this problem, thanks.
For example given the string 'man':
ASCII codes: m = 109, a = 97, n = 110
Plus 10: 119 = w, 107 = k, 120 = x
So the function should return: 'wkx'
This works:
DECLARE longitud smallint;
DECLARE nuevaCadena varchar(100);
set longitud = LENGTH(cadena);
set nuevaCadena = '';
FOR i IN 1 .. longitud DO
set nuevaCadena = concat(nuevaCadena,char(ascii(substring(cadena,i)) + 10));
END FOR;

procedure to update selected columns in a table

POSTGRESQL
Case Background -There is a table named MasterSIM to which details are to be added usin.csv file via Nodered.
CREATE OR REPLACE PROCEDURE "master_SIMs".simiccidlink1(IMEI bigint, iccid text, phonenumber bigint, apn text, "Operator" text, isesim boolean, ism2m boolean, mdi bigint, imsi integer)
LANGUAGE 'plpgsql' AS
$BODY$
declare
-- retval text
begin
if (length(IMEI) = 15) then
if (master_packs.luhn_verify(IMEI) is True) then
update "master_SIMs".list SET "ICCID" = iccid, "phoneNumber" = phonenumber, "APN" = apn, "operator" = "Operator", "isESIM" = isesim, "isM2M" = ism2m, "MDI" = mdi, "IMSI" = imsi where IMEI = "serialNumber";
end if;
end if;
end;
$BODY$;
CALL "master_SIMs".simiccidlink1(352277818466409, 'iccid1', '8018466080', 'apn1', 'operator1', '0', '0', 123456789987653, 12354);
select * from "master_SIMs".list;
error I am getting is -
ERROR: procedure master_SIMs.simiccidlink1(unknown, unknown, unknown, unknown, integer, integer, integer, integer, bigint) does not exist
LINE 2: CALL "master_SIMs".simiccidlink1('iccid1', '8018466080', 'ap...
^
HINT: No procedure matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 7
I am new to this - please GUIDE.
I have tried all possible ways to fix it.

IBM Informix aggregate function

I need to develop some kind of function in a informix db, in order to split one string into multiple rows for example:
Column1
one,two,three,four
And my expected result is:
column1
one
two
three
four
What i was thinking is to create a function, that splits the string into multiple rows. My actual code is the next one :
create function split(text_splitted varchar(100), separator char(1))
returning varchar(100)
define splitted_word varchar(100);
define current_val char(1);
define start, cont integer;
let start = 0;
let splitted_word = "";
let current_val = "";
for cont = 0 to length(text_splitted)
let current_val = substr(text_splitted, cont, 1);
if current_val = separator then
let splitted_word = substr(text_splitted, start, cont - start);
let start = cont + 1;
return splitted_word with resume;
end if;
end for;
end function
If you execute the next statement, works find:
execute function split('hello.my.name.is', '.');
And the result is:
hello
my
name
this is perfect, but my problem is that when you launch a query with this function, and the function returns more than one row an error is raised. What i have been google, is that i need to create an aggregate function but i am not able to build this function. I am new in this kind of developing....
Here is the little documentation i found: http://www.pacs.tju.edu/informix/answers/english/docs/dbdk/is40/extend/04aggs3.html
Thanks!

How to call procedure with package type param in oracle?

In oracle DB, I created a custom type in a package and i guess this type is similar to integer array.
create or replace PACKAGE mypackage AS
TYPE custom1 is table of integer index by binary_integer;
END mypackage;
Used type in procedure IN param and expecting out param to be size of IN param.
CREATE OR REPLACE PROCEDURE MYPROCEDURE( param1 in mypackage.custom1, count1 out integer) IS
begin
count1 := param.count();
END MYPROCEDURE
Now I want to call above procedure,for this I should prepare mypackage.custom1.
Please help me in constructing mypackage.custom1 and call above procedure.
You have some errors in your code;
CREATE OR REPLACE PACKAGE mypackage AS
TYPE custom1 IS TABLE OF INTEGER
INDEX BY BINARY_INTEGER;
END mypackage;
CREATE OR REPLACE PROCEDURE MYPROCEDURE(param1 IN mypackage.custom1, count1 OUT INTEGER) IS
BEGIN
count1 := param1.COUNT();
END MYPROCEDURE;
To call your procedure, you simply need to define two variables and call the procedure with them; for example, in an anonymous block:
declare
v mypackage.custom1;
n number;
begin
select 1
bulk collect into v
from dual connect by level <= 5;
--
MYPROCEDURE(v, n);
dbms_output.put_line('n= ' || n);
end;
n= 5
The same way, you can build your stored procedures, packages, ... to call your procedure.
Executing above procedure with list of integers passing to custom type
SET SERVEROUTPUT = ON;
declare
v mypackage.custom1;
n number;
begin
v(0) := 10;
v(1) := 12;
v(2) := 14;
v(3) := 16;
--
MYPROCEDURE(v, n);
dbms_output.put_line('n= ' || n);
end;
output :
n = 4
Here is the JDBC code to invoke above procedure
String procedure = "call MYPROCEDURE(?, ?)";
CallableStatement callableStatement = con.prepareCall(procedure);
ArrayDescriptor ad = ArrayDescriptor.createDescriptor("mypackage.custom1", con);
ARRAY arr = new ARRAY(ad, con, new Integer[]{1,2,3,4});
callableStatement.setArray(1, arr);
callableStatement.registerOutParameter(2, Types.INTEGER);
final boolean execute = callableStatement.execute();
System.out.println("No of entries :" + callableStatement.getObject(2));
output :
No of entries : 4

Netcool/OMNIbus SQL procedure not running\doing nothing

So i have a tool that call procedure.
Tool looks like that:
call Attach_test('select TTID from alerts.status where Class in (73000,8891) and to_int(TTID) > 0 and ServerSerial in ($selected_rows.Serial)',[ $selected_rows.Serial ]); flush iduc;
it should get TTID (that field have only one of many selected alarms ) and array of server serials of selected alarms.
Then all this data is transfered to SQL procedure that looks like:
declare
tempservser integer; k integer;
begin
for k = 1 to array_len(serserial) do
begin
set tempservser = serserial[k];
update alerts.status set ParentTT = parentttid, TTFlag = 2 where ServerSerial = tempservser and TTID = '' ;
end;
end
Parameters:
in parentttid Char(11)
in serserial array of Integer
And here comes the trouble - procedure do nothing. There is no errors or something but there is no update on selected alarms.
I want it to work like this - you select many alarms with only one that have TTID, run this tool that set ParentTT = TTID on every other of selected alarms.
OS ver. 8.1
Sorry for my english
I figured out how to do it:
Tool
call AttachSelectedToTTID([ $selected_rows.Serial ],[ $selected_rows.ParentTT ]);
flush iduc;
Procedure
declare
tempservser integer; k integer;n integer;partt char(15);
begin
for n = 1 to array_len(ttid) do
begin
if (ttid[n] != '' ) then
set partt = ttid[n];
end if;
end;
for k = 1 to array_len(serserial) do
begin
set tempservser = serserial[k];
update alerts.status set ParentTT = partt,TTFlag = 2 where Serial = tempservser and TTID = '';
end;
end
Parameters:
in ttid array of Char(15)
in serserial array of Integer