Postgres将子查询结果用括号括起来 [英] Postgres wraps subquery results in parentheses

查看:165
本文介绍了Postgres将子查询结果用括号括起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不要注意所提供查询的无用性,它只是复杂查询的简化部分。

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

我运行查询:

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

其结果为:

 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...

推荐答案

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

这篇关于Postgres将子查询结果用括号括起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