In PSQL I am aggregating concatenated strings from a table called genus_synonym
An example of the table is as follows
id|genus_synonym|specific_epithet_synonym ---|----------|----------- 1 | Acer | rubrum 2 | Acer | nigrum 3 | Betula | lenta 4 | Carya | ovata 5 | Carya | glabra 6 | Carya | tomentosa
here is an image of my table if that is easier
the code I am using is like this
Select
string_agg(CONCAT(CONCAT(s."genus_synonym"), ' ', s.specific_epithet_synonym), ', ')as syno
FROM
"public"."synonyms" as s
The result is:
Acer rubrum, Acer nigrum, Betula lenta, Carya ovata, Carya glabra, Carya tomentosa
What I am trying to figure out is if it is possible to instead produce this:
Acer rubrum, A. nigrum, Betula lenta, Carya ovata, C. glabra, C. tomentosa
Basically I am wanting to abbreviate the genus name to a single letter with a period following it, for the second and additional time a genus is repeated.
Even if this is not possible it would be good to know this and then if there was another way I could go about solving this.
Also, it doesn't look like anyone is responding to my question. Is it not clear? I haven't been able to find anything like this being asked before. Please let me know what I can do to make this question better.
qry:
mockup your data: