Questions tagged [sql-parser]

Questions relating to code, libraries, or applications that parse SQL-style query languages.

129 questions
2
votes
1 answer

SQL Server's ow "batchparser.dll" - how to use it?

Is there a documented or at least vaguely documented way to make use of the SQL Server batchparser.dll that's hidden away deep inside the SQL Server directory structure (C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn)?…
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
2
votes
2 answers

python SQL parser to get the column name and data type

Im using the python SQL parser to get the table information. Im able to get the table name and schema name. import sqlparse line = ''' CREATE TABLE public.actor ( actor_id integer DEFAULT nextval('public.actor_actor_id_seq'::regclass) NOT NULL, …
TheDataGuy
  • 2,712
  • 6
  • 37
  • 89
2
votes
2 answers

IN in WHERE-clause is not being parsed correctly using SQL::Statement

I'm using a slightly modified version of the example provided here: https://metacpan.org/pod/distribution/SQL-Statement/lib/SQL/Statement/Structure.pod use SQL::Statement; use Data::Dumper; my $sql = q{ SELECT c1 , col2 as c2 , c3 FROM…
Jerome Provensal
  • 931
  • 11
  • 22
2
votes
0 answers

Using filter for count annotation with Djongo

Currently I'm using Django and a MongoDB configured with Djongo. These are my 2 classes: class Machine (models.Model): machine_type = models.ForeignKey(MachineType, related_name ='machine_types', on_delete = models.CASCADE) machine_customer =…
2
votes
1 answer

extract all column names from an SQL query in Python using sqlparse

I am trying to extract all the column names from a given SQL query ( MySQL to start with). I am using sqlparser module in python. I have a simple code to fetch the columns until the "from" keyword is reached. How do I get column names from rest of…
akshay pai
  • 122
  • 12
2
votes
1 answer

Parse sql select statement to fetch the where clause conditions in python

I have a sql query and I want to fetch all the conditions in where clause into a Python dictionary. e.g., import sqlparse s = "select count(*) from users where employee_type = 'Employee' AND (employment_status = 'Active' OR employment_status = 'On…
Krishnachandra Sharma
  • 1,332
  • 2
  • 20
  • 42
2
votes
0 answers

General SQL Parser - Parse Oracle PL/SQL

We are using SQLParser to check for syntax errors in Oracle SQL sentences. I saw that the library supports PL/SQL, however, we are having issues parsing the following SQL: declare newSeq number; begin select MAX(id_organization) + 1 into newSeq…
Fede E.
  • 2,118
  • 4
  • 23
  • 39
2
votes
1 answer

Declaration of ReplaceProcessor::process($tokenList) must be compatible with InsertProcessor::process($tokenList, $token_category = 'INSERT')

I'm using PHP SQL Parser. Working fine last few months I upgrade PHP 7.2 Then I got the error like. > Declaration of ReplaceProcessor::process($tokenList) must be > compatible with InsertProcessor::process($tokenList,…
Siddhu
  • 241
  • 2
  • 3
  • 16
2
votes
1 answer

Error in 'sqlparse' module in python with stored procedures syntax

I am trying to use split method in sqlparse module to split the queries file into queries list. When I use, 'create procedure' query, it is splitting correctly. But when I use 'replace procedure', it is splitting a single query into two queries. It…
2
votes
2 answers

Apache Calcite to Find Selected Columns in an SQL String

I have a use case where I want to know the columns which have been selected in an SQL string.For instance, if the SQL is like this: SELECT name, age*5 as intelligence FROM bla WHERE bla=bla Then, after parsing the above String, I just want the…
Saurabh
  • 139
  • 2
  • 9
2
votes
1 answer

Python parse SQL and find relationships

I've got a large list of SQL queries all in strings, they've been written for Presto, so kinda formatted for MySQL. I want to be able to tease out the table relationships written in some queries. Let's start with something simple: SELECT…
edumike
  • 3,149
  • 7
  • 27
  • 33
2
votes
2 answers

Can't import packages from jsqlparser library

I added the jar jsqlparser-0.7.0 to my Netbeans IDE (right clic on libraries / Add Jar file) but i still can't use its packages. what could be the reason . The library is created on 2011 it could be it is not supported by JDK7?
Mikou
  • 99
  • 6
2
votes
1 answer

PHP library for parsing mysql create queries and getting difference with exists tables

I search PHP library that gets "CREATE TABLE" query and returns difference if this table already exists For example I have table "table1" id (int11) | name (varchar64) ---------------------------- Then I parse query: CREATE TABLE table1 id int(11),…
Ildar
  • 798
  • 2
  • 14
  • 35
2
votes
2 answers

Stored Procedure Parser

I am trying to parse through hundreds of stored procedures to specifically grab their output variables "@FirstName", which tables they use, and which fields they pull from "MyTbl.FirstName". I am able to collect the variables pretty easily but I'm…
2
votes
0 answers

Microsoft.SqlServer.TransactSql.ScriptDom : TSqlTokenType

When parsing in a SQL query like: SELECT g.A, g.B, g.C FROM dbo.Goat g inner join dbo.Badger b on g.A=b.A and iterating through TSqlParserToken there is a Property called TokenType. I get the following: SELECT Select WhiteSpace g …
dandcg
  • 442
  • 4
  • 16
1
2
3
8 9