为什么PostgreSQL不喜欢大写表名?

编程入门 行业动态 更新时间:2024-10-28 20:23:44
本文介绍了为什么PostgreSQL不喜欢大写表名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近尝试在PostgreSQL中创建所有大写形式的表。但是,为了查询它们,我需要将表名放在 TABLE_NAME中。有什么办法可以避免这种情况,并告诉Postgres正常使用大写名称?

I have recently tried to create some tables in PostgreSQL all in uppercase names. However in order to query them I need to put the table name inside the "TABLE_NAME". Is there any way to avoid this and tell the postgres to work with uppercase name as normal ?

UPDATE

此查询使用小写的 table_name

this query create a table with lowercase table_name

create table TABLE_NAME ( id integer, name varchar(255) )

但是,此查询创建的表具有大写名称 TABLE_NAME

However, this query creates a table with uppercase name "TABLE_NAME"

create table "TABLE_NAME" ( id integer, name varchar(255) )

问题是引号现在是名称的一部分!!在我的情况下,不是手动创建表,而是由另一个应用程序创建表,并且名称以大写字母表示。当我想通过以下方式使用 CQL 过滤器时,这会导致问题Geoserver。

the problem is the quotations are part of the name now!! in my case I do not create the tables manually, another Application creates the table and the names are in capital letters. this cause problems when I want to use CQL filters via Geoserver.

推荐答案

如果希望postgres保留关系名称的大小写,请将表名称放在双引号中。

put table name into double quotes if you want postgres to preserve case for relation names.

引用标识符也使其区分大小写,而未引用的名称总是折叠为小写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.)

来自文档(重点是我的)

示例引用:

t=# create table "UC_TNAME" (i int); CREATE TABLE t=# \dt+ UC t=# \dt+ "UC_TNAME" List of relations Schema | Name | Type | Owner | Size | Description --------+----------+-------+----------+---------+------------- public | UC_TNAME | table | postgres | 0 bytes | (1 row)

没有引用的示例:

t=# create table UC_TNAME (i int); CREATE TABLE t=# \dt+ UC_TNAME List of relations Schema | Name | Type | Owner | Size | Description --------+----------+-------+----------+---------+------------- public | uc_tname | table | postgres | 0 bytes | (1 row)

因此,如果您创建带引号的表格,则不应跳过引号查询它。但是,如果您跳过创建对象的引号,则名称会被折叠成小写,因此查询中的名称也将变为大写-这样您就不会注意到它。

So if you created table with quotes, you should not skip quotes querying it. But if you skipped quotes creating object, the name was folded to lowercase and so will be with uppercase name in query - this way you "won't notice" it.

更多推荐

为什么PostgreSQL不喜欢大写表名?

本文发布于:2023-10-14 22:55:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不喜欢   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!