Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres wraps subquery results in parentheses

Tags:

postgresql

Don't pay attention to uselessness of the provided query, it's just a simplified part of a complex one.

I run query:

SELECT elem FROM (SELECT id FROM data) AS elem;

It yields the result:

 elem 
------
 (5)
 (4)
 (24)
 (3)
 (23)

Why does each value enclosed in parentheses?

So, to fix it I do:

SELECT trim(elem::text, ')(') FROM (SELECT id FROM data) AS elem;

I have a feeling it should not be that way...

like image 475
Sergey Onishchenko Avatar asked Oct 03 '17 06:10

Sergey Onishchenko


1 Answers

SELECT elem.id FROM (SELECT id FROM data) AS elem;
like image 183
Sergey Onishchenko Avatar answered Oct 03 '22 07:10

Sergey Onishchenko