You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/24 02:32:14 UTC

[GitHub] [shardingsphere] peilinqian commented on issue #22375: If the select column doesn't only contain group by column,and the group by column is primary key,returns error.

peilinqian commented on issue #22375:
URL: https://github.com/apache/shardingsphere/issues/22375#issuecomment-1325870448

   **If the column of group by is not primary key ,opengauss is also returned erro**
   
   ```
   drop table if exists t_order; 
   drop table if exists t_merchant; 
   create table t_order (order_id int primary key, user_id int not null, status varchar(50) not null, merchant_id int not null, remark varchar(50), creation_date date);
   create table t_merchant (merchant_id int, country_id int not null, merchant_name varchar(50) not null, business_code varchar(50) not null, telephone varchar(50) not null, creation_date date not null);
   
   insert into t_order values(1000, 10, 'init', 1, 'test', '2017-07-08');
   insert into t_order values(1001, 10, 'init', 2, 'test', '2017-07-08');
   insert into t_order values(2000, 20, 'init', 3, 'test', '2017-08-08');
   insert into t_order values(2001, 20, 'init', 4, 'test', '2017-08-08');
   insert into t_order values(3100, 11, 'init', 5, 'test', '2017-08-08');
   insert into t_order values(3000, 10, 'init', 1, 'test', '2017-07-08');
   insert into t_order values(3001, 10, 'init', 2, 'test', '2017-07-08');
   insert into t_order values(4000, 20, 'init', 3, 'test', '2017-08-08');
   insert into t_order values(4001, 20, 'init', 4, 'test', '2017-08-08');
   insert into t_order values(4100, 11, 'init', 5, 'test', '2017-08-08');
   insert into t_merchant values(1, 86, 'tencent', '86000001', '86100000001', '2017-08-08');
   insert into t_merchant values(2, 86, 'haier', '86000002', '86100000002', '2017-08-08');
   insert into t_merchant values(3, 86, 'huawei', '86000003', '86100000003', '2017-08-08');
   insert into t_merchant values(4, 86, 'alibaba', '86000004', '86100000004', '2017-08-08');
   insert into t_merchant values(5, 86, 'lenovo', '86000005', '86100000005', '2017-08-08');
   
   select min(o.order_id), min(o.merchant_id), m.merchant_name from t_order o inner join t_merchant m on o.merchant_id = m.merchant_id group by m.merchant_id;
   ```
   ```
   tpccdb=# select min(o.order_id), min(o.merchant_id), m.merchant_name from t_order o inner join t_merchant m on o.merchant_id = m.merchant_id group by m.merchant_id;
   ERROR:  column "m.merchant_name" must appear in the GROUP BY clause or be used in an aggregate function
   LINE 1: select min(o.order_id), min(o.merchant_id), m.merchant_name ...
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org