Пример #1
0
    def test_create_local_temporary_table(self):
        with self.subTest("with columns"):
            q = VerticaQuery.create_table(
                self.new_table).temporary().local().columns(
                    self.foo, self.bar)

            self.assertEqual(
                'CREATE LOCAL TEMPORARY TABLE "abc" ("a" INT,"b" VARCHAR(100))',
                str(q))

        with self.subTest("with select"):
            q = VerticaQuery.create_table(
                self.new_table).temporary().local().as_select(self.select)

            self.assertEqual(
                'CREATE LOCAL TEMPORARY TABLE "abc" AS (SELECT "foo","bar" FROM "efg")',
                str(q),
            )
Пример #2
0
    def test_create_temporary_table_preserve_rows(self):
        with self.subTest("with columns"):
            q = VerticaQuery.create_table(
                self.new_table).temporary().preserve_rows().columns(
                    self.foo, self.bar)

            self.assertEqual(
                'CREATE TEMPORARY TABLE "abc" ("a" INT,"b" VARCHAR(100)) ON COMMIT PRESERVE ROWS',
                str(q),
            )

        with self.subTest("with select"):
            q = VerticaQuery.create_table(
                self.new_table).temporary().preserve_rows().as_select(
                    self.select)

            self.assertEqual(
                'CREATE TEMPORARY TABLE "abc" ON COMMIT PRESERVE ROWS AS (SELECT "foo","bar" FROM "efg")',
                str(q),
            )
Пример #3
0
    def create_temporary_table_from_select(self,
                                           table,
                                           select_query,
                                           connection=None):
        """
        Creates a temporary table from a SELECT query.

        :param table: The name of the new temporary table.
        :param select_query: The query to be used for selecting data of an existing table for the new temporary table.
        :param connection: (Optional) The connection to execute this query with.
        """
        create_query = VerticaQuery.create_table(
            table).temporary().local().preserve_rows().as_select(select_query)

        self.execute(str(create_query), connection=connection)
Пример #4
0
    def create_temporary_table_from_columns(self,
                                            table,
                                            columns,
                                            connection=None):
        """
        Creates a temporary table from a list of columns.

        :param table: The name of the new temporary table.
        :param columns: The columns of the new temporary table.
        :param connection: (Optional) The connection to execute this query with.
        """
        create_query = VerticaQuery.create_table(
            table).temporary().local().preserve_rows().columns(*columns)

        self.execute(str(create_query), connection=connection)
Пример #5
0
 def test_create_local_table_without_temporary_raises_error(self):
     with self.assertRaises(AttributeError):
         VerticaQuery.create_table(self.new_table).local()
Пример #6
0
 def test_create_table_preserve_rows_without_temporary_raises_error(self):
     with self.assertRaises(AttributeError):
         VerticaQuery.create_table(self.new_table).preserve_rows()