Coder Social home page Coder Social logo

Comments (3)

shanakadu avatar shanakadu commented on May 18, 2024 3

Thanks @begriffs , it works!!.
And if it helpfull for someone. And example how to works with it.

CREATE OR REPLACE FUNCTION public.test_array(param_in json)
  RETURNS SETOF type_struct AS
$BODY$
--for test in pgsql cmd : select  * from test_array('[{"field1":3,"field2":5},{"field1":1,"field2":2}]');
--postgrest call, on body
--{
--    "param_in":[{"field1":3,"field2":5},{"field1":1,"field2":2}]
--}
declare
_rc  refcursor;
_r record;
_i type_struct;

begin
open _rc for select * from json_array_elements(test_array.param_in);
loop 
 fetch _rc into _r;
 exit when not found;

 RAISE NOTICE '%',to_json(_r.value);
_i = json_populate_record(null::type_struct, to_json(_r.value));
RAISE NOTICE 'ee %',_i;
return next _i;
end loop;
return ;
end;

from postgrest-docs.

begriffs avatar begriffs commented on May 18, 2024

Not directly. You could use a named parameter of type json and then check that it's a json array and loop through it that way. Note that when you POST a payload to the /rpc/test_array endpoint you'll still need to wrap your request in an object like this:

{ "argument_name": [1,2,3,4] }

rather than sending the array directly as

[1,2,3,4]

from postgrest-docs.

begriffs avatar begriffs commented on May 18, 2024

Glad you got it working! Would you consider sending a pull request to add a note about how to deal with json arrays in function arguments? I think you're not the first person to ask. Maybe add it in this section if you'd be so kind https://github.com/begriffs/postgrest-docs/blob/master/docs/api/reading.md#stored-procedures

from postgrest-docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.