aggregate-functions


Creating an aggregate function fails


While looking for an aggregate function that returns the nth element of a collection I found the following solution:
CREATE OR REPLACE FUNCTION _final_nth( anyarray, integer )
RETURNS anyelement AS
$BODY$
SELECT a
FROM unnest( $1 ) a
ORDER BY a
offset $2
LIMIT 1;
$BODY$
LANGUAGE 'sql' IMMUTABLE;
CREATE AGGREGATE nth( anyelement, integer ) (
SFUNC=array_append,
STYPE=anyarray,
FINALFUNC=_final_nth,
INITCOND='{}'
);
Creating the function works fine but executing CREATE AGGREGATE produces the following error:
ERROR: function array_append(anyarray, anyelement, integer) does not exist
I am not able to resolve this error.
Maybe this will help:
CREATE OR REPLACE FUNCTION _final_nth( anyarray, integer )
RETURNS anyelement AS
$BODY$
SELECT a
FROM unnest( $1 ) a
ORDER BY a
offset $2
LIMIT 1;
$BODY$
Use it without an extra aggregate-function.
SELECT _final_nth(array_agg(someelement),n) AS someelement
FROM sometable
GROUP BY someelement;
n is the offset.

Related Links

rrdtool does not keep max
Tableau Aggregate Percentage
use aggregates (min, max, avg) in CONSTRUCT query [duplicate]
R: transposing and aggregating columns
SQL Query Aggregate Error
Usage of aggregate functions in MarkLogic
Querying customDimensions in Google Bigquery
NHibernate - QueryOver criteria appearing in Where instead in Having clause, error
Howto aggregate on full data set in Spring Batch jobs?
Creating an aggregate function fails
Necessity of declaration of function in c and cpp
Calculate window average in tableau
Complexity asymptotic relation (theta, Big O, little o, Big Omega, little omega) between functions
What are TOP_COUNT and TOP_MAXCOUNT in BigQuery?
marklogic need advise for approach to aggregate documents
multiply(num) aggregate function in postgresql

Categories

HOME
skype-for-business
optimization
gsm
gap-system
latex
x509certificate
itext7
query-string
crash
coordinates
zabbix
jquery-select2
markdown
rethinkdb
dcos
google-my-business-api
velocity
point-of-sale
box2d
multibinding
samba
airbnb
infinite-loop
devexpress-mvc
akavache
ballerinalang
stack-trace
gulp-jshint
large-files
scripting-language
cqlsh
ds-5
jsonapi-resources
webclient
asp.net-webhooks
pyenv
linkurious
blueimp
google-cloud-powershell
pexpect
result
cakephp-3.2
spring-webflow-2
easyquery
confluent
multivalue
enet
disassembly
robotc
cardview
recursive-query
computed-properties
toggleclass
mongodb-3.3
hdr
foreground
nimbus
sbt-proguard
angular-i18n
window.location
cexception
factorization
oryx
wordpress-plugin
fadein
cascading
web-performance
recode
tvp
play-json
callfire
vensim
opennebula
gcc-warning
jeet-grid
cl.exe
jsonmodel
react-os
visual-c#-express-2010
dateadd
class-library
infor-eam
zend-db-table
pyxplot
proj4
biztalk-deployment
qt5.1
freeimage
doxia
unordered-set
commonsware
jqzoom
apache-commons-email
cherokee
mass-emails
oaw
glassfish-embedded
mysql-pconnect
focus-stealing
datadude
ihtmldocument2
zend-acl

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App