diff options
-rw-r--r-- | sql/londiste/functions/londiste.split_fqname.sql | 32 | ||||
-rw-r--r-- | sql/londiste/structure/functions.sql | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/sql/londiste/functions/londiste.split_fqname.sql b/sql/londiste/functions/londiste.split_fqname.sql new file mode 100644 index 00000000..4ffeafab --- /dev/null +++ b/sql/londiste/functions/londiste.split_fqname.sql @@ -0,0 +1,32 @@ +create or replace function londiste.split_fqname( + in i_fqname text, + out schema_part text, + out name_part text) +as $$ +-- ---------------------------------------------------------------------- +-- Function: londiste.split_fqname(1) +-- +-- Split fqname to schema and name parts. +-- +-- First dot is taken as schema separator. +-- +-- If schema is missing, 'public' is assumed. +-- +-- Parameters: +-- i_fqname - object name. +-- ---------------------------------------------------------------------- +declare + dot integer; +begin + dot = position('.' in i_fqname); + if dot > 0 then + schema_part = substring(i_fqname for dot - 1); + name_part = substring(i_fqname from dot + 1); + else + schema_part = 'public'; + name_part = i_fqname; + end if; + return; +end; +$$ language plpgsql strict immutable; + diff --git a/sql/londiste/structure/functions.sql b/sql/londiste/structure/functions.sql index ebf5c5ad..2914721e 100644 --- a/sql/londiste/structure/functions.sql +++ b/sql/londiste/structure/functions.sql @@ -37,4 +37,5 @@ \i functions/londiste.find_table_oid.sql \i functions/londiste.quote_fqname.sql \i functions/londiste.make_fqname.sql +\i functions/londiste.split_fqname.sql |