PL/Proxy Language Syntax
From PostgreSQL 中文维基, PostgreSQL 中文站, PostgreSQL 中国社区, PostgreSQL Chinese community
The language is similar to plpgsql - string quoting, comments, semicolon at the statements end.
It contains only 4 statements: CONNECT, CLUSTER, RUN and SELECT.
Each function needs to have either CONNECT or pair of CLUSTER + RUN statements to specify where to run the function.
The SELECT statement is optional, if it is missing, there will be default query generated based on proxy function signature.
The RUN statment is also optional, it defaults to RUN ON ANY which means the query will be run random partition.
[编辑] CONNECT
CONNECT 'libpq connstr';
Specifies exact location where to connect and execute the query. If several functions have same connstr, they will use same connection.
[编辑] CLUSTER
CLUSTER 'cluster_name';
Specifies exact cluster name to be run on. The cluster name will be passed to plproxy.get_cluster_* functions.
CLUSTER cluster_func(..);
Cluster name can be dynamically decided upon proxy function arguments. cluster_func should return text value of final cluster name.
[编辑] RUN ON
RUN ON ALL;
Query will be run on all partitions in cluster in parallel.
RUN ON ANY;
Query will be run on random partition.
RUN ON <NR>;
Run on partition number <NR>.</font>
RUN ON partition_func(..);
Run partition_func() which should return one or more hash values. (int4) Query will be run on tagged partitions. If more than one partition was tagged, query will be sent in parallel to them.
[编辑] SELECT
SELECT .... ;
By default, PL/Proxy generates query based on its own signature. But this can be overrided by giving explicit SELECT statement to run.
Everything after SELECT until semicolon is taken as SQL to be passed on. Only argument substitution is done on the contents, otherwise the text is unparsed. To avoid a table column to be parsed as function argument, table aliases should be used.
Query result should have same number of columns as function result and same names too.
[编辑] Argument substitution
Proxy function arguments can be referenced using name or $n syntax. Everything that is not argument reference is just passed on.
