Auto Complete: Add support for table aliases

Can we make auto-complete aware of aliased tables? Right now it only works for fully qualified schema tokens.

SELECT tableName.fieldName FROM tableName

could instead be

SELECT a.fieldName FROM tableName a

Ideally, auto-complete would acknowledge a as a new schema token and show the available fields on that table.

Related issue in GitHub: #3067

The approach I outlined in #3067 was to parse the SQL to get the aliases. I wonder if just applying a regex here to find the aliases will give us most of the value without the need to deep dive into parsing the query. :thinking:

Because it’s just autocomplete it doesn’t have to be 100% accurate. It’s nice if it is, but no harm is done if we miss a thing or have a false positive.

Could we use data source metadata to customize this? A default regex would be fine because most SQL flavors share aliasing semantics. But TSQL, for example, wraps column names in square brackets [ ] where others don’t. Custom regex by data source type would solve this.