You can use this Lua code:
local res = ngx.location.capture('/pg/query', {
method = ngx.HTTP_POST, body = sql
})
if res.status ~= ngx.HTTP_OK or not res.body then
-- error
else
local parser = require "rds.parser"
local result, err = parser.parse(res.body)
if not result then
-- error
else
local rows = result.resultset
if not rows or #rows == 0 then
-- error
else
-- ok, do something
end
end
end
With this location in your conf :
location /pg/query {
internal;
postgres_output rds;
postgres_pass pgconf;
postgres_query $echo_request_body;
}
And this upstream :
upstream pgconf {
postgres_server localhost:5432 dbname=mydb user=postgres password=postgres;
}