I have a table called Listing
with fields type
+ typeCustom
where type is a strict selection of values and when type is set to value "custom" I want to be able to dynamically resolve this as whatever is in my typeCustom
-field.
SELECT
(CASE WHEN "type" = 'custom' THEN "typeCustom" ELSE "type" END) as "typeResolved"
FROM "Listing"
My naive way and quick googling tells me I should do something like this.
CREATE FUNCTION Listing_typeResolved(Listing_row "Listing")
RETURNS TEXT
LANGUAGE sql
STABLE AS $$
SELECT (CASE WHEN "type" = 'custom' THEN "typeCustom" ELSE "type" END)
$$
However, it gives me the following error:
ERROR: missing FROM-clause entry for table "Listing"
LINE 5: SELECT (CASE WHEN "Listing"."type" = 'custom' THEN "Listin...
^
Side-note: I'm using Hasura so I want to do this in order to expose a computed field.