Skip to content

Instantly share code, notes, and snippets.

@LeKovr
Created January 5, 2018 16:13
Show Gist options
  • Save LeKovr/6e4e9af89c32ea176f9f4822760a296c to your computer and use it in GitHub Desktop.
Save LeKovr/6e4e9af89c32ea176f9f4822760a296c to your computer and use it in GitHub Desktop.
dbrpc sample function
/*
concat - sample function for dbrpc demo
See https://github.com/LeKovr/dbrpc
*/
CREATE OR REPLACE FUNCTION concat(
a_arg1 TEXT
, a_arg2 TEXT DEFAULT ''
) RETURNS TEXT IMMUTABLE LANGUAGE 'plpgsql' AS
$_$
BEGIN
PERFORM pg_sleep(1);
RETURN a_arg1 || a_arg2;
END
$_$;
-- -----------------------------------------------------------------------------
-- Register code as RPC method
SELECT rpc.add('concat', 'Concatenate two strings' -- name and anno
, '{"a_arg1":"Argument 1","a_arg2":"Argument 2"}' -- arguments
, '{"-":"Result string"}' -- results
, '{"a_arg1":"prefix", "a_arg2":"suffix"}' -- call example
, 10 -- cache for 10 sec
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment