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

SQL : Phrase coloured after 'As' clause #781

Open
meteorquake opened this issue Mar 27, 2024 · 1 comment
Open

SQL : Phrase coloured after 'As' clause #781

meteorquake opened this issue Mar 27, 2024 · 1 comment

Comments

@meteorquake
Copy link

meteorquake commented Mar 27, 2024

Thanks for all the updates since I last posted!

For SQL, I wonder how easy it would be to add a colour option for the phrase after an "As" clause, as this would highlight the alias name of user-defined fields. It would make life vastly easier in long SQL statements to have those names stand out.
So e.g.

first||second as fullname,
first||second as "full name",
first||second as 'full name',
first||second as `full name`,
first||second as [full name]

would all highlight the fullname/full name (the delimiters could be highlighted or not, probably not)

In the case of the From, the As is optional but I think if simplicity is required the As could trigger it, though it wouldn't be too hard to spot an implied table-type As
So e.g. -

From (select ...) As fullname
From (select ...) fullname
Join (select ...) As fullname
Join (select ...) fullname

etc

Cheers, David

@meteorquake
Copy link
Author

meteorquake commented Mar 29, 2024

Extra note to this, 'As' can also be used in some SQL for casting (e.g. MySql) -
CAST(expression AS newtype)
So the 'As' referred to here should not be within function brackets.
I think that can be computed by starting a new bracket count when a Select keyword is encountered.
So in this example

Select * From (
Select *, val*prob AS valprob, Cast(age AS int) From table
Where Cast(age as int)<50
) tblalias

the first bracket ups the bracket count to 1 but the second 'Select' then pushes the bracket count on a select-stack and restarts the bracket count at 0, and when it closes off (brackets becoming 0, at ") tblalias" there) the select-stack is popped to get the prior bracket count (as 1, immediately reduced to 0 by the bracket) and continues... this distinguishes function brackets from subquery brackets.

However it might be simpler just to colour the word-phrase after every As but watch for the word Cast and when As occurs within Cast() don't colour the word-phrase that follows the As within it. The advantage of the more complex method is that it can be used to colour table aliases implied without any 'As' (the tblalias in the example, which is short for As tblalias).
However I think the main utility is for highlighting calculated field names and if people want it to be used for table aliases too they just need to include the table alias 'As'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants