FROM tree?

249 views
Skip to first unread message

Michael

unread,
Feb 6, 2015, 11:11:53 PM2/6/15
to sqlp...@googlegroups.com
I'm trying to parse out a list of tables referenced by a sql statement (and any subqueries within).  When I look at an identifier that belongs to FROM, it shows its parent as the SELECT. Is this a bug or is this usage not supported?  Is there an alternative way to do what I'm planning?

Thanks

Michael

unread,
Feb 8, 2015, 2:20:14 PM2/8/15
to sqlp...@googlegroups.com
I did find the extract_tables sample, but it isn't handling table aliases or ansi joins.  It's returning the aliases as the table name.  When I start debugging it, it looks like where clauses are being extracted as part of the from clause which seems strange to me.  I'll try to spend more time on it.

Amjith Ramanujam

unread,
Feb 8, 2015, 4:36:35 PM2/8/15
to sqlp...@googlegroups.com
Hi Michael,

I'm using sqlparse to extract table names in pgcli. I took the example and expanded it to address the corner cases you've identified. 

It's not the prettiest code but it gets the job done for the most part. 



--
You received this message because you are subscribed to the Google Groups "sqlparse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlparse+u...@googlegroups.com.
To post to this group, send email to sqlp...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlparse.
For more options, visit https://groups.google.com/d/optout.

Michael

unread,
Feb 8, 2015, 5:05:43 PM2/8/15
to sqlp...@googlegroups.com
Ohh very good, thanks.  I notice a couple cases that don't work with delete and update, but the selects and insert / select seem to work great. 

delete from x where x.id in ( select y.id from y );
update x set f1='Y' where x.id in ( select y.id from y, z );

I'll work on it later tonight and see if I get anywhere.  

Thanks!!
Reply all
Reply to author
Forward
0 new messages