I have the following data.
Sport
--------------
Baseball
Football
Baseball [a]
Football [a] [b]
Basketball
How can I group this to ignore the data in the brackets?
group bypostgresql
I have the following data.
Sport
--------------
Baseball
Football
Baseball [a]
Football [a] [b]
Basketball
How can I group this to ignore the data in the brackets?
Best Answer
The expression
will remove everything starting with the first space character up until the end of the string. So you just need to group by that expression:
This will return:
SQLFiddle: http://sqlfiddle.com/#!15/d41d8/3379
Edit
To deal with legitimate multi-word sports there are two options:
[
:regexp_replace(sport, ' \[.*$', '')
[..]
and then trim the result:trim(regexp_replace(sport, '\[.*\]', '', 'g'))