2014-05-05 23:13:06 +08:00
|
|
|
-- Function returning list of cartodb user tables
|
|
|
|
--
|
|
|
|
-- The optional argument restricts the result to tables
|
|
|
|
-- of the specified access type.
|
|
|
|
--
|
|
|
|
-- Currently accepted permissions are: 'public', 'private' or 'all'
|
|
|
|
--
|
2015-09-24 23:54:47 +08:00
|
|
|
DROP FUNCTION IF EXISTS CDB_UserTables(text);
|
2014-05-05 23:13:06 +08:00
|
|
|
CREATE OR REPLACE FUNCTION CDB_UserTables(perm text DEFAULT 'all')
|
2015-06-02 00:46:19 +08:00
|
|
|
RETURNS SETOF name
|
2014-05-05 23:13:06 +08:00
|
|
|
AS $$
|
2015-06-02 00:46:19 +08:00
|
|
|
|
|
|
|
SELECT c.relname
|
|
|
|
FROM pg_class c
|
|
|
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
2015-07-07 20:49:28 +08:00
|
|
|
WHERE c.relkind = 'r'
|
2015-06-02 00:46:19 +08:00
|
|
|
AND c.relname NOT IN ('cdb_tablemetadata', 'spatial_ref_sys')
|
2015-08-14 22:31:19 +08:00
|
|
|
AND n.nspname NOT IN ('pg_catalog', 'information_schema', 'topology', 'cartodb')
|
2015-07-07 20:49:28 +08:00
|
|
|
AND CASE WHEN perm = 'public' THEN has_table_privilege('publicuser', c.oid, 'SELECT')
|
2015-07-27 16:31:55 +08:00
|
|
|
WHEN perm = 'private' THEN has_table_privilege(current_user, c.oid, 'SELECT') AND NOT has_table_privilege('publicuser', c.oid, 'SELECT')
|
|
|
|
WHEN perm = 'all' THEN has_table_privilege(current_user, c.oid, 'SELECT') OR has_table_privilege('publicuser', c.oid, 'SELECT')
|
2015-06-02 01:37:46 +08:00
|
|
|
ELSE false END;
|
2015-06-02 00:46:19 +08:00
|
|
|
|
2014-05-05 23:13:06 +08:00
|
|
|
$$ LANGUAGE 'sql';
|
|
|
|
|
2014-06-06 17:33:34 +08:00
|
|
|
-- This is to migrate from pre-0.2.0 version
|
|
|
|
-- See http://github.com/CartoDB/cartodb-postgresql/issues/36
|
|
|
|
GRANT EXECUTE ON FUNCTION CDB_UserTables(text) TO public;
|