Re: First Aggregate Funtion? - Mailing list pgsql-hackers

From sudalai
Subject Re: First Aggregate Funtion?
Date
Msg-id 1437399622145-5858584.post@n5.nabble.com
Whole thread Raw
In response to Re: First Aggregate Funtion?  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: First Aggregate Funtion?
List pgsql-hackers
>I don't think so, because arrays can contain duplicates.
  I just add two element to the array.  One for INITCOND value NULL, second
for first row value.
So Array size is always 2.  So no duplicates. 

>rhaas=# select coalesce(first(x.column1), 'wrong') from (values
>(null), ('correct')) x;>coalesce
>----------
> wrong
>(1 row)
It works correct.. 
I didn't said it returns, first non-null value for a column  from aggregate
window. I said my implementation returns first row value  for a column. 
Here first row element is "null ", hence it returns null. 


check this....
db=# select 
db-# coalesce(first(x.column1),'null') as col1 , 
db-# coalesce(first(x.column2),'null') as col2,
db-#  coalesce(first(x.column3),'null') as col3 
db-# from (values (null,'abc',null), ('correct','wrong','notsure'),
('second','second1','second3')) x 
db-# ;col1 | col2 | col3 
------+------+------null | abc  | null
(1 row)

Its work correct. It returns first row value for a column. 

--Sudalai



-----
sudalai
--
View this message in context: http://postgresql.nabble.com/First-Aggregate-Funtion-tp1943031p5858584.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: patch: enhanced DROP POLICY tab complete
Next
From: Tom Lane
Date:
Subject: Re: [BUGS] object_classes array is broken, again