Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to extract table and its related columns from sql query? #1349

Open
vasudevla opened this issue Sep 23, 2021 · 2 comments
Open
Labels
question Further information is requested

Comments

@vasudevla
Copy link

vasudevla commented Sep 23, 2021

Question

For example,
If query is

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

I need something like below,

{
   "tableName":"Orders",
   "columns":[
      "OrderID",
      "OrderData",
      "CustomerID"
   ]
}

And

{
   "tableName":"Customers",
   "columns":[
      "CustomerName",
      "CustomerID"
   ]
}

I can extract table names and column names separately,
but is there anyway to extract table and its related columns?
or
Is it possible to extract table and its related columns in a single struct?

@vasudevla vasudevla changed the title How do I get table and its columns in a single struct How do I parse table and its columns in a single struct Sep 23, 2021
@kennytm kennytm added the question Further information is requested label Sep 23, 2021
@vasudevla vasudevla changed the title How do I parse table and its columns in a single struct Is it possible to parse table and its columns in a single struct? Sep 23, 2021
@vasudevla vasudevla changed the title Is it possible to parse table and its columns in a single struct? Is it possible to extract table and its related columns from sql query? Sep 27, 2021
@cjphaha
Copy link

cjphaha commented Oct 9, 2021

I think this is a good idea, but there seems no mehod, you can get table name from *ast.ColumnName.Table.String()

@penwyp
Copy link

penwyp commented Dec 1, 2021

you need a visitor to do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants