Skip to content

Commit

Permalink
Merge pull request #138 from hkad98/NAS-4268
Browse files Browse the repository at this point in the history
NAS-4268 create view related to foreign table

Reviewed-by: Jan Soubusta
             https://github.com/jaceksan
  • Loading branch information
gdgate committed Aug 18, 2022
2 parents 0629f59 + 4be0e46 commit e229a54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gooddata-fdw/docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Execute the following command in your repository root folder:

.. code-block:: shell
docker-compose up -d
docker-compose up --build -d
``gooddata-fdw`` image is built from the Dockerfile and both services are started in background.

Expand Down
14 changes: 14 additions & 0 deletions gooddata-fdw/sql/import_gooddata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ CREATE OR REPLACE PROCEDURE import_gooddata(
DECLARE
sql_statement VARCHAR;
foreign_schema VARCHAR := coalesce(foreign_schema, workspace);
foreign_table RECORD;
view_name VARCHAR;
BEGIN
-- Recreate schema, where foreign tables will be imported
sql_statement := format('DROP SCHEMA IF EXISTS "%s" CASCADE', foreign_schema);
Expand All @@ -35,4 +37,16 @@ BEGIN
workspace, foreign_server, foreign_schema, object_type, numeric_max_size
);
CALL execute_sql(sql_statement, debug);

FOR foreign_table IN
SELECT table_name
FROM information_schema.tables
WHERE table_schema = foreign_schema AND table_type = 'FOREIGN' LOOP
view_name := foreign_table.table_name || '_view';
sql_statement := format(
'CREATE OR REPLACE VIEW "%s"."%s" AS SELECT * FROM "%s"."%s"',
workspace, view_name, workspace, foreign_table.table_name
);
CALL execute_sql(sql_statement, debug);
END LOOP;
END; $$;

0 comments on commit e229a54

Please sign in to comment.