Home > Software design >  Only column name in where clause
Only column name in where clause

Time:09-27

with preparation as(
select a,
       b,
       c,
       regexp_like(a, 'example1|example2') as example
from database_X
)

select *
from preparation
where example

I have a query that looks like above and it seems to pull correct results. However, I do not understand how using only column name in where clause functions. Could anybody please explain how it works or refer me to any articles or something that explains the logic?

CodePudding user response:

WHERE clause requires a boolean condition and regexp_like returns a boolean, basically that's it. I.e. any expression resulting in a boolean is valid for WHERE, for example:

select * 
from table
where true

or

select * 
from table
where 1=1

CodePudding user response:

REGEXP_LIKE return boolean so you can use "example" in the where condition. It's the same query (but shorter) than :

with preparation as(
select a,
       b,
       c,
       regexp_like(a, 'example1|example2') as example
from database_X
)

select *
from preparation
where example is true
  • Related