Re: funciones ventana cual criterio emplea el order by para 'filtral'

From: Hellmuth Vargas <hivs77(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Lista Postgres ES <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: funciones ventana cual criterio emplea el order by para 'filtral'
Date: 2018-04-04 21:12:55
Message-ID: CAN3Qy4raR0Ckr=Zc+CK-y9DjstFwAfn9RvXfALHhHW90-L=_EA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola Alvaro

Siempre es que toca leer detalladamente la documentacion!! jejeje, claro la
verdad no le había puesto mucho cuidado al concepto de frame... muchas
gracias!

2018-04-04 15:55 GMT-05:00 Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>:

> Hellmuth Vargas escribió:
>
> > SELECT *,
> > array_agg(x) OVER () as todos,
> > array_agg(x) OVER (ORDER BY x) as order_asc,
> > array_agg(x) OVER (ORDER BY x DESC) as order_desc,
> > last_value(x) OVER (ORDER BY x)
> > FROM generate_series(1, 5) AS x order by 1;
> >
> > cuyos resultados son:
> >
> > x | todos | order_asc | order_desc | last_value
> > ---+-------------+-------------+-------------+------------
> > 1 | {1,2,3,4,5} | {1} | {5,4,3,2,1} | 1
> > 2 | {1,2,3,4,5} | {1,2} | {5,4,3,2} | 2
> > 3 | {1,2,3,4,5} | {1,2,3} | {5,4,3} | 3
> > 4 | {1,2,3,4,5} | {1,2,3,4} | {5,4} | 4
> > 5 | {1,2,3,4,5} | {1,2,3,4,5} | {5} | 5
> > (5 rows)
> >
> >
> > Y la verdad no entiendo la lógica del 'filtrado' que hace el order by
> > (ASC/DESC). Gracias Lista
>
> No es el ASC/DESC que hace filtrado. Y en realidad no se hace ningún
> filtrado;
> lo que se hace es definir el "frame". Como no lo especificas, la
> documentación
> indica cuál es la definición por omisión:
>
> The default framing option is RANGE UNBOUNDED PRECEDING, which is
> the
> same as RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW; it sets
> the
> frame to be all rows from the partition start up through the
> current
> row's last peer (a row that ORDER BY considers equivalent to the
> current row, or all rows if there is no ORDER BY).
> https://www.postgresql.org/docs/10/static/sql-select.html
>
> es decir, en cada registro, el frame es "todos los registros que vienen
> antes del registro actual (UNBOUNDED PRECEDING), y hasta el registro
> actual (CURRENT ROW)". Con el ASC/DESC del order by, cambias la
> definición de cuáles registros vienen "antes".
>
> --
> Álvaro Herrera https://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

--
Cordialmente,

Ing. Hellmuth I. Vargas S.
Esp. Telemática y Negocios por Internet
Oracle Database 10g Administrator Certified Associate
EnterpriseDB Certified PostgreSQL 9.3 Associate

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Kernel 2018-04-09 11:46:51 buscar referenciado
Previous Message Alvaro Herrera 2018-04-04 20:55:32 Re: funciones ventana cual criterio emplea el order by para 'filtral'