I have data available in postgres database on which I need to run a BI tool to have some aggregational information. Unfortunately the data is structured in the weirdest way. I have the example json column to work with:
{"products": ["345661C1-2665-4870-9649-803B20A4B579", 1, "FE719978-253F-4763-B1B7-648B9988C5BF", 2, "F66FE491-AC06-49DD-987B-0B88CB49CEB7", 2, "5628A5A4-6030-459D-96F3-32D3C04B7F80", 3, "2B8DAE11-5D60-4DB7-901B-0CCBA7D9418C", 1]}
I do realize the products array itself is not in the correct postgres syntax neither are the string literals.
Ideally I have a query resulting in this:
| Product | Amount |
|---|---|
| 345661C1-2665-4870-9649-803B20A4B579 | 1 |
| FE719978-253F-4763-B1B7-648B9988C5BF | 2 |
| F66FE491-AC06-49DD-987B-0B88CB49CEB7 | 2 |
| 5628A5A4-6030-459D-96F3-32D3C04B7F80 | 3 |
| 2B8DAE11-5D60-4DB7-901B-0CCBA7D9418C | 1 |
Is this possible with postgres? I was looking for
- a function to split arrays based on data type
- a function to remove elements based on odd/even index
I would always look for a solution with code but the BI tool is the only one whitelisted for this database