最近才接觸到一個用PostgreSQL的項目,然后在開發的過程中發現了這樣的一個問題。
錯誤: 操作符不存在: character = integer
反正還有很多報錯的,原因都是類型的轉換問題。在mysql中似乎對類型這個概念不是那么敏感,而在PostgreSql中Integer 、Long、Date、String 等等之間轉換都會存在操作符不存在的報錯。
所以在使用非實體進行數據傳輸的時候,例如Map等等就需要手動設置數據類型。
Long orgId = (maps.get("orgId") != null maps.get("orgId").toString().length() > 0) ? Long.valueOf(maps.get("orgId").toString()) : null;
maps.put("orgId", orgId);
就可以利用maps進行判斷后再進行插入修改等操作,Date格式也同理。
補充:PostgreSQL一些簡單問題以及解決辦法
問題:
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
解決辦法:
Edit /var/lib/pgsql/data/postgresql.conf file
Change
#listen_addresses = 'localhost'
to
listen_addresses = '*'
問題:
org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "host_ip>", user "fkong", database "fkong", SSL off
解決辦法:
Edit /var/lib/pgsql/data/pg_hba.conf file
Add below line under "# IPv4 local connections:"
"host all all host_ip>/32 password"
問題:
org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user "fkong"
解決辦法:
Edit /var/lib/pgsql/data/pg_hba.conf file
Change
"host all all host_ip>/32 ident"
to
"host all all host_ip>/32 password"
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- Postgresql 賦予用戶權限和撤銷權限的實例
- postgresql限制某個用戶僅連接某一個數據庫的操作
- PostgreSQL用戶、數據庫及表的管理、操作與授權方式
- PostgreSQL 實現快速刪除一個用戶
- PostgreSQL 自定義自動類型轉換操作(CAST)
- postgresql 賦權語句 grant的正確使用說明