akretschmer
Datenbank-Guru
- Beiträge
- 10.333
Wozu das GROUP BY hier?
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
test=# select * from mikluxo ;
id | begriff
----+-------------
1 | banane
3 | Birne
4 | Zitrone
5 | Strom|kabel
2 | Wald-apfel
(5 Zeilen)
test=*# select * from mikluxo where replace(replace(begriff,'|',''),'-','') in( 'Stromkabel', 'Waldapfel');
id | begriff
----+-------------
5 | Strom|kabel
2 | Wald-apfel
(2 Zeilen)
test=*# select * from mikluxo where replace(replace(begriff,'|',''),'-','') in( 'Stromkabel', 'Waldapfel') group by id;
id | begriff
----+-------------
2 | Wald-apfel
5 | Strom|kabel
(2 Zeilen)
test=*# alter table mikluxo drop constraint mikluxo_pkey ;
ALTER TABLE
test=*# select * from mikluxo where replace(replace(begriff,'|',''),'-','') in( 'Stromkabel', 'Waldapfel') group by id;
FEHLER: Spalte »mikluxo.begriff« muss in der GROUP-BY-Klausel erscheinen oder in einer Aggregatfunktion verwendet werden
ZEILE 1: select * from mikluxo where replace(replace(begriff,'|',''),...
^
test=*#
test=*# explain select *, similarity (begriff, 'Waldapfel') as "Waldapfel", similarity(begriff,'Stromkabel') as "Stromkabel" from mikluxo where begriff % 'Waldapfel' or begriff % 'Stromkabel';
QUERY PLAN
-----------------------------------------------------------------------------------
Bitmap Heap Scan on mikluxo (cost=8.28..12.30 rows=1 width=36)
Recheck Cond: ((begriff % 'Waldapfel'::text) OR (begriff % 'Stromkabel'::text))
-> BitmapOr (cost=8.28..8.28 rows=1 width=0)
-> Bitmap Index Scan on trgm_index (cost=0.00..4.14 rows=1 width=0)
Index Cond: (begriff % 'Waldapfel'::text)
-> Bitmap Index Scan on trgm_index (cost=0.00..4.14 rows=1 width=0)
Index Cond: (begriff % 'Stromkabel'::text)
(7 Zeilen)