| /* ----------------------------------------------------------------------- *//** |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| * @file avg_var.sql_in |
| * |
| * @brief SQL functions for average and variance |
| * @date September 2015 |
| * |
| * |
| *//* ----------------------------------------------------------------------- */ |
| |
| m4_include(`SQLCommon.m4') |
| |
| --------------------------------------------------------------------------- |
| -- Functions for user-defined aggregates |
| --------------------------------------------------------------------------- |
| -- normal |
| CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.avg_var_merge_states( |
| state1 double precision[], |
| state2 double precision[]) |
| RETURNS double precision[] AS 'MODULE_PATHNAME', 'avg_var_merge_states' |
| LANGUAGE C |
| IMMUTABLE STRICT |
| m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `NO SQL', `'); |
| |
| CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.avg_var_final( |
| state double precision[]) |
| RETURNS double precision[] AS 'MODULE_PATHNAME' |
| LANGUAGE C |
| IMMUTABLE STRICT |
| m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `NO SQL', `'); |
| |
| CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.avg_var_transition( |
| state double precision[], |
| x double precision) |
| RETURNS double precision[] AS 'MODULE_PATHNAME' |
| LANGUAGE C |
| IMMUTABLE STRICT |
| m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `NO SQL', `'); |
| --------------------------------------------------------------------------- |
| |
| --------------------------------------------------------------------------- |
| -- User-defined aggregates |
| --------------------------------------------------------------------------- |
| DROP AGGREGATE IF EXISTS MADLIB_SCHEMA.avg_var(DOUBLE PRECISION); |
| CREATE AGGREGATE MADLIB_SCHEMA.avg_var( |
| DOUBLE PRECISION) ( |
| |
| SFUNC=MADLIB_SCHEMA.avg_var_transition, |
| STYPE=double precision[], |
| FINALFUNC=MADLIB_SCHEMA.avg_var_final, |
| m4_ifdef(`__POSTGRESQL__', `', `prefunc=MADLIB_SCHEMA.avg_var_merge_states,') |
| INITCOND='{0, 0, 0}' |
| ); |