1

This should be simple one. A query like

SELECT code_id FROM code WHERE status = 1

gives normally a result like

code_id
10
11
12

But my goal is to fetch into a string like

10,11,12

In order to use it in an other query

SELECT x FROM table WHERE status in (10,12,13)

Preferable in the same query. Is this possible using "standard" Postgresql WITHOUT adding extra extension?

Everything so far is using extension that not are available as standard.

Thanks in advance.

sibert
  • 1,648
  • 8
  • 28
  • 53

2 Answers2

4

You can try this way to get result as comma-separated

But my goal is to fetch into a string like

SELECT string_agg(code_id, ',') FROM code WHERE status = 1
Always Sunny
  • 32,751
  • 7
  • 52
  • 86
4

Whatever tool you are using just shows you the data like that for convenience. But you can also use the resultset in a subquery, like this

SELECT x FROM table WHERE status in (
    SELECT code_id FROM code WHERE status = 1
)
fvu
  • 31,838
  • 5
  • 60
  • 78