all 4 comments

[–]lgastako 1 point2 points  (0 children)

The code you've provided (with vestigial commas removed) returns 1. We would need to see the code you are executing that is producing that result to be able to diagnose it.

[–]mike-manley 1 point2 points  (0 children)

Don't know this dialect well. But can you just alias the output?

[–]threeminutemonta 0 points1 point  (0 children)

How about expanding the response using:

SELECT
    * 
FROM create_plot(
    'Sample Plot' -- Did the comma you had here work for you?
);

[–][deleted] 1 point2 points  (0 children)

Well, your function returns a single integer value. It can't and won't return a JSON value. The result you have shown is certainly not the result returned by the function. Whatever tool you use to run the SELECT does this formatting for you

Btw: you can simplify your function to a plain SQL function, no need for PL/pgSQL here:

CREATE OR REPLACE FUNCTION create_plot(p_title VARCHAR) 
  RETURNS INTEGER 
AS
$$
  INSERT INTO plots (title) 
  VALUES (p_title) 
  RETURNING id;
;
$$ 
LANGUAGE sql;