0

Let's say I have a query that returns the following:

Country
US
FR
UK
IT

Is it possible to use the result of that query to create a new query with columns as country names like the following:

US FR UK IT
0 0 0 0

My main goal is to create a new query dynamically in case the number of countries increases in the first query.

I am trying to avoid using postgresql extension tablefunc as it needs to be installed. The production db does not have the crosstab extension installed, so I am trying to avoid it. Thanks!

  • [Crosstab questions](https://stackoverflow.com/search?q=%5Bpostgresql%5D+and+%28%5Bpivot%5D+or+%5Bcrosstab%5D%29) –  Nov 21 '22 at 10:33
  • I don't want to install an extension to the prod db unless it is not possible to accomplish this task without crosstab extension. – Isa Ishangulyyev Nov 21 '22 at 10:38
  • You don't need the crosstab extensions. See [here](https://stackoverflow.com/a/58062286) or [here](https://stackoverflow.com/a/67549662) or [here](https://stackoverflow.com/questions/25938927/) or [here](https://stackoverflow.com/a/52392501/) or [here](https://stackoverflow.com/a/65965872/) –  Nov 21 '22 at 10:42

0 Answers0