Skip to content

duplicate variable #4

Open
Open
@houmanb

Description

@houmanb

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;
        }

    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions