Comments (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.
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.
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)
- How-to for dynamic schemas with `pre-config` HOT 1
- serve image with img tag HOT 1
- Readthedocs will stop working on September 25 with the current config file HOT 1
- Docker crashing on M1 HOT 3
- limiting HTTP verbs in openapi response HOT 3
- Link to Installation from tutorial
- Move binary installation from tut0.rst to install.rst and add install options to tabs
- Library not loaded on Mac HOT 4
- Rename admin page name to Observability
- Deprecated "External JWT Generation" section using Auth0 Rules
- Chocolatey doesn't add `postgrest` to the PATH
- Drop all plain HTTP snippets in favor of `curl` commands HOT 1
- Missing entries in Preferences section HOT 1
- Show a more prominent version number
- Having more than one internal schema on schema isolation is confusing HOT 4
- Use the term "secret" instead of "password" in Tutorial 1
- Avoid Globbing in Curl examples HOT 2
- Move from tailwind to PicoCSS in HTMX how-to
- Expand on Schema Isolation HOT 2
- Recommend using `row_security = off` for starting up with RLS HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postgrest-docs.