[MDEV-23277] Make "for" sentence support JSON arrays Created: 2020-07-23  Updated: 2020-09-14  Resolved: 2020-09-14

Status: Closed
Project: MariaDB Server
Component/s: JSON
Fix Version/s: N/A

Type: Task Priority: Minor
Reporter: Rubén Assignee: Sergei Golubchik
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
PartOf
is part of MDEV-17399 Add support for JSON_TABLE Closed

 Description   

Hello.

Is it possible to make "for" sentece support JSON arrays? For example:

declare json_string varchar(1024) default '[
    {"rdbms":"MySQL/MariaDB","tag":"Rocks!"},
    {"rdbms":"Oracle Database","tag":"It\'s fine"},
    {"rdbms":"IBM DB2","tag":"Available in z/OS"},
    {"rdbms":"Microsoft SQL Server","tag":"No comments"}
]';
 
for rdbms in json_query(json_string, '$') do
   -- Do something with current iteration's object.
   select json_value(rdbms, '$.rdbms'), json_value(rdbms, '$.tag');
end for;

Regards.



 Comments   
Comment by Sergei Golubchik [ 2020-09-14 ]

You'll be able to do it when MDEV-17399 is implemented. Something like

for rdbms in (select ... from json_table(...)) do
  ...
end for;

Generated at Thu Feb 08 09:21:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.