parser icon indicating copy to clipboard operation
parser copied to clipboard

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

Open vasudevla opened this issue 3 years ago • 2 comments

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 avatar Sep 23 '21 05:09 vasudevla

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

cjphaha avatar Oct 09 '21 18:10 cjphaha

you need a visitor to do that

penwyp avatar Dec 01 '21 10:12 penwyp