Skip to content

Instantly share code, notes, and snippets.

@bububa
Created January 21, 2014 08:12
Show Gist options
  • Save bububa/8536141 to your computer and use it in GitHub Desktop.
Save bububa/8536141 to your computer and use it in GitHub Desktop.
plproxy query setup
CREATE FUNCTION "plproxy"."get_cluster_config"(IN cluster_name text, OUT "key" text, OUT val text) RETURNS SETOF "record"
AS $BODY$
begin
key := 'statement_timeout';
val := 60;
return next;
return;
end; $BODY$
LANGUAGE plpgsql
COST 100
ROWS 1000
CALLED ON NULL INPUT
SECURITY INVOKER
VOLATILE;
ALTER FUNCTION "plproxy"."get_cluster_config"(IN cluster_name text, OUT "key" text, OUT val text) OWNER TO "turbo";
CREATE FUNCTION "plproxy"."get_cluster_partitions"(IN cluster_name text) RETURNS SETOF "text"
AS $BODY$
BEGIN
IF cluster_name = 'sem' THEN
RETURN NEXT 'dbname=kwinsights host=code1 user=turbo';
RETURN NEXT 'dbname=kwinsights host=code2 user=turbo';
RETURN NEXT 'dbname=kwinsights host=code5 user=turbo';
RETURN NEXT 'dbname=kwinsights host=code6 user=turbo';
RETURN;
END IF;
RAISE EXCEPTION 'Unknown cluster';
END;
$BODY$
LANGUAGE plpgsql
COST 100
ROWS 1000
CALLED ON NULL INPUT
SECURITY INVOKER
VOLATILE;
ALTER FUNCTION "plproxy"."get_cluster_partitions"(IN cluster_name text) OWNER TO "turbo";
CREATE FUNCTION "plproxy"."get_cluster_version"(IN cluster_name text) RETURNS "int4"
AS $BODY$
BEGIN
IF cluster_name = 'sem' THEN
RETURN 1;
END IF;
RAISE EXCEPTION 'Unknown cluster';
END;
$BODY$
LANGUAGE plpgsql
COST 100
CALLED ON NULL INPUT
SECURITY INVOKER
VOLATILE;
ALTER FUNCTION "plproxy"."get_cluster_version"(IN cluster_name text) OWNER TO "turbo";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment