How to use the pypika.fn function in PyPika

To help you get started, we’ve selected a few PyPika examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kayak / pypika / test / test_functions.py View on Github external
def test__lower__str(self):
        q = Q.select(fn.Lower('ABC'))

        self.assertEqual("SELECT LOWER('ABC')", str(q))
github kayak / pypika / test / test_functions.py View on Github external
def test__min(self):
        q = Q.from_('abc').select(fn.Min('foo'))

        self.assertEqual('SELECT MIN(foo) FROM abc', str(q))
github kayak / pypika / test / test_joins.py View on Github external
def test_select_field_from_missing_table(self):
        with self.assertRaises(JoinException):
            Query.from_(self.t0).select(self.t1.foo)

        with self.assertRaises(JoinException):
            Query.from_(self.t0).where(self.t1.foo == 0)

        with self.assertRaises(JoinException):
            Query.from_(self.t0).where(fn.Sum(self.t1.foo) == 0)

        with self.assertRaises(JoinException):
            Query.from_(self.t0).select(fn.Sum(self.t0.bar * 2) + fn.Sum(self.t1.foo * 2))

        with self.assertRaises(JoinException):
            Query.from_(self.t0).groupby(self.t1.foo)

        with self.assertRaises(JoinException):
            Query.from_(self.t0).groupby(self.t0.foo).having(self.t1.bar)
github kayak / pypika / test / test_functions.py View on Github external
def test__max(self):
        q = Q.from_('abc').select(fn.Max('foo'))

        self.assertEqual('SELECT MAX(foo) FROM abc', str(q))
github kayak / pypika / test / test_selects.py View on Github external
def test_functions_using_constructor_param(self):
        q = Query.from_(self.t).select(fn.Count('*', alias='foo'))

        self.assertEqual('SELECT COUNT(*) foo FROM abc', str(q))
github kayak / pypika / test / test_criterions.py View on Github external
def test_function_with_values_and_fields_for_table(self):
        f = fn.Mod(self.t0.foo, 2).for_(self.t1)

        self.assertEqual('MOD(t1.foo,2)', str(f))
github kayak / pypika / test / test_selects.py View on Github external
def test_groupby__count_distinct(self):
        q = Query.from_(self.t).groupby(self.t.foo).select(self.t.foo, fn.Count('*').distinct())

        self.assertEqual('SELECT foo,COUNT(DISTINCT *) FROM abc GROUP BY foo', str(q))
github kayak / pypika / test / test_functions.py View on Github external
def test__cast__signed(self):
        q1 = Q.from_(self.t).select(fn.Signed(self.t.foo))
        q2 = Q.from_(self.t).select(fn.Cast(self.t.foo, 'SIGNED'))

        self.assertEqual("SELECT CAST(foo AS SIGNED) FROM abc", str(q1))
        self.assertEqual("SELECT CAST(foo AS SIGNED) FROM abc", str(q2))
github kayak / pypika / test / test_joins.py View on Github external
def test_prefixes_added_to_function_in_orderby(self):
        test_query = Query.from_(self.t0).join(self.t1).on(
            self.t0.foo == self.t1.bar
        ).select(self.t0.foo, self.t1.buz).orderby(fn.Date(self.t0.foo))

        self.assertEqual('SELECT t0.foo,t1.buz FROM abc t0 '
                         'JOIN efg t1 ON t0.foo=t1.bar '
                         'ORDER BY DATE(t0.foo)', str(test_query))