From 6b49ccc3482e672fb2206c3d560133d6797700f0 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Thu, 10 Oct 2019 10:28:29 +0100 Subject: [PATCH 1/6] [engine spec] Fix, CTAS needs commit to apply --- superset/db_engine_specs/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py index 12911ad99f888..494c3a15630d6 100644 --- a/superset/db_engine_specs/base.py +++ b/superset/db_engine_specs/base.py @@ -755,6 +755,7 @@ def execute(cls, cursor, query: str, **kwargs): """ if cls.arraysize: cursor.arraysize = cls.arraysize + cursor.connection.autocommit = True cursor.execute(query) @classmethod From f48292b0af96acd922e1962bb2215d4ebe697db0 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Sun, 13 Oct 2019 15:03:33 +0100 Subject: [PATCH 2/6] [docs] New, document need for PG to use autocommit for CTAS --- docs/sqllab.rst | 16 ++++++++++++++++ superset/db_engine_specs/base.py | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/sqllab.rst b/docs/sqllab.rst index 9f9bac07623c4..ea0499f422ca0 100644 --- a/docs/sqllab.rst +++ b/docs/sqllab.rst @@ -122,3 +122,19 @@ database configuration: Here, "version" should be the version of your Presto cluster. Support for this functionality was introduced in Presto 0.319. + +Create Table As +''''''''''''''' + +You can use `CREATE TABLE AS SELECT ...` statements on SQLLab this feature can be toggled on +and off at the database configuration level, note that on PostgreSQL DDL is transactional, +this means that, to properly use this feature you have to set `autocommit` to true on your +engine parameters: + +.. code-block:: json + + { + ... + "engine_params": {"isolation_level":"AUTOCOMMIT"}, + ... + } diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py index 494c3a15630d6..12911ad99f888 100644 --- a/superset/db_engine_specs/base.py +++ b/superset/db_engine_specs/base.py @@ -755,7 +755,6 @@ def execute(cls, cursor, query: str, **kwargs): """ if cls.arraysize: cursor.arraysize = cls.arraysize - cursor.connection.autocommit = True cursor.execute(query) @classmethod From 1baec36e5776c5c6d62e780d55a7a13b21a5cf61 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Sun, 13 Oct 2019 15:04:42 +0100 Subject: [PATCH 3/6] [docs] Fix, ident JSON example --- docs/sqllab.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sqllab.rst b/docs/sqllab.rst index ea0499f422ca0..3bc5e14b14cc3 100644 --- a/docs/sqllab.rst +++ b/docs/sqllab.rst @@ -134,7 +134,7 @@ engine parameters: .. code-block:: json { - ... - "engine_params": {"isolation_level":"AUTOCOMMIT"}, - ... + ... + "engine_params": {"isolation_level":"AUTOCOMMIT"}, + ... } From dd488272f2cb1d30ac1f32f8b09752cf1a1a2866 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Sun, 13 Oct 2019 18:18:42 +0100 Subject: [PATCH 4/6] [docs] Fix, improve text --- docs/sqllab.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/sqllab.rst b/docs/sqllab.rst index 3bc5e14b14cc3..82287b3528f6c 100644 --- a/docs/sqllab.rst +++ b/docs/sqllab.rst @@ -123,13 +123,14 @@ database configuration: Here, "version" should be the version of your Presto cluster. Support for this functionality was introduced in Presto 0.319. -Create Table As -''''''''''''''' +Create Table As (CTAS) +'''''''''''''''''''''' You can use `CREATE TABLE AS SELECT ...` statements on SQLLab this feature can be toggled on -and off at the database configuration level, note that on PostgreSQL DDL is transactional, -this means that, to properly use this feature you have to set `autocommit` to true on your -engine parameters: +and off at the database configuration level. + +Note that since `CREATE TABLE..` belongs to a SQL DDL category. Specifically on PostgreSQL, DDL is transactional, +this means that, to properly use this feature you have to set `autocommit` to true on your engine parameters: .. code-block:: json From 5d122bd40a83f41121eccdb86f2197a1401cae5d Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Sun, 13 Oct 2019 19:56:01 +0100 Subject: [PATCH 5/6] [docs] New, reference on installation --- docs/installation.rst | 3 +++ docs/sqllab.rst | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index cc6792a0d51fa..569277ed47b63 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -579,6 +579,9 @@ object gets unpacked into the while the ``metadata_params`` get unpacked into the `sqlalchemy.MetaData `_ call. Refer to the SQLAlchemy docs for more information. +.. note:: If your using CTAS on SQLLab and PostgreSQL + take a look at :ref:`ref_ctas_engine_config` for specific ``engine_params``. + Schemas (Postgres & Redshift) ----------------------------- diff --git a/docs/sqllab.rst b/docs/sqllab.rst index 82287b3528f6c..25add861df6c0 100644 --- a/docs/sqllab.rst +++ b/docs/sqllab.rst @@ -123,14 +123,16 @@ database configuration: Here, "version" should be the version of your Presto cluster. Support for this functionality was introduced in Presto 0.319. +.. _ref_ctas_engine_config: + Create Table As (CTAS) '''''''''''''''''''''' -You can use `CREATE TABLE AS SELECT ...` statements on SQLLab this feature can be toggled on +You can use ``CREATE TABLE AS SELECT ...`` statements on SQLLab this feature can be toggled on and off at the database configuration level. -Note that since `CREATE TABLE..` belongs to a SQL DDL category. Specifically on PostgreSQL, DDL is transactional, -this means that, to properly use this feature you have to set `autocommit` to true on your engine parameters: +Note that since ``CREATE TABLE..`` belongs to a SQL DDL category. Specifically on PostgreSQL, DDL is transactional, +this means that to properly use this feature you have to set ``autocommit`` to true on your engine parameters: .. code-block:: json From 59740275c0655565c37d92f8983213737ceac780 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 16 Oct 2019 08:48:20 +0100 Subject: [PATCH 6/6] [docs] Fix, split big sentence --- docs/sqllab.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sqllab.rst b/docs/sqllab.rst index 25add861df6c0..39ae4d4d7a99a 100644 --- a/docs/sqllab.rst +++ b/docs/sqllab.rst @@ -128,7 +128,7 @@ functionality was introduced in Presto 0.319. Create Table As (CTAS) '''''''''''''''''''''' -You can use ``CREATE TABLE AS SELECT ...`` statements on SQLLab this feature can be toggled on +You can use ``CREATE TABLE AS SELECT ...`` statements on SQLLab. This feature can be toggled on and off at the database configuration level. Note that since ``CREATE TABLE..`` belongs to a SQL DDL category. Specifically on PostgreSQL, DDL is transactional,