Skip to content

Instantly share code, notes, and snippets.

@malkab
Last active January 4, 2021 11:23
Show Gist options
  • Save malkab/0c00642f8d93eafe5bb38189265ca09c to your computer and use it in GitHub Desktop.
Save malkab/0c00642f8d93eafe5bb38189265ca09c to your computer and use it in GitHub Desktop.
PostgreSQL - Functions
/**
*
* A Pl/PgSql function example.
*
*/
create or replace function public.gs__split_qualified_name(
_name text
) returns public.gs__qualified_name as
$$
declare
_qn public.gs__qualified_name;
begin
_qn._schema := substring(_name from 1 for position('.' in _name)-1);
_qn._object_name := substring(_name from position('.' in _name)+1 for char_length(_name)-position('.' in _name));
return _qn;
end;
$$
language plpgsql;
comment on function public.gs__split_qualified_name(text) is
'Takes a text in schema.object_name format and returns a public.gs__qualified_name.';
/**
*
* A SQL function example.
*
*/
create function prefix__tf1(
_acct_no integer,
_debit numeric
) returns numeric as
$$
select n
from foo
where acct_no=$1 and debit=$2;
$$
language sql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment