[pgsql-ayuda] arrays
hypatia@mail.internet.com.mx
hypatia@mail.internet.com.mx
Mon, 10 Apr 2000 15:19:37 -0500
"Roberto E. Ortega" escribió:
>
> Hola: queria saber como debo hacer el SQL para que me diga cuantos
> elementos tengo en un array. He creado un campo tipo array con cantidad de
> elementos variable y necesito saber de cada registro cuantos elementos tengo.
Revisando los fuentes de postgres, encuentro lo siguiente en la parte de
los tests de regresión:
8<---------------------------------------
--
-- ARRAYS
--
SELECT * FROM arrtest;
SELECT arrtest.a[1],
arrtest.b[1][1][1],
arrtest.c[1],
arrtest.d[1][1],
arrtest.e[0]
FROM arrtest;
-- ??? what about
-- SELECT a[1], b[1][1][1], c[1], d[1][1], e[0]
-- FROM arrtest;
SELECT arrtest.a[1:3],
arrtest.b[1:1][1:2][1:2],
arrtest.c[1:2],
arrtest.d[1:1][1:2]
FROM arrtest;
-- returns three different results--
SELECT array_dims(arrtest.b) AS x;
-- returns nothing
SELECT *
FROM arrtest
WHERE arrtest.a[1] < 5 and
arrtest.c = '{"foobar"}'::_name;
-- updating array subranges seems to be broken
--
-- UPDATE arrtest
-- SET a[1:2] = '{16,25}',
-- b[1:1][1:1][1:2] = '{113, 117}',
-- c[1:1] = '{"new_word"}';
SELECT arrtest.a[1:3],
arrtest.b[1:1][1:2][1:2],
arrtest.c[1:2],
arrtest.d[1:1][1:2]
FROM arrtest;
8<---------------------------------------
Y la salida esperada para el quinto Query es:
QUERY: SELECT array_dims(arrtest.b) AS x;
x
---------------
[1:1][1:2][1:2]
[1:2][1:2]
--
Espero que te sirva.
Saludos
Juan Pablo Rosas Durán
--------- Pie de mensaje -------------------------------------------
Archivo historico: http://tlali.iztacala.unam.mx/maillist/pgsql-ayuda
Cancelar inscripcion:
mail to: majordomo@tlali.iztacala.unam.mx
text : unsubscribe pgsql-ayuda