5

I have written down this query in postgres sql with column alias it is working fine:

select email as e from users 

It displays me result under e column alias but when I fire where condition with e then it shows this error:

select email as e from users where e = 'jaskaransingh@demo.com'

ERROR: column "e" does not exist

Why so? How we can use alias in where condition?

potashin
  • 44,205
  • 11
  • 83
  • 107
Harman
  • 1,703
  • 5
  • 22
  • 40

1 Answers1

19

where is evaluated before select, so you can't use alias declared in select in where clause.

potashin
  • 44,205
  • 11
  • 83
  • 107
  • 3
    This is correct but makes me sad. Is there a good reason for this? Would be so useful to be able to refer to aliases in the `where` clause. – mitchus Oct 06 '20 at 13:47