Last active
January 4, 2021 11:23
-
-
Save malkab/0c00642f8d93eafe5bb38189265ca09c to your computer and use it in GitHub Desktop.
PostgreSQL - Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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