예제 #1
0
async def test_position(conn):
    result = await conn.fetch_b('SELECT :a',
                                a=funcs.position('xx', 'testing xx more'))
    assert [dict(r) for r in result] == [{'position': 9}]
예제 #2
0
 (lambda: V('a').nulls_last(), 'a NULLS LAST'),
 (lambda: V('a').desc().nulls_first(), 'a DESC NULLS FIRST'),
 (lambda: ~V('a'), 'not(a)'),
 (lambda: -V('a'), '-a'),
 (lambda: V('x').operate(RawDangerous(' foobar '), V('y')), 'x foobar y'),
 (lambda: funcs.sqrt(4), '|/ $1'),
 (lambda: funcs.abs(4), '@ $1'),
 (lambda: funcs.factorial(4), '$1!'),
 (lambda: funcs.count('*'), 'COUNT(*)'),
 (lambda: funcs.count(V('*')), 'COUNT(*)'),
 (lambda: funcs.count('*').as_('foobar'), 'COUNT(*) AS foobar'),
 (lambda: funcs.upper('a'), 'upper($1)'),
 (lambda: funcs.lower('a'), 'lower($1)'),
 (lambda: funcs.lower('a') > 4, 'lower($1) > $2'),
 (lambda: funcs.length('a'), 'length($1)'),
 (lambda: funcs.position('a', 'b'), 'position($1 in $2)'),
 (lambda: funcs.substring('a', 'b'), 'substring($1 from $2)'),
 (lambda: funcs.substring('x', 2, 3), 'substring($1 from $2 for $3)'),
 (lambda: funcs.extract(V('epoch').from_(V('foo.bar'))).cast('int'), 'extract(epoch from foo.bar)::int'),
 (lambda: funcs.AND('a', 'b', 'c'), '$1 AND $2 AND $3'),
 (lambda: funcs.AND('a', 'b', V('c') | V('d')), '$1 AND $2 AND (c OR d)'),
 (lambda: funcs.OR('a', 'b', V('c') & V('d')), '$1 OR $2 OR c AND d'),
 (lambda: funcs.comma_sep('a', 'b', V('c') | V('d')), '$1, $2, c OR d'),
 (lambda: funcs.comma_sep(V('first_name'), 123), 'first_name, $1'),
 (lambda: Func('foobar', V('x'), V('y')), 'foobar(x, y)'),
 (lambda: Func('foobar', funcs.comma_sep('x', 'y')), 'foobar($1, $2)'),
 (lambda: Empty() & (V('foo') == 4), ' AND foo = $1'),
 (lambda: Empty() & (V('bar') == 4), ' AND bar = $1'),
 (lambda: V('epoch').at_time_zone('MST'), 'epoch AT TIME ZONE $1'),
 (lambda: S('2032-02-16 19:38:40-08').at_time_zone('MST'), '$1 AT TIME ZONE $2'),
 (lambda: V('foo').matches(V('bar')), 'foo @@ bar'),