Ejemplo n.º 1
0
    def test_temporal_select(self):
        t = Table("abc")

        with self.subTest("with system time as of"):
            q = Query.from_(t.for_(
                SYSTEM_TIME.as_of('2020-01-01'))).select("*")

            self.assertEqual(
                'SELECT * FROM "abc" FOR SYSTEM_TIME AS OF \'2020-01-01\'',
                str(q))

        with self.subTest("with system time between"):
            q = Query.from_(
                t.for_(SYSTEM_TIME.between('2020-01-01',
                                           '2020-02-01'))).select("*")

            self.assertEqual(
                'SELECT * FROM "abc" FOR SYSTEM_TIME BETWEEN \'2020-01-01\' AND \'2020-02-01\'',
                str(q))

        with self.subTest("with system time from to"):
            q = Query.from_(
                t.for_(SYSTEM_TIME.from_to('2020-01-01',
                                           '2020-02-01'))).select("*")

            self.assertEqual(
                'SELECT * FROM "abc" FOR SYSTEM_TIME FROM \'2020-01-01\' TO \'2020-02-01\'',
                str(q))

        with self.subTest("with ALL"):
            q = Query.from_(t.for_(SYSTEM_TIME.all_())).select("*")

            self.assertEqual('SELECT * FROM "abc" FOR SYSTEM_TIME ALL', str(q))

        with self.subTest("with period between"):
            q = Query.from_(
                t.for_(t.valid_period.between('2020-01-01',
                                              '2020-02-01'))).select("*")

            self.assertEqual(
                'SELECT * FROM "abc" FOR "valid_period" BETWEEN \'2020-01-01\' AND \'2020-02-01\'',
                str(q))

        with self.subTest("with period from to"):
            q = Query.from_(
                t.for_(t.valid_period.from_to('2020-01-01',
                                              '2020-02-01'))).select("*")

            self.assertEqual(
                'SELECT * FROM "abc" FOR "valid_period" FROM \'2020-01-01\' TO \'2020-02-01\'',
                str(q))

        with self.subTest("with ALL"):
            q = Query.from_(t.for_(t.valid_period.all_())).select("*")

            self.assertEqual('SELECT * FROM "abc" FOR "valid_period" ALL',
                             str(q))
Ejemplo n.º 2
0
    def test_for_portion(self):
        with self.subTest("with system time"):
            q = Query.from_(self.table_abc.for_portion(SYSTEM_TIME.from_to('2020-01-01', '2020-02-01'))).delete()

            self.assertEqual(
                'DELETE FROM "abc" FOR PORTION OF SYSTEM_TIME FROM \'2020-01-01\' TO \'2020-02-01\'', str(q)
            )

        with self.subTest("with column"):
            q = Query.from_(
                self.table_abc.for_portion(self.table_abc.valid_period.from_to('2020-01-01', '2020-02-01'))
            ).delete()

            self.assertEqual(
                'DELETE FROM "abc" FOR PORTION OF "valid_period" FROM \'2020-01-01\' TO \'2020-02-01\'', str(q)
            )
Ejemplo n.º 3
0
    def test_for_portion(self):
        with self.subTest("with system time"):
            q = Query.update(self.table_abc.for_portion(SYSTEM_TIME.from_to('2020-01-01', '2020-02-01'))).set(
                "foo", "bar"
            )

            self.assertEqual(
                'UPDATE "abc" FOR PORTION OF SYSTEM_TIME FROM \'2020-01-01\' TO \'2020-02-01\' SET "foo"=\'bar\'',
                str(q),
            )

        with self.subTest("with column"):
            q = Query.update(
                self.table_abc.for_portion(self.table_abc.valid_period.from_to('2020-01-01', '2020-02-01'))
            ).set("foo", "bar")

            self.assertEqual(
                'UPDATE "abc" FOR PORTION OF "valid_period" FROM \'2020-01-01\' TO \'2020-02-01\' SET "foo"=\'bar\'',
                str(q),
            )
Ejemplo n.º 4
0
    def test_for_portion(self):
        with self.subTest("with system time"):
            q = Query.from_(
                self.table_abc.for_portion(
                    SYSTEM_TIME.from_to("2020-01-01", "2020-02-01"))).delete()

            self.assertEqual(
                "DELETE FROM \"abc\" FOR PORTION OF SYSTEM_TIME FROM '2020-01-01' TO '2020-02-01'",
                str(q),
            )

        with self.subTest("with column"):
            q = Query.from_(
                self.table_abc.for_portion(
                    self.table_abc.valid_period.from_to(
                        "2020-01-01", "2020-02-01"))).delete()

            self.assertEqual(
                "DELETE FROM \"abc\" FOR PORTION OF \"valid_period\" FROM '2020-01-01' TO '2020-02-01'",
                str(q),
            )
