[Django]-PostgreSQL empty list VALUES expression

2👍

If you can put your lons and lats in separate arrays, you could use arrays with unnest:

select * from unnest(ARRAY[1, 2, 3]::int[], ARRAY[4, 5, 6]::int[]) as v(lon, lat);
 lon | lat
-----+-----
   1 |   4
   2 |   5
   3 |   6
(3 rows)

select * from unnest(ARRAY[]::int[], ARRAY[]::int[]) as v(lon, lat);
 lon | lat
-----+-----
(0 rows)

You’ll have to cast the arrays to the appropriate type (probably not int[]). Postgres will guess the type if the arrays aren’t empty, but it will throw an error if they are empty and you don’t cast them to a specific type.

👤Jeremy

Leave a comment