Questions relating to code, libraries, or applications that parse SQL-style query languages.
Questions tagged [sql-parser]
129 questions
0
votes
0 answers
ZetaSQL - catalog registration for nested complex types (Array of Record/Struct)
I am using ZetaSQL to analyze statements (Analyzer.analyzeStatements) coming from GCP audit log, particularly, the queries executed from BigQuery.
Usually, for simple queries, the way I register it into a catalog is by creating a SimpleTable with…

Jay-r Bangit
- 59
- 1
- 9
0
votes
1 answer
Python Sqlparser - Replace :: with cast()
I am trying to create a script which will convert Redshift SQL into SparkSQL. One specific conversion is giving me troubles - converting '::' into cast() function. Sql parser seems to mark '::' as punctuation, and doesn't parse out the entire…

shong555
- 49
- 7
0
votes
1 answer
split queries with regex
#i am using regex to split this but i am getting wrong results.
import re
queries ="""
INSERT ignore into persons VALUES (15,'Tom D.', 'Erilchsen',
'Skagen 21', 'Erlangen');
select * from persons;
"""
regex = "[;!]+?"
y = re.split(regex…

asheer ali
- 9
- 2
0
votes
1 answer
What is the relevant rules of Flink Window TVF and CEP SQL?
I am trying to parse Flink windowing TVF sql column level lineage, I initial a custom FlinkChainedProgram and set some Opt rules.
Mostly works fine except Window TVF SQL and CEP SQL.
for example, I get a logical plan as
insert into sink_table(f1,…

slo
- 23
- 5
0
votes
1 answer
Invalid expression / Unexpected token While using sqlglot to fetch all the columns used in the where clause
sql_query = "select T.lk1,T1.lk1 as dc_lk1, T.BB_NOW_name,T.City,T.DC_name,T.SKU_code,T.SKU_description,T.Brand,T.Manufacturer,T.From_Date,T.To_date,…

Raj
- 1
- 1
0
votes
1 answer
How to extract column names along with conditions from a SQL query using python
How to extract column names along with their conditions applied from a SQL query string using Python, so that I can map the result to other table and get the required data?
query = "SELECT COUNT(*) as cnt FROM dbo.main_table WHERE (VKRKA10001920015…

vikas madoori
- 147
- 1
- 11
0
votes
1 answer
Is there a good way to parse sql case statement?
The goal is to parse the sql statement in Python, and I have some difficulties using sqlparse to parse the case statement. I have tried the method in this link Parse CASE WHEN statements with sqlparse, but the result becomes messy when the data set…

Gabriel JIANG
- 1
- 1
0
votes
0 answers
Why am I getting antlr.MismatchedTokenException thrown for simple SQL query parsing (.NET)?
Queries are read fine when debugging only My Code. However, when disabling the option in Visual Studio in 'Debug > Options > Enable Just My Code', antlr.MismatchedTokenException is thrown for almost every SQL query which is run through the…

chairmanbertie
- 21
- 2
0
votes
1 answer
import sqlparse ModuleNotFoundError: No module named 'sqlparse'
I have installed
pip install sqlparse
pip3 install sqlparse
conda install sqlparse
But still getting sqlparse module error
Why is that?
(New4) C:\Users\zesha\Documents\GitHub\django-blog>python manage.py makemigrations
Traceback (most recent call…

NobinPegasus
- 545
- 2
- 16
0
votes
2 answers
Parsing two SQL statements using split , the result is incorrect
>>> import sqlparse
>>> t_sql = """create table dmc_o2_test(
... stuid number(38) primary key,
... stuname varchar2(30) not null
... )
...
... select * from dmc_o2_test;"""
>>>
>>>
>>> sqlparse.split(t_sql)
['create table…

caiyi0923
- 9
- 1
0
votes
2 answers
Get and Add WHERE clause in SQL Query Python
I am coding in Python. I have query like this:
SELECT device_os, count(*) FROM warehouse WHERE device_year <= 2016 GROUP BY device_os;
Now, I have some additional filters which are coming dynamically from the user. For example,
device_id IN (15,…

Muhammad Muaaz
- 164
- 1
- 13
0
votes
1 answer
Anorm replacement of params gives error on usage of aggregate functions
Table structure -
create table test
(month integer,
year integer,
thresholds decimal(18,2)
);
Static insert for simulation -
insert into test(month,year,threshold) values(4,2021,100),(5,2021,98),(6,2021,99);
If I query postgres database using…

ForeverLearner
- 1,901
- 2
- 28
- 51
0
votes
0 answers
Invalid placeholder character in C# for SQL query
I was trying to execute the query. But somehow I'm getting "Invalid placeholder character" error.
public static DataTable GetOrderItem(TransactionContext tc, int challanID)
{
string sql = string.Empty;
sql = SQLParser.MakeSQL(@"Select…
0
votes
1 answer
SQLParse - issue with the wildcard LIKE condition
I'm focusing on the Where clause of a SQL statement and I'm trying to pull back all the columns used in the Where clause. Below is an example SQL:
sql_2 = """Select
PERS_ID
, STF_NO
, NAME
FROM
TEST T
WHERE T.JOIN_DT >= T.POSTING_DT'
AND…

MrPaul91
- 57
- 5
0
votes
2 answers
Tuple Index Out of Range - but only when run in a function
I'm trying to write a process using SQLParse which lists the tables present in an SQL statement, currently focusing on the 'FROM' clause of the query. I'm also trying identify nested queries (or subqueries) within the FROM clause and run the process…

MrPaul91
- 57
- 5