コード例 #1
0
    def _test_array_zero_indexes(self, zero_indexes):
        c = Column('x', postgresql.ARRAY(Integer, zero_indexes=zero_indexes))

        add_one = 1 if zero_indexes else 0

        self.assert_compile(
            cast(c, postgresql.ARRAY(Integer, zero_indexes=zero_indexes)),
            "CAST(x AS INTEGER[])")
        self.assert_compile(c[5],
                            "x[%(x_1)s]",
                            checkparams={'x_1': 5 + add_one})

        self.assert_compile(c[5:7],
                            "x[%(x_1)s:%(x_2)s]",
                            checkparams={
                                'x_2': 7 + add_one,
                                'x_1': 5 + add_one
                            })
        self.assert_compile(c[5:7][2:3],
                            "x[%(x_1)s:%(x_2)s][%(param_1)s:%(param_2)s]",
                            checkparams={
                                'x_2': 7 + add_one,
                                'x_1': 5 + add_one,
                                'param_1': 2 + add_one,
                                'param_2': 3 + add_one
                            })
        self.assert_compile(c[5:7][3],
                            "x[%(x_1)s:%(x_2)s][%(param_1)s]",
                            checkparams={
                                'x_2': 7 + add_one,
                                'x_1': 5 + add_one,
                                'param_1': 3 + add_one
                            })
コード例 #2
0
    def test_array(self):
        c = Column('x', postgresql.ARRAY(Integer))

        self.assert_compile(cast(c, postgresql.ARRAY(Integer)),
                            "CAST(x AS INTEGER[])")
        self.assert_compile(c[5], "x[%(x_1)s]", checkparams={'x_1': 5})

        self.assert_compile(c[5:7],
                            "x[%(x_1)s:%(x_2)s]",
                            checkparams={
                                'x_2': 7,
                                'x_1': 5
                            })
        self.assert_compile(c[5:7][2:3],
                            "x[%(x_1)s:%(x_2)s][%(param_1)s:%(param_2)s]",
                            checkparams={
                                'x_2': 7,
                                'x_1': 5,
                                'param_1': 2,
                                'param_2': 3
                            })
        self.assert_compile(c[5:7][3],
                            "x[%(x_1)s:%(x_2)s][%(param_1)s]",
                            checkparams={
                                'x_2': 7,
                                'x_1': 5,
                                'param_1': 3
                            })

        self.assert_compile(c.contains([1]),
                            'x @> %(x_1)s',
                            checkparams={'x_1': [1]})
        self.assert_compile(c.contained_by([2]),
                            'x <@ %(x_1)s',
                            checkparams={'x_1': [2]})
        self.assert_compile(c.overlap([3]),
                            'x && %(x_1)s',
                            checkparams={'x_1': [3]})
        self.assert_compile(postgresql.Any(4, c),
                            '%(param_1)s = ANY (x)',
                            checkparams={'param_1': 4})
        self.assert_compile(c.any(5, operator=operators.ne),
                            '%(param_1)s != ANY (x)',
                            checkparams={'param_1': 5})
        self.assert_compile(postgresql.All(6, c, operator=operators.gt),
                            '%(param_1)s > ALL (x)',
                            checkparams={'param_1': 6})
        self.assert_compile(c.all(7, operator=operators.lt),
                            '%(param_1)s < ALL (x)',
                            checkparams={'param_1': 7})
コード例 #3
0
 def test_array_literal_insert(self):
     m = MetaData()
     t = Table('t', m, Column('data', postgresql.ARRAY(Integer)))
     self.assert_compile(
         t.insert().values(data=array([1, 2, 3])),
         "INSERT INTO t (data) VALUES (ARRAY[%(param_1)s, "
         "%(param_2)s, %(param_3)s])")
コード例 #4
0
 def test_update_array_element(self):
     m = MetaData()
     t = Table('t', m, Column('data', postgresql.ARRAY(Integer)))
     self.assert_compile(
         t.update().values({t.c.data[5]: 1}),
         "UPDATE t SET data[%(data_1)s]=%(param_1)s",
         checkparams={'data_1': 5, 'param_1': 1}
     )