db.define_table(‘cat’,
Field('name', 'string', length=45),
Field(‘age’, ‘integer’),
Field(‘apt_time’,’datetime’)
)
db.define_table(‘dog’,
Field('name', 'string', length=45),
Field(‘age’, ‘integer’),
Field(‘apt_time’,’datetime’)
)
#Controller
query = ((db.cat.age == 3) | (db.dog.age == 3))
union_rows = db(query).select()
print union_rows
The returned value is a single row object, containing an entry for each table.
<Row {‘cat’: {'name': ‘FLUFFY’, 'age': 3L, 'apt_time': datetime.datetime(2017, 4, 22, 16, 22, 10), }, ‘dog’: {'name': ‘SPOT’, 'age': 3L, 'apt_time': datetime.datetime(2017, 4, 22, 16, 22, 10), }}>
FLUFFY 3 2017-04-22 16:22:10 SPOT 3 2017-04-22 16:22:10
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
db.define_table(‘animal’,
Field('name', 'string', length=45),
Field(‘age’, ‘integer’),
Field(‘apt_time’,’datetime’)
and then subclass:
db.define_table(‘cat’, db.animal)
and
db.define_table(‘dog’, db.animal)
and then query on db.animal ?
--
Forgot to mention... If you for some reason you can't refactor your schema... you can unionize query in web2py like so :select_cat = db(db.cat.id>0).select()select_dog = db(db.dog.id>0).select()select_cat_and_dog = select_cat | select_dogNote: You can use & or | they are python binary operator, if I recall used like that combine with web2py query they mimic union (no duplicate) and union all (keep duplicate)...
--
sql = """
SELECT * FROM table1
UNION SELECT * FROM table2"""
rows = db.executesql(sql, fields = [
Field("name", "string")
, Field("age", "integer")
, Field("apt_time", "datetime")
])
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/lnjK7nibOqw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/lnjK7nibOqw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.