Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add two maps of key to values(array) together in Presto?

Tags:

presto

I have this presto query that gives me this. enter image description here

but what I am looking for is this.

{"accountnumber":"A00000065","invoice":{"ids":["2c92c09a693316310169384472126a0d"], "numbers":["INV00000270"]}}

I have tried using the map_concat to no luck. [![enter image description here][2]][2]

https://prestodb.io/docs/current/functions/map.html [2]: https://i.sstatic.net/pq5iu.png


UPDATE: If I do the following it works.

map_concat(multimap_agg('number', invoice.invoicenumber), multimap_agg('id', invoice.id))

but if I change to

map_concat(multimap_agg('number', invoice.invoicenumber), multimap_agg('id', invoice.balance))

I get this error

line 1:23: Unexpected parameters (map(varchar(6),array(varchar)), map(varchar(2),array(decimal(18,6)))) for function map_concat. Expected: map_concat(map(K,V)) K, V

like image 498
user2434674 Avatar asked Sep 17 '25 00:09

user2434674


1 Answers

It should go in a comment, but that's too long. If it doesn't work, I'll delete the answer.

try this:

SELECT map_concat(multimap_agg('ids', invoice.id), multimap_agg('numbers', invoice.invoicenumber))
FROM ...
like image 100
Piotr Findeisen Avatar answered Sep 19 '25 14:09

Piotr Findeisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!