Questions relating to code, libraries, or applications that parse SQL-style query languages.
Questions tagged [sql-parser]
129 questions
2
votes
1 answer
Add statements to sql query in jsqlparser
I was wondering if it is possible to add an expression to a sql query using jsqlparser. For example I would like to add a column and a value to a sql statement:
original query: "INSERT INTO frontend(in_reply_to) VALUES (email);"
modified query:…

Alex
- 681
- 2
- 9
- 18
1
vote
2 answers
Usage of SQL parsers for java for search scenarios
Can anyone suggest some good implementation examples or usage scenarios where SQL parsers can be used for java.
I have an application where we need to filter data to be presented on UI based on certain parameters, sort criteria etc.
I have some…

saurzcode
- 827
- 12
- 30
1
vote
0 answers
Apache Calcite SQL parser not able to parse the SQL query with column or column alias having a number
Example query:
SELECT empid as 3_e FROM EMP;
Error:
Exception: org.apache.calcite.sql.parser.SqlParseException: Encountered "3" at line 1, column 17.
Was expecting one of:
...
...
…

Amit B
- 11
- 2
1
vote
1 answer
Antlr4 can't recognize a single number and bracket. I don't know what the problem is?
lexer grammar TransformLexer;
@header { package com.abc.g4.gen; }
channels { DPCOMMENT, ERRORCHANNEL }
@members {
/**
* Verify whether current token is a valid decimal token (which contains dot).
* Returns true if the character that…

hanhe
- 11
- 2
1
vote
0 answers
Getting token types in python sqlparse library
I am wokring on SQL code parser in python for further code analysis. I decided to use "sqlparse" python library and after parsing the text I would like to know particular token type such as "Identifier", "Keyword", ....
Globally after running:
raw…

Juraj
- 63
- 6
1
vote
2 answers
capture pattern_X repeatedly, then capture pattern_Y once, then repeat until EOS
[update:] Accepted answer suggests, this can not be done with the python re library in one step. If you know otherwise, please comment.
I'm reverse-engineering a massive ETL pipeline, I'd like to extract the full data lineage from stored procedures…

Lorinc Nyitrai
- 968
- 1
- 10
- 27
1
vote
0 answers
How to Remove SQL Comments from sql queries stored in data frame?
I have data which is stored in dataframe with one of the column (query column) contains sql queries. I want to remove all sql comments from all these sql queries in data frame and retain the query column along with other columns in data…

Nitesh Jha
- 11
- 2
1
vote
2 answers
How to correctly use group_concat with json_array() in mySQL ver 8.0.28-cll-lve
Scenario
I wish to SELECT from a table with simple varchar and integer columns and return a JSON representation of the whole table. This is so that later I can use PhP's curl() to send the 'table' to another server and reconstruct it. I'm using…

user2834566
- 775
- 9
- 22
1
vote
1 answer
Extract JSON representation of SQL query where clause with sqlparse
I'm trying to use python library sqlparse to extract the WHERE condition from a SQL statement and represent it in conditional JSON format. I'm interested only in the SQL condition, so the starting point is a dummy SQL statement, i.e. select * from…

Nicola
- 11
- 2
1
vote
1 answer
use python to extract database schema from existing sql queries
Given an SQL query, how can I programmatically extract schema information about the database it is querying? Ideally I would like to use Python to parse and extract info.
For example, the following SQL:
SELECT
rc.dateCooked,
r.name,
…

Selah
- 7,728
- 9
- 48
- 60
1
vote
1 answer
Parsing SQL query joins with python
I'm trying to parse out sql queries. I'm using the [moz-sql-parser][1] to identify the sql parts in a query and then writing a function parse out table names and columns that were joined on.
I have a sample query below :
join_query2 =…

adsthd
- 13
- 2
1
vote
1 answer
How to use sqlparse to parse sql statements
I am trying to parse all the queries executed by users (within a period of time) in PostgreSQL DB (by querying the pg_stat_statements table) and trying to create a report of which tables are used by users to run either a Select or an Insert or a…

P_Ar
- 377
- 2
- 9
- 25
1
vote
1 answer
How can I extract table names from sub queries using sqlparse?
I'm trying to extract all the table names in a query using sqlparse but I'm having trouble with subqueries or insert statements wrapped in parenthesis.
I have the following query,
import sqlparse
sql = """
create test.test_table as…

james rizkallah
- 11
- 2
1
vote
1 answer
How to get table names from join condition using gsqlarser?
I am trying to implement sqlparser and using gsqlparser from here. The source of the jar is in Java but I am implementing the same in Scala.
Below is my query which contains a join condition.
SELECT e.last_name AS name, e.commission_pct comm,…

Metadata
- 2,127
- 9
- 56
- 127
1
vote
0 answers
Customizing Calcite's Sql parser
I am trying to use Apache Calcite's SqlParser to get entity level lineage for my views written in Hive and Impala. However, the parser throws an exception for the following cases.
SELECT emp.1ab FROM emp -- Column name begins with…

Anand Kannan
- 141
- 3
- 8