Baptiste Pernet
Baptiste Pernet

Reputation: 3384

How to query for a built string select

I would like to do something like

SELECT * FROM (
    SELECT ('reword#' || reword) || reword_faq as reword FROM me_review_entries re
) as re
WHERE re.reword = 'reword#2#SOME_FAQ'

I tried to do

SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE foo = 'reword#2#SOME_FAQ'

But I get:

ERROR:  column "foo" does not exist
LINE 2: WHERE foo = 'reword#2#SOME_FAQ'

Is the first way of doing the only way ? Or could I improve that ?

Upvotes: 2

Views: 75

Answers (1)

Schroedingers Cat
Schroedingers Cat

Reputation: 3139

I think it depends on your database, but the foo column does not exist except within the query, so you might have to do:

SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE ('reword#' || reword) || reword_faq = 'reword#2#SOME_FAQ'

Upvotes: 6

Related Questions