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

duplicate variable #4

Open
houmanb opened this issue Dec 20, 2021 · 1 comment
Open

duplicate variable #4

houmanb opened this issue Dec 20, 2021 · 1 comment

Comments

@houmanb
Copy link

houmanb commented Dec 20, 2021

Dear all,
I'm new to openResty and my question might appear trivial, but nevertheless I need some advice on this issue I'm experiencing with the "postgres_set" directive:

As soon as I define a variable whose value is set by "postgres_set" directive within two completely separate locations of my nginx.conf , I receive an error from nginx.

nginx: [emerg] the duplicate "VAR" variable .....

Opposite to postgres_set using set $var 1 doesn't cause any errors.
What is the scope of a variable defined using postgres_set within a location?

Thanks in advance

nginx version: openresty/1.19.9.1
OS: cat /etc/debian_version 10.11

Here is my nginx.conf file:

worker_processes 2;

events {}
http {
    variables_hash_bucket_size 4096;

    upstream database {
        postgres_server  host.docker.internal  dbname=test user=postgres password=;
        postgres_keepalive max=200 overflow=ignore;
    }

    server {
        listen       8080;

        location  /loc1 {

                        postgres_pass database;
                        postgres_output text;
                        postgres_query
                        GET  "SELECT 1";
                        postgres_set $var 0 0 optional;
                        #set $var "1";
                        postgres_rewrite no_rows 404;
                        postgres_rewrite GET rows 200;
                       
        }

        location  /loc2 {

                        postgres_pass database;
                        postgres_output text;
                        postgres_query
                        GET  "SELECT 1";
                        postgres_set $var 0 0 optional;
                        #set $var "1";
                        postgres_rewrite no_rows 404;
                        postgres_rewrite GET rows 200;
        }

    }
}
@xiaocang
Copy link
Contributor

This error is expected, at least in the current version of ngx_postgres module: you can't set the same variable name in the same server, or even in different servers.

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

2 participants