Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am converting multiple rows in to a array using array_agg() function, and i need to give that array to a select statements where condition.

My query is,

SELECT * FROM table WHERE id = 
  ALL(SELECT array_agg(id) FROM table WHERE some_condition)

but it gives error, how can i over come it..

share|improve this question
 
And which error? –  Audrius Meškauskas Apr 5 '13 at 6:23
 
what is the error you are getting?? –  hs.chandra Apr 5 '13 at 6:23
 
ERROR:operator does not exist: bigint = bigint[] HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. –  Sumither S Apr 5 '13 at 6:26
add comment

2 Answers

up vote 1 down vote accepted

the error has been cleared by type casting the array, using my query like this

 SELECT * FROM table WHERE id = 
    ALL((SELECT array_agg(id) FROM table WHERE some_condition)::bigint[])

reference link

share|improve this answer
add comment

It seems like you are over-complicating things. As far as I can tell, your query should be equivalent to simple:

SELECT * FROM table WHERE some_condition

Or, if you are selecting from 2 different tables, use join:

SELECT table1.*
FROM table1
JOIN table2 ON table1.id = table2.id
WHERE some_condition

Not only this is simpler, it is also faster than fiddling with arrays.

share|improve this answer
 
i need to take the count of the records, –  Sumither S Apr 5 '13 at 6:34
 
this was not mentioned in your question. what's wrong with SELECT count(*) ...? –  mvp Apr 5 '13 at 6:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.