pramsey/pgsql-http

How to include query result into http call?

slamethendry opened this issue · 1 comments

I have read the readme as carefully as I can and searched around the internet, but I cannot see any example or guide. Trial and error gets me nowhere thus far.

What I would like to do is to incorporate query result, for example:
SELECT handle SINGLE FROM users WHERE ...

and use handle as a variable in http_post. Something like

SELECT status FROM http_post('url', 'myvar=' || handle || '&foo=bar', 'application/x-www-form-urlencoded');

And then do something with status, e.g. upsert a log table.

I assume this is possible with pgsql-http. Any guide or example is highly appreciated.

Maybe just pull the status directly out of the http response tuple?

INSERT INTO handle_status (handle, status)
SELECT h.handle, (http_post('url', 'myvar=' || handle || '&foo=bar', 'application/x-www-form-urlencoded')).status
FROM handle h
WHERE h.foo = 'bar'