Python sqlalchemy.sql.operators.sub() Examples

The following are 29 code examples of sqlalchemy.sql.operators.sub(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.sql.operators , or try the search function .
Example #1
Source File: sqltypes.py    From planespotter with MIT License 6 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.mul: {
                Interval: Interval,
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.div: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.truediv: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.add: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.sub: {
                Numeric: self.__class__,
                Integer: self.__class__,
            }
        } 
Example #2
Source File: sqltypes.py    From android_universal with MIT License 6 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Integer: self.__class__,
                Interval: DateTime,
                Time: DateTime,
            },
            operators.sub: {
                # date - integer = date
                Integer: self.__class__,

                # date - date = integer.
                Date: Integer,

                Interval: DateTime,

                # date - datetime = interval,
                # this one is not in the PG docs
                # but works
                DateTime: Interval,
            },
        } 
Example #3
Source File: sqltypes.py    From android_universal with MIT License 6 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.mul: {
                Interval: Interval,
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.div: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.truediv: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.add: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.sub: {
                Numeric: self.__class__,
                Integer: self.__class__,
            }
        } 
Example #4
Source File: sqltypes.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Integer: self.__class__,
                Interval: DateTime,
                Time: DateTime,
            },
            operators.sub: {
                # date - integer = date
                Integer: self.__class__,

                # date - date = integer.
                Date: Integer,

                Interval: DateTime,

                # date - datetime = interval,
                # this one is not in the PG docs
                # but works
                DateTime: Interval,
            },
        } 
Example #5
Source File: sqltypes.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.mul: {
                Interval: Interval,
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.div: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.truediv: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.add: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.sub: {
                Numeric: self.__class__,
                Integer: self.__class__,
            }
        } 
Example #6
Source File: sqltypes.py    From sqlalchemy with MIT License 6 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Integer: self.__class__,
                Interval: DateTime,
                Time: DateTime,
            },
            operators.sub: {
                # date - integer = date
                Integer: self.__class__,
                # date - date = integer.
                Date: Integer,
                Interval: DateTime,
                # date - datetime = interval,
                # this one is not in the PG docs
                # but works
                DateTime: Interval,
            },
        } 
Example #7
Source File: sqltypes.py    From sqlalchemy with MIT License 6 votes vote down vote up
def _expression_adaptations(self):
        # TODO: need a dictionary object that will
        # handle operators generically here, this is incomplete
        return {
            operators.add: {
                Date: Date,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.mul: {
                Interval: Interval,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.div: {Integer: self.__class__, Numeric: Numeric},
            operators.truediv: {Integer: self.__class__, Numeric: Numeric},
            operators.sub: {Integer: self.__class__, Numeric: Numeric},
        } 
Example #8
Source File: sqltypes.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.add: {
                Date: DateTime,
                Interval: self.__class__,
                DateTime: DateTime,
                Time: Time,
            },
            operators.sub: {
                Interval: self.__class__
            },
            operators.mul: {
                Numeric: self.__class__
            },
            operators.truediv: {
                Numeric: self.__class__
            },
            operators.div: {
                Numeric: self.__class__
            }
        } 
Example #9
Source File: sqltypes.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.add: {
                Integer: self.__class__,
                Interval: DateTime,
                Time: DateTime,
            },
            operators.sub: {
                # date - integer = date
                Integer: self.__class__,

                # date - date = integer.
                Date: Integer,

                Interval: DateTime,

                # date - datetime = interval,
                # this one is not in the PG docs
                # but works
                DateTime: Interval,
            },
        } 
Example #10
Source File: sqltypes.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.mul: {
                Interval: Interval,
                Numeric: self.__class__,
            },
            operators.div: {
                Numeric: self.__class__,
            },
            operators.truediv: {
                Numeric: self.__class__,
            },
            operators.add: {
                Numeric: self.__class__,
            },
            operators.sub: {
                Numeric: self.__class__,
            }
        } 
Example #11
Source File: sqltypes.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.mul: {
                Interval: Interval,
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.div: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.truediv: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.add: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.sub: {
                Numeric: self.__class__,
                Integer: self.__class__,
            }
        } 
Example #12
Source File: sqltypes.py    From planespotter with MIT License 6 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Integer: self.__class__,
                Interval: DateTime,
                Time: DateTime,
            },
            operators.sub: {
                # date - integer = date
                Integer: self.__class__,

                # date - date = integer.
                Date: Integer,

                Interval: DateTime,

                # date - datetime = interval,
                # this one is not in the PG docs
                # but works
                DateTime: Interval,
            },
        } 
Example #13
Source File: sqltypes.py    From android_universal with MIT License 5 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Date: DateTime,
                Interval: self.__class__
            },
            operators.sub: {
                Time: Interval,
                Interval: self.__class__,
            },
        } 
Example #14
Source File: sqltypes.py    From pyRevit with GNU General Public License v3.0 5 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.add: {
                Interval: self.__class__,
            },
            operators.sub: {
                Interval: self.__class__,
                DateTime: Interval,
            },
        } 
Example #15
Source File: sqltypes.py    From planespotter with MIT License 5 votes vote down vote up
def _expression_adaptations(self):
        # TODO: need a dictionary object that will
        # handle operators generically here, this is incomplete
        return {
            operators.add: {
                Date: Date,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.mul: {
                Interval: Interval,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.div: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.truediv: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.sub: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
        } 
Example #16
Source File: sqltypes.py    From android_universal with MIT License 5 votes vote down vote up
def _expression_adaptations(self):

        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Interval: self.__class__,
            },
            operators.sub: {
                Interval: self.__class__,
                DateTime: Interval,
            },
        } 
