PostgreSQL string_to_array group by 兩個列報錯
現象是這樣的,生產環境和測試環境資料相同,執行相同的SQL,生產報錯,測試環境沒有報錯,
原因其實是表結構不用,生產環境沒有主鍵,模擬復現如下:
生產環境
create table test(id int,name varchar(100)); insert into test values (1,'a,b'); insert into test values (2,'c,d,e'); select id, (string_to_array(name, ',')) as name1 from test e group by id; oss_ods@oss_ods-> group by id; ERROR: column "e.name" must appear in the GROUP BY clause or be used in an aggregate function LINE 3: (string_to_array(name, ',')) as name1 oss_ods@oss_ods=> select oss_ods@oss_ods-> id, oss_ods@oss_ods-> (string_to_array(name, ',')) as name1 oss_ods@oss_ods-> from oss_ods@oss_ods-> test e oss_ods@oss_ods-> group by id,name; id | name1 ----+--------- 1 | {a,b} 2 | {c,d,e} (2 rows)
測試環境
drop table test; create table test(id int,name varchar(100),constraint test_pk primary key(id)); insert into test values (1,'a,b'); insert into test values (2,'c,d,e'); oss_ods@oss_ods=> select oss_ods@oss_ods-> id, oss_ods@oss_ods-> (string_to_array(name, ',')) as name1 oss_ods@oss_ods-> from oss_ods@oss_ods-> test e oss_ods@oss_ods-> group by id,name; id | name1 ----+--------- 1 | {a,b} 2 | {c,d,e} (2 rows) oss_ods@oss_ods=> oss_ods@oss_ods=> select oss_ods@oss_ods-> id, oss_ods@oss_ods-> (string_to_array(name, ',')) as name1 oss_ods@oss_ods-> from oss_ods@oss_ods-> test e oss_ods@oss_ods-> group by id; id | name1 ----+--------- 2 | {c,d,e} 1 | {a,b} (2 rows)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-2919141/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- PostgreSQL的兩個模板庫SQL
- PostgreSQL DBA(186) - SQL Group BySQL
- 兩個報錯就想把我整懵嗎
- Mysql報錯注入原理分析(count()、rand()、group by)MySql
- 【Java面試】Spring 中,有兩個 id 相同的 bean,會報錯嗎,如果會報錯,在哪個階段報錯Java面試SpringBean
- PostgreSQL pg_rewind 報錯分析SQL
- group by 和 order by 一起使用,報錯 ORA-00979:不是 GROUP BY 表示式
- PostgreSQL DBA(169) - Develop(Distinct vs Group by)SQLdev
- Redis 佇列報錯Redis佇列
- mysql報錯:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggreMySqlExpressAI
- Laravel 中 sql 查詢 使用 group by 報錯問題。LaravelSQL
- 兩個棧實現佇列佇列
- 合併兩個有序陣列陣列
- 關於 Laravel 佇列報錯Laravel佇列
- 量子糾錯碼——Clifford group
- group by 引發的錯誤
- 將兩個有序陣列合併為一個有序陣列陣列
- 兩個有序陣列如何合併成一個有序陣列陣列
- 兩個棧實現佇列操作佇列
- 88、合併兩個有序陣列陣列
- 比較兩個陣列是否相等陣列
- js合併兩個陣列物件JS陣列物件
- MySQL5.7 group by新特性報錯1055的解決辦法MySql
- 349.兩個陣列的交集|python陣列Python
- 兩個有序陣列的中位數陣列
- leetcode 349. 兩個陣列的交集LeetCode陣列
- 88. 合併兩個有序陣列陣列
- 找到兩個陣列中的公共元素陣列
- 力扣之兩個陣列的交集力扣陣列
- LeetCode-349-兩個陣列的交集LeetCode陣列
- Laravel-查詢-ONLY_FULL_GROUP_BY SQL 模式-報錯限制-解決LaravelSQL模式
- gdb 除錯 new 一個物件主要兩個 handler除錯物件
- 一個關於php兩個陣列compare實踐PHP陣列
- Java 列舉、JPA 和 PostgreSQL 列舉JavaSQL
- 力扣-349. 兩個陣列的交集力扣陣列
- 每日一練(46):兩個陣列的交集陣列
- 【LeetCode】88. 合併兩個有序陣列LeetCode陣列
- LeetCode-350-兩個陣列的交集 IILeetCode陣列