londiste: helper function to extract parts from fqname
authorMarko Kreen <markokr@gmail.com>
Thu, 27 Aug 2009 08:45:16 +0000 (11:45 +0300)
committerMarko Kreen <markokr@gmail.com>
Thu, 27 Aug 2009 08:45:16 +0000 (11:45 +0300)
sql/londiste/functions/londiste.split_fqname.sql [new file with mode: 0644]
sql/londiste/structure/functions.sql

diff --git a/sql/londiste/functions/londiste.split_fqname.sql b/sql/londiste/functions/londiste.split_fqname.sql
new file mode 100644 (file)
index 0000000..4ffeafa
--- /dev/null
@@ -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;
+
index ebf5c5adb213d534501fe229dffb265762d3c2b5..2914721e6a21504d88d86a6e589ea6b596b7404b 100644 (file)
@@ -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