allow direct argument references for RUN statement: RUN ON $1;
authorMarko Kreen <markokr@gmail.com>
Fri, 2 Jan 2009 14:49:39 +0000 (14:49 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 2 Jan 2009 14:49:39 +0000 (14:49 +0000)
expected/plproxy_test.out
sql/plproxy_test.sql
src/parser.y

index b79f5ca1c75bd1938a9f5a33d9bc2771588dacfd..8941db5cec2274b57adf749a50f5aa20891cf133 100644 (file)
@@ -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)
+
index 5fb025b9503098ad059f0f40f605d7939f907650..3a40647597c8ca2d495105e4c67b83dcec93f60b 100644 (file)
@@ -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);
+
index 502b4efef90abad4fdc4b8397905b1c7fe36b348..aeb965e93ca8d33d930496b99e6fa61203c76f89 100644 (file)
@@ -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 ");