postgresql查詢自動(dòng)將大寫(xiě)的名稱轉(zhuǎn)換為小寫(xiě)的案例
我就廢話不多說(shuō)了,大家還是直接看代碼吧~
SELECT sum(aa) as "recordNumber" FROM table SELECT sum(aa) as recordNumber FROM table
postgis查詢字段是將字段字段轉(zhuǎn)為小寫(xiě),如果需要大寫(xiě)的字符,需要加雙引號(hào)
補(bǔ)充:Postgresql中表名、列名、用戶名大小寫(xiě)問(wèn)題
注意:是雙引號(hào),單引號(hào)可能會(huì)被解析成普通字符,因而是不識(shí)別的字段
highgo=# create table "ExChange" (id int); CREATE TABLE highgo=# create table ExChange (id int); CREATE TABLE highgo=# \d List of relations Schema | Name | Type | Owner ----------------+----------+-------+-------- oracle_catalog | dual | view | highgo public | ExChange | table | highgo public | exchange | table | highgo public | myt | table | highgo public | t1 | table | highgo public | tran | table | highgo (6 rows) highgo=# insert into exchange values (1); INSERT 0 1 highgo=# insert into "ExChange" values (2); INSERT 0 1 highgo=# select * FROM exchange ; id ---- 1 (1 row) highgo=# select * FROM ExChange ; id ---- 1 (1 row) highgo=# select * FROM "ExChange" ; id ---- 2 (1 row) highgo=# insert into ExChange values (2); INSERT 0 1 highgo=# select * FROM "ExChange" ; id ---- 2 (1 row) highgo=# select * FROM exchange ; id ---- 1 2 (2 rows)
> 從上面可以看出,如果不加雙引號(hào),那么表名都會(huì)被轉(zhuǎn)化為小寫(xiě)。如果想要大小寫(xiě)混用,需要添加雙引號(hào)。
highgo=# create table exchange (ID int,id int);
ERROR: 42701: column "id" specified more than once
highgo=# create table exchange (ID int,name text);
CREATE TABLE
highgo=# select id from exchange ;
id
----
(0 rows)
highgo=# select ID from exchange ;
id
----
(0 rows)
highgo=# select "ID" from exchange ;
ERROR: 42703: column "ID" does not exist
LINE 1: select "ID" from exchange ;
highgo=# \d exchange
Table "public.exchange"
Column | Type | Modifiers
--------+---------+-----------
id | integer |
name | text |
highgo=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
aaa | | {}
gpadmin | Superuser, Create role, Create DB | {}
highgo | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
replica | Replication | {}
highgo=# create table AAA;
ERROR: 42601: syntax error at or near ";"
LINE 1: create table AAA;
^
highgo=# create user AAA;
ERROR: 42710: role "aaa" already exists
highgo=# create user "AAA";
CREATE ROLE
highgo=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
AAA | | {}
aaa | | {}
gpadmin | Superuser, Create role, Create DB | {}
highgo | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
replica | Replication | {}
實(shí)驗(yàn)證明,字段與用戶同樣會(huì)被自動(dòng)轉(zhuǎn)化為小寫(xiě),除非添加雙引號(hào)。 其實(shí)最好的辦法就是全部用小寫(xiě),這樣才能盡量減少問(wèn)題的出現(xiàn)。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章
如何為PostgreSQL的表自動(dòng)添加分區(qū)
這篇文章主要介紹了如何為PostgreSQL的表自動(dòng)添加分區(qū),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
postgreSQL 數(shù)字與字符串類型轉(zhuǎn)換操作
這篇文章主要介紹了postgreSQL 數(shù)字與字符串類型轉(zhuǎn)換操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12
PostgreSQL并行計(jì)算算法及參數(shù)強(qiáng)制并行度設(shè)置方法
這篇文章主要介紹了PostgreSQL 并行計(jì)算算法,參數(shù),強(qiáng)制并行度設(shè)置,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
postgresql數(shù)據(jù)庫(kù)使用說(shuō)明_實(shí)現(xiàn)時(shí)間范圍查詢
這篇文章主要介紹了postgresql數(shù)據(jù)庫(kù)使用說(shuō)明_實(shí)現(xiàn)時(shí)間范圍查詢,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01
postgreSQL自動(dòng)生成隨機(jī)數(shù)值的實(shí)例
這篇文章主要介紹了postgreSQL自動(dòng)生成隨機(jī)數(shù)值的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01
Postgresql 查看SQL語(yǔ)句執(zhí)行效率的操作

