File: intagg--1.0.sql

package info (click to toggle)
postgresql-9.1 9.1.21-0%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 109,588 kB
  • sloc: ansic: 578,671; sql: 44,674; yacc: 26,399; perl: 6,541; lex: 6,173; sh: 5,286; makefile: 3,847; asm: 65; sed: 15; python: 12
file content (35 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* contrib/intagg/intagg--1.0.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION intagg" to load this file. \quit

-- Internal function for the aggregate
-- Is called for each item in an aggregation
CREATE FUNCTION int_agg_state (internal, int4)
RETURNS internal
AS 'array_agg_transfn'
LANGUAGE INTERNAL;

-- Internal function for the aggregate
-- Is called at the end of the aggregation, and returns an array.
CREATE FUNCTION int_agg_final_array (internal)
RETURNS int4[]
AS 'array_agg_finalfn'
LANGUAGE INTERNAL;

-- The aggregate function itself
-- uses the above functions to create an array of integers from an aggregation.
CREATE AGGREGATE int_array_aggregate (
	BASETYPE = int4,
	SFUNC = int_agg_state,
	STYPE = internal,
	FINALFUNC = int_agg_final_array
);

-- The enumeration function
-- returns each element in a one dimensional integer array
-- as a row.
CREATE FUNCTION int_array_enum(int4[])
RETURNS setof integer
AS 'array_unnest'
LANGUAGE INTERNAL IMMUTABLE STRICT;