greenplum 数组操作

参考:http://gpdb.docs.pivotal.io/4390/admin_guide/query/topics/functions-operators.html

Table 4. Advanced Analytic Functions
FunctionReturn TypeFull SyntaxDescription
matrix_add(array[], array[])smallint[], int[], bigint[], float[]matrix_add( array[[1,1],[2,2]], array[[3,4],[5,6]])Adds two two-dimensional matrices. The matrices must be conformable.
matrix_multiply( array[], array[])smallint[]int[], bigint[], float[]matrix_multiply( array[[2,0,0],[0,2,0],[0,0,2]], array[[3,0,3],[0,3,0],[0,0,3]] )Multiplies two, three- dimensional arrays. The matrices must be conformable.
matrix_multiply( array[], expr)int[], float[]matrix_multiply( array[[1,1,1], [2,2,2], [3,3,3]], 2)Multiplies a two-dimensional array and a scalar numeric value.
matrix_transpose( array[])Same as input arraytype.matrix_transpose( array [[1,1,1],[2,2,2]])Transposes a two-dimensional array.
pinv(array [])smallint[]int[], bigint[], float[]pinv(array[[2.5,0,0],[0,1,0],[0,0,.5]])Calculates the Moore-Penrose pseudoinverse of a matrix.
unnest (array[])set of anyelementunnest( array['one', 'row', 'per', 'item'])Transforms a one dimensional array into rows. Returns a set ofanyelement, a polymorphic pseudotype in PostgreSQL.
Table 5. Advanced Aggregate Functions
FunctionReturn TypeFull SyntaxDescription
MEDIAN (expr)timestamp, timestampz, interval, floatMEDIAN (expression)

Example:

SELECT department_id, MEDIAN(salary) 
FROM employees 
GROUP BY department_id; 
Can take a two-dimensional array as input. Treats such arrays as matrices.
PERCENTILE_CONT (expr) WITHIN GROUP (ORDER BYexpr [DESC/ASC])timestamp, timestampz, interval, floatPERCENTILE_CONT(percentage) WITHIN GROUP (ORDER BY expression)

Example:

SELECT department_id,
PERCENTILE_CONT (0.5) WITHIN GROUP (ORDER BY salary DESC)
"Median_cont"; 
FROM employees GROUP BY department_id;
Performs an inverse function that assumes a continuous distribution model. It takes a percentile value and a sort specification and returns the same datatype as the numeric datatype of the argument. This returned value is a computed result after performing linear interpolation. Null are ignored in this calculation.
PERCENTILE_DISC (expr) WITHIN GROUP (ORDER BYexpr [DESC/ASC])timestamp, timestampz, interval, floatPERCENTILE_DISC(percentage) WITHIN GROUP (ORDER BY expression)

Example:

SELECT department_id, 
PERCENTILE_DISC (0.5) WITHIN GROUP (ORDER BY salary DESC)
"Median_desc"; 
FROM employees GROUP BY department_id;
Performs an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification. This returned value is an element from the set. Null are ignored in this calculation.
sum(array[])smallint[]int[], bigint[], float[]sum(array[[1,2],[3,4]])

Example:

CREATE TABLE mymatrix (myvalue int[]);
INSERT INTO mymatrix VALUES (array[[1,2],[3,4]]);
INSERT INTO mymatrix VALUES (array[[0,1],[1,0]]);
SELECT sum(myvalue) FROM mymatrix;
 sum 
---------------
 {{1,3},{4,4}}
Performs matrix summation. Can take as input a two-dimensional array that is treated as a matrix.
pivot_sum (label[], label, expr)int[], bigint[], float[]pivot_sum( array['A1','A2'], attr, value)A pivot aggregation using sum to resolve duplicate entries.
mregr_coef(expr, array[])float[]mregr_coef(y, array[1, x1, x2])The four mregr_*aggregates perform linear regressions using the ordinary-least-squares method. mregr_coefcalculates the regression coefficients. The size of the return array formregr_coef is the same as the size of the input array of independent variables, since the return array contains the coefficient for each independent variable.
mregr_r2 (expr, array[])floatmregr_r2(y, array[1, x1, x2])The four mregr_*aggregates perform linear regressions using the ordinary-least-squares method. mregr_r2calculates the r-squared error value for the regression.
mregr_pvalues(expr, array[])float[]mregr_pvalues(y, array[1, x1, x2])The four mregr_*aggregates perform linear regressions using the ordinary-least-squares method. mregr_pvaluescalculates the p-values for the regression.
mregr_tstats(expr, array[])float[]mregr_tstats(y, array[1, x1, x2])The four mregr_*aggregates perform linear regressions using the ordinary-least-squares method. mregr_tstatscalculates the t-statistics for the regression.
nb_classify(text[], bigint, bigint[], bigint[])textnb_classify(classes, attr_count, class_count, class_total)Classify rows using a Naive Bayes Classifier. This aggregate uses a baseline of training data to predict the classification of new rows and returns the class with the largest likelihood of appearing in the new rows.
nb_probabilities(text[], bigint, bigint[], bigint[])textnb_probabilities(classes, attr_count, class_count, class_total)Determine probability for each class using a Naive Bayes Classifier. This aggregate uses a baseline of training data to predict the classification of new rows and returns the probabilities that each class will appear in new rows.

 

转载于:https://www.cnblogs.com/lvlin241/p/9378583.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值