plpgsql error “RETURN NEXT cannot have a parameter in function with OUT parameters” in table-returning function

RETURN NEXT just returns what output parameters currently hold. The manual: If you declared the function with output parameters, write just RETURN NEXT with no expression. You object: There are no OUT parameters. Output parameters are declared among function parameters with the keyword OUT or INOUT, or implicitly in your RETURNS clause: RETURNS TABLE(column1 integer, … Read more

now() default values are all showing same timestamp

That is expected and documented behaviour: From the manual: Since these functions return the start time of the current transaction, their values do not change during the transaction. This is considered a feature: the intent is to allow a single transaction to have a consistent notion of the “current” time, so that multiple modifications within … Read more

PostgreSQL – set a default cell value according to another cell value

This is not possible with a simple DEFAULT value, as the manual clearly states: The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). You could use a trigger instead: CREATE OR REPLACE FUNCTION trg_foo_b_default() RETURNS trigger LANGUAGE plpgsql AS $func$ BEGIN — For just a … Read more

PostgreSQL: Query has no destination for result data

The stored procedure won’t just return the result of the last SELECT. You need to actually return the value: CREATE OR REPLACE FUNCTION fun() RETURNS text AS $$ BEGIN — …. RETURN(SELECT dblink_disconnect()); END $$ LANGUAGE plpgsql; You’re getting the error because Postgres expects the function to return something of type text, but your function … Read more