Skip to content
Advertisement

SQL procedure loop on a key from JSON object

I am trying to insert a JSON object into multiple tables

Procedure:

When I test it

I get the following error

ERROR: function json_array_elements(text) does not exist

No function matches the given name and argument types. You might need to add explicit type casts.
Where: PL/pgSQL function example1(json) line 5 at FOR over SELECT rows

I want to insert each of the images array into images table.

Advertisement

Answer

Your immediate error is, that ->> returns a text value, but json_array_elements() expects a json value. You need to use the -> operator here:

But you don’t need a LOOP for this (or PL/pgSQL to begin with):

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement