Esempio n. 1
0
def compile_case(compile, expr, state):
    stmt = "CASE WHEN %s THEN %s" % (expr_compile(expr.condition, state),
                                     expr_compile(expr.result, state))
    if expr.else_ is not None:
        stmt += ' ELSE ' + expr_compile(expr.else_, state)
    stmt += ' END'
    return stmt
Esempio n. 2
0
def compile_case(compile, expr, state):
    stmt = "CASE WHEN %s THEN %s" % (expr_compile(expr.condition, state),
                                     expr_compile(expr.result, state))
    if expr.else_ is not None:
        stmt += ' ELSE ' + expr_compile(expr.else_, state)
    stmt += ' END'
    return stmt
Esempio n. 3
0
def compile_prefix_expr(compile, expr, state):
    stmt = "CASE WHEN %s THEN %s" % (expr_compile(expr.condition, state),
                                     expr_compile(expr.result, state))
    if expr.else_:
        stmt += ' ELSE ' + expr_compile(expr.else_, state)
    stmt += ' END'
    return stmt
Esempio n. 4
0
def compile_generate_series(compile, expr, state):
    state.push("context", EXPR)
    if expr.step is Undef:
        expr = 'generate_series(%s, %s)' % (expr_compile(expr.start, state),
                                            expr_compile(expr.end, state))
    else:
        expr = 'generate_series(%s, %s, %s)' % (expr_compile(expr.start, state),
                                                expr_compile(expr.end, state),
                                                expr_compile(expr.step, state))
    state.pop()
    return expr
Esempio n. 5
0
def compile_generate_series(compile, expr, state):
    state.push("context", EXPR)
    if expr.step is Undef:
        expr = 'generate_series(%s, %s)' % (expr_compile(expr.start, state),
                                            expr_compile(expr.end, state))
    else:
        expr = 'generate_series(%s, %s, %s)' % (expr_compile(expr.start, state),
                                                expr_compile(expr.end, state),
                                                expr_compile(expr.step, state))
    state.pop()
    return expr
Esempio n. 6
0
def compile_over(compile, expr, state):

    result = ' %s OVER (' % expr_compile(expr.attribute, state)

    if expr.partitions:
        partitions = ', '.join(expr_compile(i, state) for i in expr.partitions)
        result += 'PARTITION BY %s ' % partitions

    if expr.orders:
        orders = ', '.join(expr_compile(i, state) for i in expr.orders)
        result += 'ORDER BY %s ' % orders

    result += ')'
    return result
Esempio n. 7
0
def compile_over(compile, expr, state):

    result = ' %s OVER (' % expr_compile(expr.attribute, state)

    if expr.partitions:
        partitions = ', '.join(expr_compile(i, state) for i in expr.partitions)
        result += 'PARTITION BY %s ' % partitions

    if expr.orders:
        orders = ', '.join(expr_compile(i, state) for i in expr.orders)
        result += 'ORDER BY %s ' % orders

    result += ')'
    return result
Esempio n. 8
0
def compile_in(expr_compile, expr, state):
    expr1 = expr_compile(expr.expr1, state)
    state.precedence = 0  # We're forcing parenthesis here.
    return "%s %s (%s)" % (expr1, expr.oper, expr_compile(expr.expr2, state))
Esempio n. 9
0
def compile_contains(expr_compile, expr, state):
    # We currently support only the first argument as a list.
    expr1 = "ARRAY[%s]" % ",".join(expr_compile(i, state) for i in expr.expr1)

    return '%s%s%s' % (expr1, expr.oper,
                       expr_compile(expr.expr2, state))
Esempio n. 10
0
def compile_array(expr_compile, expr, state):
    return "ARRAY[%s]" % ",".join(expr_compile(i, state) for i in expr.array)
Esempio n. 11
0
def compile_between(compile, expr, state):
    return ' %s BETWEEN %s AND %s ' % (
        expr_compile(expr.value, state),
        expr_compile(expr.start, state),
        expr_compile(expr.end, state))
Esempio n. 12
0
def compile_in(expr_compile, expr, state):
    expr1 = expr_compile(expr.expr1, state)
    state.precedence = 0  # We're forcing parenthesis here.
    return "%s %s (%s)" % (expr1, expr.oper, expr_compile(expr.expr2, state))
Esempio n. 13
0
def compile_contains(expr_compile, expr, state):
    # We currently support only the first argument as a list.
    expr1 = "ARRAY[%s]" % ",".join(expr_compile(i, state) for i in expr.expr1)

    return '%s%s%s' % (expr1, expr.oper,
                       expr_compile(expr.expr2, state))
Esempio n. 14
0
def compile_position(compile, expr, state):
    return "%s(%s in %s)" % (expr.name, expr_compile(expr.substring, state),
                             expr_compile(expr.string, state))
Esempio n. 15
0
def compile_trim(compile, expr, state):
    return "TRIM(%s %s FROM %s)" % (
        expr.op,
        expr_compile(expr.character, state),
        expr_compile(expr.column, state))
Esempio n. 16
0
def compile_concat(compile, expr, state):
    return " || ".join(expr_compile(input_, state) for input_ in expr.inputs)
Esempio n. 17
0
def compile_trim(compile, expr, state):
    return "TRIM(%s %s FROM %s)" % (
        expr.op,
        expr_compile(expr.character, state),
        expr_compile(expr.column, state))
Esempio n. 18
0
def compile_concat(compile, expr, state):
    return " || ".join(expr_compile(input_, state) for input_ in expr.inputs)
Esempio n. 19
0
def compile_between(compile, expr, state):
    return ' %s BETWEEN %s AND %s ' % (
        expr_compile(expr.value, state),
        expr_compile(expr.start, state),
        expr_compile(expr.end, state))
Esempio n. 20
0
def compile_position(compile, expr, state):
    return "%s(%s in %s)" % (expr.name, expr_compile(expr.substring, state),
                             expr_compile(expr.string, state))
Esempio n. 21
0
def compile_filter(compile, expr, state):
    stmt = "%s FILTER (WHERE %s )" % (expr_compile(expr.expr, state),
                                      expr_compile(expr.clause, state))
    return stmt