使用 "select trim" 时如何避免 postgresql 更改列名

How to avoid postgresql from changing column names when using "select trim"

我 运行 在我的 PostgreSql version 9.3 中进行以下查询(我正在使用 PgAdmin III):

Select trim(both ' ' from column1) from myTable

它 returns 我想要的数据,但它也将列名称从 'column1' 重命名为 'btrim'。我需要原始列名称,因为我正在使用来自 Java 应用程序的查询。这种重命名发生在我使用 Trim 函数的所有列上,无论我是直接在 pgAdmin 中 运行 查询还是通过我的 postgres jdbc driver (这就是为什么我认为问题出在postgres 本身)。

如何在使用 Trim 函数时获取正确名称的数据和列?

使用列别名:

Select trim(both ' ' from column1) AS column1 
from myTable

SqlFiddleDemo

如果您需要区分大小写的别名,您需要用 ".

将它们括起来

Idenfifiers:

Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other. (The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case. Thus, foo should be equivalent to "FOO" not "foo" according to the standard. If you want to write portable applications you are advised to always quote a particular name or never quote it.)