Project

General

Profile

« Previous | Next » 

Revision 9959

schemas/util.sql: added all_same() aggregate

View differences:

util.sql
507 507

  
508 508

  
509 509
--
510
-- Name: all_same_final(anyarray); Type: FUNCTION; Schema: util; Owner: -
511
--
512

  
513
CREATE FUNCTION all_same_final(state anyarray) RETURNS boolean
514
    LANGUAGE sql IMMUTABLE
515
    AS $_$
516
SELECT $1 IS NULL/*no rows*/ OR util.not_empty($1)/*not no_match_sentinel*/
517
$_$;
518

  
519

  
520
--
521
-- Name: all_same_transform(anyarray, anyelement); Type: FUNCTION; Schema: util; Owner: -
522
--
523

  
524
CREATE FUNCTION all_same_transform(state anyarray, value anyelement) RETURNS anyarray
525
    LANGUAGE plpgsql IMMUTABLE
526
    AS $$
527
DECLARE
528
	value_cmp         state%TYPE = ARRAY[value];
529
	state             state%TYPE = COALESCE(state, value_cmp);
530
	no_match_sentinel state%TYPE = value_cmp[1:0]/*=ARRAY[]::state%TYPE*/;
531
BEGIN
532
	RETURN (CASE WHEN value_cmp IS NOT DISTINCT FROM state THEN state ELSE no_match_sentinel END);
533
END;
534
$$;
535

  
536

  
537
--
510 538
-- Name: cluster_index(regclass); Type: FUNCTION; Schema: util; Owner: -
511 539
--
512 540

  
......
1191 1219

  
1192 1220

  
1193 1221
--
1222
-- Name: all_same(anyelement); Type: AGGREGATE; Schema: util; Owner: -
1223
--
1224

  
1225
CREATE AGGREGATE all_same(anyelement) (
1226
    SFUNC = all_same_transform,
1227
    STYPE = anyarray,
1228
    FINALFUNC = all_same_final
1229
);
1230

  
1231

  
1232
--
1233
-- Name: AGGREGATE all_same(anyelement); Type: COMMENT; Schema: util; Owner: -
1234
--
1235

  
1236
COMMENT ON AGGREGATE all_same(anyelement) IS 'includes NULLs in comparison';
1237

  
1238

  
1239
--
1194 1240
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: util; Owner: -
1195 1241
--
1196 1242

  

Also available in: Unified diff