Igual tenia el ultimo select mal hecho, muy mal hecho, ahora mi funcion es asi:
Código sql:
Ver originalCREATE OR REPLACE FUNCTION p_update_locales_in_count() RETURNS INTEGER AS $BODY$
DECLARE
query_count RECORD;
query_has_locales RECORD;
real_data RECORD;
BEGIN
FOR query_count IN SELECT neighborhood_code,city_code FROM conteo_manzanas_barrio_co LOOP
FOR query_has_locales IN SELECT has_locales FROM sm_city WHERE pk_city = query_count.city_code LOOP
IF query_has_locales.has_locales THEN
SELECT INTO real_data sl.pk_locale,sl.name
FROM sm_locale sl,sm_neighborhood sn,servcon_barrios sb
WHERE sn.pk_neighborhood = query_count.neighborhood_code AND
sl.fk_pk_city = query_count.city_code AND
sb.cod_localidad = sl.locale_code AND
sb.cod_barrio = sn.neighborhood_code AND
sl.name = sb.nom_localidad LOOP
UPDATE conteo_manzanas_barrio_co
SET locale_code = real_data.pk_locale, locale_name = real_data.name
WHERE neighborhood_code = query_count.neighborhood_code;
END IF;
END LOOP;
END LOOP;
RETURN 0;
END $BODY$
LANGUAGE plpgsql;
y al ejecutar el procedimiento me da arroja este error
ERROR: record "real_data" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: PL/pgSQL function "p_update_locales_in_count" line 12 at select into variables
En la declaración:
select p_update_locales_in_count()