Re: [pgsql-ayuda] arrays

From: hypatia(at)mail(dot)internet(dot)com(dot)mx
To: pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx
Subject: Re: [pgsql-ayuda] arrays
Date: 2000-04-10 20:19:37
Message-ID: 38F23759.9455A28C@mail.internet.com.mx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

"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�:

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�
--------- Pie de mensaje -------------------------------------------
Archivo historico: http://tlali.iztacala.unam.mx/maillist/pgsql-ayuda
Cancelar inscripcion:
mail to: majordomo(at)tlali(dot)iztacala(dot)unam(dot)mx
text : unsubscribe pgsql-ayuda

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message osky 2000-04-12 13:59:49 Re: [pgsql-ayuda] Importacion
Previous Message Ing. Roberto Andrade Fonseca 2000-04-10 15:01:53 [pgsql-ayuda] Ya el 7.0 Beta 5