Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » PostgreSQL »

array_length en postgres 8.3

Estas en el tema de array_length en postgres 8.3 en el foro de PostgreSQL en Foros del Web. Saludos, el tema es el siguiente: bajo postgres 8.3 no se soporta la funcion array_length, cuando quiero ejecutar una consulta como: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código SQL: ...
  #1 (permalink)  
Antiguo 07/10/2011, 06:44
Avatar de djmashe  
Fecha de Ingreso: julio-2007
Ubicación: Posadas, Misiones
Mensajes: 52
Antigüedad: 16 años, 9 meses
Puntos: 2
Exclamación array_length en postgres 8.3

Saludos, el tema es el siguiente: bajo postgres 8.3 no se soporta la funcion array_length, cuando quiero ejecutar una consulta como:

Código SQL:
Ver original
  1. -- Function: texto_array((text[])
  2. DROP FUNCTION IF EXISTS texto_array(text[]);
  3. CREATE OR REPLACE FUNCTION texto_array(text[])
  4.   RETURNS text AS
  5. $BODY$
  6. DECLARE
  7. BEGIN
  8.   FOR i IN 1..(array_length(array[1,2,3], 1)) LOOP
  9.     raise notice '%', i;
  10.   END LOOP;
  11.   RETURN TRUE;
  12. END;
  13. $BODY$
  14. LANGUAGE 'plpgsql';
  15. ALTER FUNCTION texto_array(text[]) OWNER TO postgres;

Da el siguiente error:

ERROR: function array_length(integer[], integer) does not exist
LINE 1: SELECT (array_length(array[1,2,3], 1))


¿Que alternativa existe para poder contar la cantidad de elementos de un array?
¿Y como se contaria en el caso de arrays bidimensionales o tridimensionales?

Desde ya gracias.
  #2 (permalink)  
Antiguo 07/10/2011, 18:22
Avatar de huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: array_length en postgres 8.3

prueba la función array_upper.

nos cuentas como te va.

saludos
__________________
Without data, You are another person with an opinion.
W. Edwads Deming
  #3 (permalink)  
Antiguo 11/10/2011, 08:32
Avatar de djmashe  
Fecha de Ingreso: julio-2007
Ubicación: Posadas, Misiones
Mensajes: 52
Antigüedad: 16 años, 9 meses
Puntos: 2
De acuerdo Respuesta: array_length en postgres 8.3

Gracias huesos52 por la rta. A continuacion dejo el script con la solucion:

Código SQL:
Ver original
  1. -- Function: texto_array()
  2. DROP FUNCTION IF EXISTS texto_array();
  3. CREATE OR REPLACE FUNCTION texto_array()
  4.   RETURNS text AS
  5. $BODY$
  6. DECLARE
  7.   arreglo text[];
  8.   total INTEGER := 0;
  9. BEGIN
  10.   arreglo := array[1,2,3];
  11.  
  12.   total := array_upper(arreglo, 1) - array_lower(arreglo, 1) + 1;
  13.   raise notice 'Total elementos: %', total;
  14.  
  15.   FOR i IN 1 .. total LOOP                      -- version < 8.4
  16.   --FOR i IN 1..(array_length(arreglo, 1)) LOOP -- version > 8.4
  17.     raise notice '%', i;
  18.   END LOOP;
  19.   RETURN TRUE;
  20. END;
  21. $BODY$
  22. LANGUAGE 'plpgsql';
  23. ALTER FUNCTION texto_array() OWNER TO postgres;

Etiquetas: postgres, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:53.