Why the error when I run the below in pgAdmin 4 query editor? I copied the create statement in one database and trying to move to a new server.
So I right clicked the function in pgAdmin and selected from the menu Scripts –> CREATE Script the generate the below code. Copied and executed into a new database.
-- FUNCTION: public.osmtrip_format(bigint, numeric, numeric)
-- DROP FUNCTION public.osmtrip_format(bigint, numeric, numeric);
CREATE OR REPLACE FUNCTION public.osmtrip_format(
num bigint,
length numeric,
tolerance numeric)
RETURNS bigint
LANGUAGE 'sql'
COST 100
IMMUTABLE
ROWS 0
AS $BODY$
SELECT
CASE WHEN $1=0 OR $2<=0.7*$3 THEN NULL ELSE $1 END;
$BODY$;
ALTER FUNCTION public.osmtrip_format(bigint, numeric, numeric)
OWNER TO gis;
ERROR: ROWS must be positive
SQL state: 22023
Best Answer
From the documentation about
CREATE FUNCTION
:ROWS 0
is not allowed even in those functions (should be positive).Since the function is not returning a set, you need to remove that
ROWS n
.