Différences
Ci-dessous, les différences entre deux révisions de la page.
| cookbook:tableau_accumulateur [2008/10/14 18:24] – créée ioguix | cookbook:tableau_accumulateur [2008/10/15 16:47] (Version actuelle) – effacée ioguix | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Tableau Accumulateur ====== | ||
| - | Plutôt que de faire une somme, on peut avoir besoin de cumuler l' | ||
| - | |||
| - | <code sql> | ||
| - | CREATE AGGREGATE array_acc ( | ||
| - | BASETYPE = anyelement, | ||
| - | SFUNC = array_append, | ||
| - | STYPE = anyarray, | ||
| - | INITCOND = ' | ||
| - | ); | ||
| - | </ | ||
| - | |||
| - | Il s' | ||
| - | |||
| - | < | ||
| - | pgloader=# begin; | ||
| - | BEGIN | ||
| - | pgloader=# create table foo (a int, b text); | ||
| - | CREATE TABLE | ||
| - | pgloader=# insert into foo values(1, ' | ||
| - | INSERT 0 4 | ||
| - | pgloader=# CREATE AGGREGATE array_acc ( | ||
| - | pgloader(# BASETYPE = anyelement, | ||
| - | pgloader(# SFUNC = array_append, | ||
| - | pgloader(# STYPE = anyarray, | ||
| - | pgloader(# INITCOND = ' | ||
| - | pgloader(# ); | ||
| - | CREATE AGGREGATE | ||
| - | pgloader=# select a, array_acc(b) from foo group by a; | ||
| - | a | array_acc | ||
| - | ---+----------------- | ||
| - | 2 | {baz} | ||
| - | 1 | {foo, | ||
| - | (2 lignes) | ||
| - | pgloader=# rollback; | ||
| - | ROLLBACK | ||
| - | pgloader=# begin; | ||
| - | BEGIN | ||
| - | pgloader=# create table foo (a int, b text); | ||
| - | CREATE TABLE | ||
| - | pgloader=# insert into foo values(1, ' | ||
| - | INSERT 0 4 | ||
| - | pgloader=# CREATE AGGREGATE array_acc ( | ||
| - | pgloader(# BASETYPE = anyelement, | ||
| - | pgloader(# SFUNC = array_append, | ||
| - | pgloader(# STYPE = anyarray, | ||
| - | pgloader(# INITCOND = ' | ||
| - | pgloader(# ); | ||
| - | CREATE AGGREGATE | ||
| - | pgloader=# select a, array_acc(b) from foo group by a; | ||
| - | a | array_acc | ||
| - | ---+----------------- | ||
| - | 2 | {baz} | ||
| - | 1 | {foo, | ||
| - | (2 lignes) | ||
| - | |||
| - | pgloader=# rollback; | ||
| - | ROLLBACK | ||
| - | </ | ||
| - | |||
| - | -- \\ | ||
| - | Par dim le 05/06/2007 | ||