Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The response from Postgres includes the column headers too #58

Open
rajasaran opened this issue Feb 20, 2018 · 0 comments
Open

The response from Postgres includes the column headers too #58

rajasaran opened this issue Feb 20, 2018 · 0 comments

Comments

@rajasaran
Copy link

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;

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant