From 453016f966680afe58923292c8473cf6f3e59aac Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Fri, 2 Jan 2009 14:49:39 +0000 Subject: [PATCH] allow direct argument references for RUN statement: RUN ON $1; --- expected/plproxy_test.out | 28 ++++++++++++++++++++++++++++ sql/plproxy_test.sql | 20 ++++++++++++++++++++ src/parser.y | 9 +++++++++ 3 files changed, 57 insertions(+) diff --git a/expected/plproxy_test.out b/expected/plproxy_test.out index b79f5ca..8941db5 100644 --- a/expected/plproxy_test.out +++ b/expected/plproxy_test.out @@ -310,3 +310,31 @@ select * from test_difftypes('types'); 1 | 3 (1 row) +-- test simple hash +\c test_part +create function test_simple(partno int4) returns int4 +as $$ begin return $1; end; $$ language plpgsql; +\c regression +create function test_simple(partno int4) returns int4 +as $$ + cluster 'testcluster'; + run on $1; +$$ language plproxy; +select * from test_simple(0); + test_simple +------------- + 0 +(1 row) + +drop function test_simple(int4); +create function test_simple(partno int4) returns int4 +as $$ + cluster 'testcluster'; + run on partno; +$$ language plproxy; +select * from test_simple(0); + test_simple +------------- + 0 +(1 row) + diff --git a/sql/plproxy_test.sql b/sql/plproxy_test.sql index 5fb025b..3a40647 100644 --- a/sql/plproxy_test.sql +++ b/sql/plproxy_test.sql @@ -198,3 +198,23 @@ create function test_difftypes(username text, out val1 int4, out val2 float4) as $$ cluster 'testcluster'; run on 0; $$ language plproxy; select * from test_difftypes('types'); +-- test simple hash +\c test_part +create function test_simple(partno int4) returns int4 +as $$ begin return $1; end; $$ language plpgsql; +\c regression +create function test_simple(partno int4) returns int4 +as $$ + cluster 'testcluster'; + run on $1; +$$ language plproxy; +select * from test_simple(0); +drop function test_simple(int4); + +create function test_simple(partno int4) returns int4 +as $$ + cluster 'testcluster'; + run on partno; +$$ language plproxy; +select * from test_simple(0); + diff --git a/src/parser.y b/src/parser.y index 502b4ef..aeb965e 100644 --- a/src/parser.y +++ b/src/parser.y @@ -108,8 +108,17 @@ run_spec: hash_func sql_token_list { xfunc->run_type = R_HASH; } | NUMBER { xfunc->run_type = R_EXACT; xfunc->exact_nr = atoi($1); } | ANY { xfunc->run_type = R_ANY; } | ALL { xfunc->run_type = R_ALL; } + | hash_direct { xfunc->run_type = R_HASH; } ; +hash_direct: IDENT { hash_sql = plproxy_query_start(xfunc, false); + cur_sql = hash_sql; + plproxy_query_add_const(cur_sql, "select "); + if (!plproxy_query_add_ident(cur_sql, $1)) + yyerror("invalid argument reference: %s", $1); + } + ; + hash_func: FNCALL { hash_sql = plproxy_query_start(xfunc, false); cur_sql = hash_sql; plproxy_query_add_const(cur_sql, "select * from "); -- 2.39.5