Ejemplo n.º 5
0
    def test_for_portion(self):
        with self.subTest("with system time"):
            q = Query.update(
                self.table_abc.for_portion(
                    SYSTEM_TIME.from_to("2020-01-01",
                                        "2020-02-01"))).set("foo", "bar")

            self.assertEqual(
                "UPDATE \"abc\" FOR PORTION OF SYSTEM_TIME FROM '2020-01-01' TO '2020-02-01' SET \"foo\"='bar'",
                str(q),
            )

        with self.subTest("with column"):
            q = Query.update(
                self.table_abc.for_portion(
                    self.table_abc.valid_period.from_to(
                        "2020-01-01", "2020-02-01"))).set("foo", "bar")

            self.assertEqual(
                "UPDATE \"abc\" FOR PORTION OF \"valid_period\" FROM '2020-01-01' TO '2020-02-01' SET \"foo\"='bar'",
                str(q),
            )
Ejemplo n.º 6
0
    def test_table_for_system_time_sql(self):
        with self.subTest("with between criterion"):
            table = Table("test_table").for_(
                SYSTEM_TIME.between("2020-01-01", "2020-02-01"))

            self.assertEqual(
                "\"test_table\" FOR SYSTEM_TIME BETWEEN '2020-01-01' AND '2020-02-01'",
                str(table))

        with self.subTest("with as of criterion"):
            table = Table("test_table").for_(SYSTEM_TIME.as_of("2020-01-01"))

            self.assertEqual(
                "\"test_table\" FOR SYSTEM_TIME AS OF '2020-01-01'",
                str(table))

        with self.subTest("with from to criterion"):
            table = Table("test_table").for_(
                SYSTEM_TIME.from_to("2020-01-01", "2020-02-01"))

            self.assertEqual(
                "\"test_table\" FOR SYSTEM_TIME FROM '2020-01-01' TO '2020-02-01'",
                str(table))
Ejemplo n.º 7
0
    def test_table_for_system_time_sql(self):
        with self.subTest("with between criterion"):
            table = Table("test_table").for_(
                SYSTEM_TIME.between('2020-01-01', '2020-02-01'))

            self.assertEqual(
                '"test_table" FOR SYSTEM_TIME BETWEEN \'2020-01-01\' AND \'2020-02-01\'',
                str(table))

        with self.subTest("with as of criterion"):
            table = Table("test_table").for_(SYSTEM_TIME.as_of('2020-01-01'))

            self.assertEqual(
                '"test_table" FOR SYSTEM_TIME AS OF \'2020-01-01\'',
                str(table))

        with self.subTest("with from to criterion"):
            table = Table("test_table").for_(
                SYSTEM_TIME.from_to('2020-01-01', '2020-02-01'))

            self.assertEqual(
                '"test_table" FOR SYSTEM_TIME FROM \'2020-01-01\' TO \'2020-02-01\'',
                str(table))
Ejemplo n.º 8
0
    def test_temporal_select(self):
        t = Table("abc")

        with self.subTest("with system time as of"):
            q = Query.from_(t.for_(
                SYSTEM_TIME.as_of("2020-01-01"))).select("*")

            self.assertEqual(
                "SELECT * FROM \"abc\" FOR SYSTEM_TIME AS OF '2020-01-01'",
                str(q))

        with self.subTest("with system time between"):
            q = Query.from_(
                t.for_(SYSTEM_TIME.between("2020-01-01",
                                           "2020-02-01"))).select("*")

            self.assertEqual(
                "SELECT * FROM \"abc\" FOR SYSTEM_TIME BETWEEN '2020-01-01' AND '2020-02-01'",
                str(q),
            )

        with self.subTest("with system time from to"):
            q = Query.from_(
                t.for_(SYSTEM_TIME.from_to("2020-01-01",
                                           "2020-02-01"))).select("*")

            self.assertEqual(
                "SELECT * FROM \"abc\" FOR SYSTEM_TIME FROM '2020-01-01' TO '2020-02-01'",
                str(q),
            )

        with self.subTest("with ALL"):
            q = Query.from_(t.for_(SYSTEM_TIME.all_())).select("*")

            self.assertEqual('SELECT * FROM "abc" FOR SYSTEM_TIME ALL', str(q))

        with self.subTest("with period between"):
            q = Query.from_(
                t.for_(t.valid_period.between("2020-01-01",
                                              "2020-02-01"))).select("*")

            self.assertEqual(
                "SELECT * FROM \"abc\" FOR \"valid_period\" BETWEEN '2020-01-01' AND '2020-02-01'",
                str(q),
            )

        with self.subTest("with period from to"):
            q = Query.from_(
                t.for_(t.valid_period.from_to("2020-01-01",
                                              "2020-02-01"))).select("*")

            self.assertEqual(
                "SELECT * FROM \"abc\" FOR \"valid_period\" FROM '2020-01-01' TO '2020-02-01'",
                str(q),
            )

        with self.subTest("with ALL"):
            q = Query.from_(t.for_(t.valid_period.all_())).select("*")

            self.assertEqual('SELECT * FROM "abc" FOR "valid_period" ALL',
                             str(q))