I know I can specify a column alias like so:
SELECT stuff as mask
Is there a way I can specify a column alias without returning that column data in the result set? Essentially, I want to be able to make my query clean by doing:
SELECT doManipulationStuff(cleanCompactAlias)
Where
reallyLong.misleading.andAnnoying.columnName as cleanCompactAlias
You can use a Common Table Expression (CTE) to create a subquery with aliases:
WITH clean_cte AS
(
SELECT reallyLong.misleading.andAnnoying.columnName1 as cleanCompactAlias1,
reallyLong.misleading.andAnnoying.columnName2 as cleanCompactAlias2
)
SELECT doManipulationStuff(cleanCompactAlias1),
doManipulationStuff(cleanCompactAlias2)
That way you can put all of your aliasing in the CTE and just forget about it when calling your functions. You still have to do the aliasing somewhere, but this at least keeps it out of your main query to make it a bit more readable.
You could use a subquery:
select doManipulationStuff(cleanCompactAlias)
from (select t.*, reallyLong.misleading.andAnnoying.columnName as cleanCompactAlias
. . .
) t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With