Comments (7)
stmt, err := sqlparser.Parse(sql)
if err != nil {
fmt.Println("Error: " + err.Error())
}
tableNames := make([]string, 0)
_ = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
switch node := node.(type) {
case sqlparser.TableName:
tableNames = append(tableNames, node.Name.CompliantName())
}
return true, nil
}, stmt)
fmt.Println(tableNames)
from sqlparser.
buffer:= sqlparser.NewTrackedBuffer(nil)
stmt.From.Format(buffer)
fmt.Println(buffer)
from sqlparser.
hey @Hassnain-Alvi can u please help
I am new to sqlParser and I am not able to know its usage
from sqlparser.
hey @Hassnain-Alvi can u please help
I am new to sqlParser and I am not able to know its usage
sure whats the problem you are facing ?
from sqlparser.
hey @Hassnain-Alvi can u please help
I am new to sqlParser and I am not able to know its usagesure whats the problem you are facing ?
I have started today only and I am unable to get through its documentation for parsing table name from simple expression
from sqlparser.
@Hassnain-Alvi I am not even able to use ins.Table.name reference your above mentioned code it shows error
from sqlparser.
stmt, err := sqlparser.Parse(sql) if err != nil { fmt.Println("Error: " + err.Error()) } tableNames := make([]string, 0) _ = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) { switch node := node.(type) { case sqlparser.TableName: tableNames = append(tableNames, node.Name.CompliantName()) } return true, nil }, stmt) fmt.Println(tableNames)
@raintean thanks for the solution but it's not valid if query has alias of the join or subquery. E.g. The result of this query select * from db.my_table as mt, (select * from db2.users) as u join db3.other_table ot on ot.user_id = u.id
is [my_table users other_table ot u]
which is not correct.
from sqlparser.
Related Issues (20)
- Node position
- This repo is out of date HOT 2
- Feature: Support for more SQL variants
- A question about using sqlparser to parse sql with placeholders
- how to bypass some sql keyword
- Does this parser detect sql injection?
- Multilevel qualifier treated as parse error
- parse error HOT 3
- Does it support nested queries/sub-quries HOT 1
- How to parse SQL procedure CALL
- Doesn't parse insert statement with `returning` clause
- Some table builder SQL parsing does not report an error but TableSpec is a null pointer HOT 2
- not supported between x and x
- syntax error at position 1262
- how parse 100G sql file to csv files?
- Doesn't parse postgresql extract(... from ...)
- Does it support "SELECT * FROM 11111.table1" ? HOT 3
- Can we suppot to parse 'row_number() OVER (PARTITION BY xx)'
- Is it possible for me to implement custom grammar
- Doesn't support the name of table starts with numbers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlparser.