0down votefavorite | I am trying Openresty connecting to Postgresql returning html content to the browser from postgresql functions. I am able to receive the response but the response also contains the headers of the SQL table with some junk characters which is something I do not want.My nginx conf file is as follows
location /articles/ {
postgres_pass database;
postgres_query HEAD GET "SELECT getArticles()";
more_set_headers 'Content-Type: text/html;charset=utf-8';
postgres_rewrite HEAD GET no_rows 410;
}
}
}`
My Postgres function is as follows
`CREATE OR REPLACE FUNCTION getArticles() RETURNS text AS $$
DECLARE
returnText text;
p1 record;
BEGIN
returnText := '
';
FOR p1 in SELECT * FROM articles LOOP
returnText := returnText || '<div>' || p1.title || '</div>';
END LOOP;
returnText := returnText || '</body></html>';
RETURN returnText;
END;
$$ LANGUAGE 'plpgsql';`
When I run the code I get the following response
�getarticles^
Chatbot
Machine Learning
Data Science
The getArticles is the SQL table header of the result which I do not need as a response. Is there a way to avoid these headers and garbage characters coming as part of the response?
0down votefavorite | I am trying Openresty connecting to Postgresql returning html content to the browser from postgresql functions. I am able to receive the response but the response also contains the headers of the SQL table with some junk characters which is something I do not want.My nginx conf file is as follows
`worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http {
upstream database { postgres_server 127.0.0.1 dbname=mydb user=postgres password=mypass; postgres_keepalive max=200 overflow=reject; }
server { listen 8080;
} }`
My Postgres function is as follows
`CREATE OR REPLACE FUNCTION getArticles() RETURNS text AS $$ DECLARE
';returnText text; p1 record; BEGIN returnText := '
END; $$ LANGUAGE 'plpgsql';`
When I run the code I get the following response
�getarticles^