Código SQL:
Ver original
SELECT p_shops_and_sites(3,'11001',2,$$'01','02','03','04'$$,98,0,'',0.0,0.0) CREATE OR REPLACE FUNCTION p_shops_and_sites(INTEGER,VARCHAR,INTEGER,VARCHAR,INTEGER,DOUBLE PRECISION,VARCHAR,DOUBLE PRECISION,DOUBLE PRECISION) RETURNS SETOF t_shops_and_sites AS $BODY$ DECLARE SOURCE alias FOR $1; city alias FOR $2; filter_type alias FOR $3; filter_value alias FOR $4; category alias FOR $5; radio alias FOR $6; polygon alias FOR $7; cx alias FOR $8; cy alias FOR $9; TABLE_NAME VARCHAR; select_fields VARCHAR; SQL VARCHAR; where_conds VARCHAR; query_result t_shops_and_sites; BEGIN select_fields := 'SELECT ciudad,nombre_localidad AS localidad,nombre_barrio AS barrio,nombre_categoria AS categoria,nombre AS nom_establ,direccion,nivsocio,telefono,cx,cy,codigo_categoria'; where_conds := ' WHERE coddane = '||QUOTE_LITERAL(city)||' AND '; IF SOURCE = 1 THEN TABLE_NAME := ' FROM servcon_sitios_interes'; ELSE IF SOURCE = 2 THEN TABLE_NAME := ' FROM servcon_info2006_'||category; ELSE TABLE_NAME := ' FROM servcon_info2009_'||category; END IF; END IF; IF filter_type = 1 THEN where_conds := where_conds||' codigo_categoria = '||category; ELSE IF filter_type = 2 THEN where_conds := where_conds||' codigo_localidad IN ('||filter_value||') AND codigo_categoria = '||category; ELSE IF filter_type = 3 THEN where_conds := where_conds||' codigo_barrio IN ('||filter_value||') AND codigo_categoria = '||category; ELSE IF filter_type = 4 THEN where_conds := where_conds||' CIRCLE '||quote_literal('(('||cx||','||cy||'),'||radio||')')||' ~ POINT (cx,cy) AND codigo_categoria = '||category; ELSE where_conds := where_conds||' INTERSECTS(geom,GeometryFromText(('||QUOTE_LITERAL(polygon)||'), -1)) AND codigo_categoria = '||category; END IF; END IF; END IF; END IF; SQL := select_fields||TABLE_NAME||where_conds; FOR query_result IN EXECUTE SQL LOOP RETURN NEXT query_result; END LOOP; RETURN SQL; END $BODY$ LANGUAGE 'plpgsql'; CREATE TYPE t_shops_and_sites AS ( ciudad VARCHAR, localidad VARCHAR, barrio VARCHAR, categoria VARCHAR, nom_establ VARCHAR, direccion VARCHAR, nivsocio VARCHAR, telefono VARCHAR, cx DOUBLE PRECISION, cy DOUBLE PRECISION, codigo_categoria INTEGER);
adjunto el codigo del sp, del tipo creado para el retorno y la forma en como llamo el sp.
ya cree un sp alterno para verficar que el sql que ejecuto dinamicamente quedo bien armado y asi es. pero me aparece este error
ERROR: set-valued function called in context that cannot accept a set
CONTEXT: PL/pgSQL function "p_shops_and_sites" line 54 at return next
thanks