~ubuntu-branches/ubuntu/trusty/postgresql-8.4/trusty

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/array_userfuncs.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Copyright (c) 2003-2009, PostgreSQL Global Development Group
7
7
 *
8
8
 * IDENTIFICATION
9
 
 *        $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.28 2009/01/01 17:23:48 momjian Exp $
 
9
 *        $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.31 2009/06/20 18:45:28 tgl Exp $
10
10
 *
11
11
 *-------------------------------------------------------------------------
12
12
 */
474
474
Datum
475
475
array_agg_transfn(PG_FUNCTION_ARGS)
476
476
{
477
 
        Oid arg1_typeid = get_fn_expr_argtype(fcinfo->flinfo, 1);
 
477
        Oid                     arg1_typeid = get_fn_expr_argtype(fcinfo->flinfo, 1);
478
478
        MemoryContext aggcontext;
479
479
        ArrayBuildState *state;
480
480
        Datum           elem;
504
504
                                                         aggcontext);
505
505
 
506
506
        /*
507
 
         * The transition type for array_agg() is declared to be "internal",
508
 
         * which is a pass-by-value type the same size as a pointer.  So we
509
 
         * can safely pass the ArrayBuildState pointer through nodeAgg.c's
510
 
         * machinations.
 
507
         * The transition type for array_agg() is declared to be "internal", which
 
508
         * is a pass-by-value type the same size as a pointer.  So we can safely
 
509
         * pass the ArrayBuildState pointer through nodeAgg.c's machinations.
511
510
         */
512
511
        PG_RETURN_POINTER(state);
513
512
}
520
519
        int                     dims[1];
521
520
        int                     lbs[1];
522
521
 
 
522
        /*
 
523
         * Test for null before Asserting we are in right context.      This is to
 
524
         * avoid possible Assert failure in 8.4beta installations, where it is
 
525
         * possible for users to create NULL constants of type internal.
 
526
         */
 
527
        if (PG_ARGISNULL(0))
 
528
                PG_RETURN_NULL();               /* returns null iff no input values */
 
529
 
523
530
        /* cannot be called directly because of internal-type argument */
524
531
        Assert(fcinfo->context &&
525
532
                   (IsA(fcinfo->context, AggState) ||
526
533
                        IsA(fcinfo->context, WindowAggState)));
527
534
 
528
 
        if (PG_ARGISNULL(0))
529
 
                PG_RETURN_NULL();   /* returns null iff no input values */
530
 
 
531
535
        state = (ArrayBuildState *) PG_GETARG_POINTER(0);
532
536
 
533
537
        dims[0] = state->nelems;
534
538
        lbs[0] = 1;
535
539
 
536
 
        /* Release working state if regular aggregate, but not if window agg */
 
540
        /*
 
541
         * Make the result.  We cannot release the ArrayBuildState because
 
542
         * sometimes aggregate final functions are re-executed.
 
543
         */
537
544
        result = makeMdArrayResult(state, 1, dims, lbs,
538
545
                                                           CurrentMemoryContext,
539
 
                                                           IsA(fcinfo->context, AggState));
 
546
                                                           false);
540
547
 
541
548
        PG_RETURN_DATUM(result);
542
549
}