0

I am trying to create a function in PostgreSQL using this query:

create function cs.has_double_bridge(cs.nose_bridge_type) returns boolean as $$
  return $1 = 'double bridge';
$$ language plpgsql stable;

But I keep getting an error on the second line:

ERROR:  syntax error at or near "return"
LINE 2:   return $1 = 'keyhole';
          ^

I am not an expert in PostgreSQL, so I haven't been able to figure out the cause of the error. What am I doing wrong here?

1 Answer 1

1

As documented in the manual PL/pgSQL requires a BEGIN ... END block:

create function cs.has_double_bridge(cs.nose_bridge_type) 
  returns boolean 
as $$
begin
  return $1 = 'double bridge';
end;
$$ language plpgsql stable;

Alternatively you can use a SQL function instead:

create function cs.has_double_bridge(cs.nose_bridge_type) 
  returns boolean 
as $$
  select $1 = 'double bridge';
$$ language sql stable;
Sign up to request clarification or add additional context in comments.

2 Comments

Ah! I had it wrapped in begin/end but I think perhaps I had them indented... I'm not sure if that matters or not, so maybe I had another mistake.
Nope, the indentation does not matter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.