0

I have the following SQL:

SELECT * FROM (SELECT t.id, t.summary, null as worker, tt.worked from ticket t
INNER JOIN (SELECT ticket, sum(seconds_worked)/3600.0 as worked FROM ticket_time GROUP BY ticket) tt ON tt.ticket=t.id
UNION ALL 
SELECT ticket,null, tt.worker, sum(tt.seconds_worked)/3600.0 from ticket_time tt GROUP BY ticket,worker) as foo
WHERE id in ('9755, 9759') ORDER BY id

The ids string '9755, 9759' in the last line can and will change whenever the sql executed. I can convert the sting to an array like this:

string_to_array('9755, 9759', ',')

But is there a way to convert this array of strings into array of integers?

1 Answer 1

1

Just cast the resulting array to an int[]

where id = ANY ( string_to_array('9755, 9759', ',')::int[] )
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! I'm knew to psql and tried to cast it as ::int4 instead.
Or just use an ARRAY literal in the first place, e.g. ANY (ARRAY[9755, 9759])
That was the problem - the core of the system I'm working here can't pass anything but a string, so I have to create an array from it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.