Conditional expresion in query - Mailing list pgsql-novice

From JORGE MALDONADO
Subject Conditional expresion in query
Date
Msg-id CAAY=A780HT7gzBmt2HhnsxAR26DzhLVo1HXXAPkiCE5k492+DA@mail.gmail.com
Whole thread Raw
List pgsql-novice
I have been reading about contidional expresions in a query and I have a question about the following example included in the documentation:

SELECT a,      CASE WHEN a=1 THEN 'one'           WHEN a=2 THEN 'two'           ELSE 'other'      END   FROM test;

I would like to make a few changes but I need to give a name (an alias) to the result of  the CASE. Can an "AS" be added as shown below?

SELECT a, b,      CASE WHEN a=b THEN a           ELSE a || '-' || b      END AS ab   FROM test;


Respectfully,
Jorge Maldonado


pgsql-novice by date:

Previous
From: Philip Couling
Date:
Subject: Re: Two Tables That Share Data?
Next
From: Carlos Mennens
Date:
Subject: Re: Two Tables That Share Data?