Example #17
Source File: sqltypes.py    From planespotter with MIT License 5 votes vote down vote up
def _expression_adaptations(self):

        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Interval: self.__class__,
            },
            operators.sub: {
                Interval: self.__class__,
                DateTime: Interval,
            },
        } 
Example #18
Source File: sqltypes.py    From android_universal with MIT License 5 votes vote down vote up
def _expression_adaptations(self):
        # TODO: need a dictionary object that will
        # handle operators generically here, this is incomplete
        return {
            operators.add: {
                Date: Date,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.mul: {
                Interval: Interval,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.div: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.truediv: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.sub: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
        } 
Example #19
Source File: sqltypes.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Date: DateTime,
                Interval: self.__class__
            },
            operators.sub: {
                Time: Interval,
                Interval: self.__class__,
            },
        } 
Example #20
Source File: sqltypes.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def _expression_adaptations(self):

        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Interval: self.__class__,
            },
            operators.sub: {
                Interval: self.__class__,
                DateTime: Interval,
            },
        } 
Example #21
Source File: sqltypes.py    From planespotter with MIT License 5 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {
                Date: DateTime,
                Interval: self.__class__
            },
            operators.sub: {
                Time: Interval,
                Interval: self.__class__,
            },
        } 
Example #22
Source File: sqltypes.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def _expression_adaptations(self):
        # TODO: need a dictionary object that will
        # handle operators generically here, this is incomplete
        return {
            operators.add: {
                Date: Date,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.mul: {
                Interval: Interval,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.div: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.truediv: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.sub: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
        } 
Example #23
Source File: test_compare.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_compare_clauselist_not_assoc_different_operator(self):

        l1 = ClauseList(
            table_c.c.x, table_c.c.y, table_d.c.y, operator=operators.sub
        )

        l2 = ClauseList(
            table_c.c.x, table_c.c.y, table_d.c.y, operator=operators.div
        )

        is_false(l1.compare(l2)) 
Example #24
Source File: test_compare.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_compare_clauselist_not_associative(self):

        l1 = ClauseList(
            table_c.c.x, table_c.c.y, table_d.c.y, operator=operators.sub
        )

        l2 = ClauseList(
            table_d.c.y, table_c.c.x, table_c.c.y, operator=operators.sub
        )

        is_true(l1.compare(l1))
        is_false(l1.compare(l2)) 
Example #25
Source File: sqltypes.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _expression_adaptations(self):
        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {Date: DateTime, Interval: self.__class__},
            operators.sub: {Time: Interval, Interval: self.__class__},
        } 
Example #26
Source File: sqltypes.py    From pyRevit with GNU General Public License v3.0 5 votes vote down vote up
def _expression_adaptations(self):
        # TODO: need a dictionary object that will
        # handle operators generically here, this is incomplete
        return {
            operators.add: {
                Date: Date,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.mul: {
                Interval: Interval,
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.div: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.truediv: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
            operators.sub: {
                Integer: self.__class__,
                Numeric: Numeric,
            },
        } 
Example #27
Source File: sqltypes.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _expression_adaptations(self):

        # Based on http://www.postgresql.org/docs/current/\
        # static/functions-datetime.html.

        return {
            operators.add: {Interval: self.__class__},
            operators.sub: {Interval: self.__class__, DateTime: Interval},
        } 
Example #28
Source File: sqltypes.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _expression_adaptations(self):
        return {
            operators.mul: {
                Interval: Interval,
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.div: {Numeric: self.__class__, Integer: self.__class__},
            operators.truediv: {
                Numeric: self.__class__,
                Integer: self.__class__,
            },
            operators.add: {Numeric: self.__class__, Integer: self.__class__},
            operators.sub: {Numeric: self.__class__, Integer: self.__class__},
        } 
Example #29
Source File: test_types.py    From sqlalchemy with MIT License 4 votes vote down vote up
def setup_class(cls):
        global test_table, meta, MyCustomType, MyTypeDec

        class MyCustomType(types.UserDefinedType):
            def get_col_spec(self):
                return "INT"

            def bind_processor(self, dialect):
                def process(value):
                    return value * 10

                return process

            def result_processor(self, dialect, coltype):
                def process(value):
                    return value / 10

                return process

        class MyOldCustomType(MyCustomType):
            def adapt_operator(self, op):
                return {
                    operators.add: operators.sub,
                    operators.sub: operators.add,
                }.get(op, op)

        class MyTypeDec(types.TypeDecorator):
            impl = String

            def process_bind_param(self, value, dialect):
                return "BIND_IN" + str(value)

            def process_result_value(self, value, dialect):
                return value + "BIND_OUT"

        meta = MetaData(testing.db)
        test_table = Table(
            "test",
            meta,
            Column("id", Integer, primary_key=True),
            Column("data", String(30)),
            Column("atimestamp", Date),
            Column("avalue", MyCustomType),
            Column("bvalue", MyTypeDec(50)),
        )

        meta.create_all()

        with testing.db.connect() as conn:
            conn.execute(
                test_table.insert(),
                {
                    "id": 1,
                    "data": "somedata",
                    "atimestamp": datetime.date(2007, 10, 15),
                    "avalue": 25,
                    "bvalue": "foo",
                },
            )