本文整理汇总了Python中sqlalchemy.sql.cast函数的典型用法代码示例。如果您正苦于以下问题:Python cast函数的具体用法?Python cast怎么用?Python cast使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: query
def query(self):
pq = qualstat_getstatdata(column("eval_type") == "f")
base = alias(pq)
query = (select([
func.array_agg(column("queryid")).label("queryids"),
"qualid",
cast(column("quals"), JSONB).label('quals'),
"occurences",
"execution_count",
func.array_agg(column("query")).label("queries"),
"avg_filter",
"filter_ratio"
]).select_from(
join(base, powa_databases,
onclause=(
powa_databases.c.oid == literal_column("dbid"))))
.where(powa_databases.c.datname == bindparam("database"))
.where(column("avg_filter") > 1000)
.where(column("filter_ratio") > 0.3)
.group_by(column("qualid"), column("execution_count"),
column("occurences"),
cast(column("quals"), JSONB),
column("avg_filter"), column("filter_ratio"))
.order_by(column("occurences").desc())
.limit(200))
return query
开发者ID:girgen,项目名称:powa-web,代码行数:26,代码来源:wizard.py
示例2: fetch_legs
def fetch_legs(db, where):
legs = db.metadata.tables["leg_modes"]
legends0 = db.metadata.tables["leg_ends"]
legends1 = legends0.alias("legends1")
places0 = db.metadata.tables["places"]
places1 = places0.alias("places1")
s = select(
[ legs.c.id,
legs.c.time_start,
legs.c.time_end,
legs.c.activity,
legs.c.line_type,
legs.c.line_name,
legs.c.km,
legs.c.trip,
func.coalesce(places0.c.label, cast(
places0.c.id, String)).label("startplace"),
func.coalesce(places1.c.label, cast(
places1.c.id, String)).label("endplace")],
where,
legs.outerjoin(legends0, legs.c.cluster_start == legends0.c.id) \
.outerjoin(legends1, legs.c.cluster_end == legends1.c.id) \
.outerjoin(places0, legends0.c.place == places0.c.id) \
.outerjoin(places1, legends1.c.place == places1.c.id),
order_by=legs.c.time_start)
return db.engine.execute(s)
开发者ID:aalto-trafficsense,项目名称:regular-routes-server,代码行数:28,代码来源:server_common.py
示例3: aspect_range
def aspect_range(stmt, parent_uri, nodes):
"""
Find all image nodes having an aspect ratio between two values
Query parameters:
value_min - Aspect ratio (float)
value_max - Aspect ratio (float)
"""
value_min = float(nodes.pop(0))
value_max = float(nodes.pop(0))
subq = select([node_meta_table.c.md5])
subq = subq.where(
cast(node_meta_table.c.metadata.op('->')('aspect_ratio'),
Numeric(7,3)) >= value_min)
subq = subq.where(
cast(node_meta_table.c.metadata.op('->')('aspect_ratio'),
Numeric(7,3)) <= value_max)
stmt = stmt.filter(Node.md5.in_(subq))
return stmt
开发者ID:exhuma,项目名称:metafilter,代码行数:25,代码来源:nodes.py
示例4: __table_args__
def __table_args__(cls):
return (
db.Index("ix_reservations_start_dt_date", cast(cls.start_dt, Date)),
db.Index("ix_reservations_end_dt_date", cast(cls.end_dt, Date)),
db.Index("ix_reservations_start_dt_time", cast(cls.start_dt, Time)),
db.Index("ix_reservations_end_dt_time", cast(cls.end_dt, Time)),
{"schema": "roombooking"},
)
开发者ID:k3njiy,项目名称:indico,代码行数:8,代码来源:reservations.py
示例5: _build_notification_before_days_filter
def _build_notification_before_days_filter(notification_before_days):
days_until_occurrence = cast(ReservationOccurrence.start_dt, Date) - cast(func.now(), Date)
notification_before_days = func.coalesce(Room.notification_before_days, notification_before_days)
if datetime.now().hour >= settings.get('notification_hour', 6):
# Notify of today and delayed occurrences (happening in N or less days)
return days_until_occurrence <= notification_before_days
else:
# Notify only of delayed occurrences (happening in less than N days)
return days_until_occurrence < notification_before_days
开发者ID:pferreir,项目名称:indico-backup,代码行数:9,代码来源:tasks.py
示例6: find_incall_id
def find_incall_id(self, extension_id):
return (self.session.query(Incall.id)
.join(Extension,
and_(Extension.type == 'incall',
cast(Extension.typeval, Integer) == Incall.id))
.join(Dialaction,
and_(Dialaction.category == 'incall',
cast(Dialaction.categoryval, Integer) == Incall.id))
.filter(Extension.id == extension_id)
.scalar())
开发者ID:alafarcinade,项目名称:xivo-dao,代码行数:10,代码来源:fixes.py
示例7: find_all_by_member_id
def find_all_by_member_id(session, member_id):
query = (session.query(Callfiltermember.id,
sql.cast(Callfiltermember.typeval, Integer).label('member_id'),
Callfiltermember.bstype.label('role'))
.filter(Callfiltermember.type == 'user')
.filter(Callfiltermember.bstype.in_(['boss', 'secretary']))
.filter(sql.cast(Callfiltermember.typeval, Integer) == member_id)
)
return [FilterMember(id=row.id, member_id=row.member_id, role=row.role)
for row in query]
开发者ID:alafarcinade,项目名称:xivo-dao,代码行数:11,代码来源:dao.py
示例8: make_filter
def make_filter(cls, field, ftype, value):
filter = None
if ftype == 'IN':
filter = field.in_([v for v in value if v])
elif ftype == 'date_gt':
filter = field > value
elif ftype == 'date_gte':
filter = field >= value
elif ftype == 'date_gt_now_less':
qty, granularity = value.split(" ")
filter = field > func.date_trunc(granularity, func.now() - cast(value, Interval()))
elif ftype == 'date_lt_now_less':
qty, granularity = value.split(" ")
filter = field < func.date_trunc(granularity, func.now() - cast(value, Interval()))
elif ftype == 'date_x_last_n':
qty, granularity, count_current_period = value.split(" ")
filter = (field > func.date_trunc(granularity, func.now() - cast("%s %s" % (qty, granularity), Interval())), field < func.date_trunc(granularity, func.now() - cast('0', Interval())),)
if count_current_period == 'on':
filter = filter[0]
elif ftype == 'date_month_ne':
filter = extract('month', field) != value
elif ftype == 'date_month_gt':
filter = extract('month', field) > value
elif ftype == 'date_month_lt':
filter = extract('month', field) < value
elif ftype == 'date_month_eq':
filter = extract('month', field) == value
elif ftype == 'date_hour_ne':
filter = extract('hour', field) != value
elif ftype == 'date_hour_gt':
filter = extract('hour', field) > value
elif ftype == 'date_hour_lt':
filter = extract('hour', field) < value
elif ftype == 'date_hour_eq':
filter = extract('hour', field) == value
elif ftype == 'date_lt':
filter = field < value
elif ftype == 'date_lte':
filter = field <= value
elif ftype == '=':
filter = field == value
elif ftype == '!=':
filter = field != value
elif ftype == '>':
filter = field > value
elif ftype == '>=':
filter = field >= value
elif ftype == '<':
filter = field < value
elif ftype == '<=':
filter = field <= value
elif ftype == 'like':
filter = field.ilike(value)
return filter
开发者ID:josepe36,项目名称:claritick,代码行数:54,代码来源:models.py
示例9: is_in_notification_window
def is_in_notification_window(self, exclude_first_day=False):
from indico.modules.rb import settings as rb_settings
from indico.modules.rb.models.rooms import Room
in_the_past = cast(self.start_dt, Date) < cast(func.now(), Date)
days_until_occurrence = cast(self.start_dt, Date) - cast(func.now(), Date)
notification_window = func.coalesce(Room.notification_before_days,
rb_settings.get('notification_before_days', 1))
if exclude_first_day:
return (days_until_occurrence < notification_window) & ~in_the_past
else:
return (days_until_occurrence <= notification_window) & ~in_the_past
开发者ID:MichelCordeiro,项目名称:indico,代码行数:11,代码来源:reservation_occurrences.py
示例10: __getitem__
def __getitem__(self, key):
bind = self.column.table.bind
values = list(
bind.execute(
select(
[
self.function(cast(key, types.Date)).label("id"),
self.label_expression(cast(key, types.Date)).label("label"),
]
)
)
)[0]
return Member(self, values.id, values.label)
开发者ID:Kozea,项目名称:pypet,代码行数:13,代码来源:util.py
示例11: _export_reservations
def _export_reservations(hook, limit_per_room, include_rooms, extra_filters=None):
"""Exports reservations.
:param hook: The HTTPAPIHook instance
:param limit_per_room: Should the limit/offset be applied per room
:param include_rooms: Should reservations include room information
"""
filters = list(extra_filters) if extra_filters else []
if hook._fromDT and hook._toDT:
filters.append(cast(Reservation.start_dt, Date) <= hook._toDT.date())
filters.append(cast(Reservation.end_dt, Date) >= hook._fromDT.date())
filters.append(cast(Reservation.start_dt, Time) <= hook._toDT.time())
filters.append(cast(Reservation.end_dt, Time) >= hook._fromDT.time())
elif hook._toDT:
filters.append(cast(Reservation.end_dt, Date) <= hook._toDT.date())
filters.append(cast(Reservation.end_dt, Time) <= hook._toDT.time())
elif hook._fromDT:
filters.append(cast(Reservation.start_dt, Date) >= hook._fromDT.date())
filters.append(cast(Reservation.start_dt, Time) >= hook._fromDT.time())
filters += _get_reservation_state_filter(hook._queryParams)
data = ['vc_equipment']
if hook._occurrences:
data.append('occurrences')
order = {
'start': Reservation.start_dt,
'end': Reservation.end_dt
}.get(hook._orderBy, Reservation.start_dt)
if hook._descending:
order = order.desc()
reservations_data = Reservation.get_with_data(*data, filters=filters, limit=hook._limit, offset=hook._offset,
order=order, limit_per_room=limit_per_room)
for result in reservations_data:
yield result['reservation'].room_id, _serializable_reservation(result, include_rooms)
开发者ID:sofian86,项目名称:indico-gh-test,代码行数:33,代码来源:api.py
示例12: search_added
def search_added(self, year, month=None, day=None, types='*', limit=None):
''' Search by added date '''
date_trunc = 'day' if day else 'month' if month else 'year'
month, day = month or 1, day or 1
search_date = date(year, month, day)
search_for = orm.with_polymorphic(Content, types)
search_query = self.dbsession.query(search_for)
filters = sql.and_(
search_for.filter_published(),
sql.func.date_trunc(
date_trunc,
sql.cast(search_for.added, Date)
) == sql.func.date_trunc(
date_trunc, search_date
)
)
if types != '*':
ids = polymorphic_ids(search_for, types)
filters.append(search_for.content_type_id.in_(ids))
search_query = search_query.filter(filters)
count = search_query.count()
search_query = search_query.order_by(search_for.added.desc())
if limit:
search_query = search_query.limit(limit)
return search_result(search_query, count)
开发者ID:silenius,项目名称:amnesia,代码行数:32,代码来源:resources.py
示例13: filter_modified
def filter_modified(cls, part, col=None):
if col is None:
col = cls.last_update
return sql.and_(col >= sql.func.date_trunc(part, sql.func.now()),
col < sql.func.date_trunc(part, sql.func.now())\
+ sql.cast('1 %s' % part, Interval))
开发者ID:BelgianBiodiversityPlatform,项目名称:amnesia,代码行数:7,代码来源:content.py
示例14: tree_stats
def tree_stats(request, treedef, tree, parentid):
tree_table = datamodel.get_table(tree)
parentid = None if parentid == 'null' else int(parentid)
node = getattr(models, tree_table.name)
descendant = aliased(node)
node_id = getattr(node, node._id)
descendant_id = getattr(descendant, node._id)
treedef_col = tree_table.name + "TreeDefID"
same_tree_p = getattr(descendant, treedef_col) == int(treedef)
is_descendant_p = sql.and_(
sql.between(descendant.nodeNumber, node.nodeNumber, node.highestChildNodeNumber),
same_tree_p)
target, make_joins = getattr(StatsQuerySpecialization, tree)()
target_id = getattr(target, target._id)
direct_count = sql.cast(
sql.func.sum(sql.case([(sql.and_(target_id != None, descendant_id == node_id), 1)], else_=0)),
types.Integer)
all_count = sql.func.count(target_id)
with models.session_context() as session:
query = session.query(node_id, direct_count, all_count) \
.join(descendant, is_descendant_p) \
.filter(node.ParentID == parentid) \
.group_by(node_id)
query = make_joins(request.specify_collection, query, descendant_id)
results = list(query)
return HttpResponse(toJson(results), content_type='application/json')
开发者ID:Colombia1819,项目名称:specify7,代码行数:34,代码来源:tree_views.py
示例15: __call__
def __call__(self, column_clause, cuboid=None):
if cuboid and cuboid.fact_count_column is not None:
count = func.sum(cuboid.fact_count_column)
return case([(count == 0, 0)], else_=(
func.sum(column_clause * cuboid.fact_count_column) /
cast(count,
types.Numeric)))
return func.avg(column_clause)
开发者ID:Kozea,项目名称:pypet,代码行数:8,代码来源:aggregates.py
示例16: __init__
def __init__(self, level, id, label, metadata=None):
self.level = level
self.id = id
self.label = label
self.label_expression = cast(_literal_as_binds(self.label),
types.Unicode)
self.id_expr = _literal_as_binds(self.id)
self.metadata = metadata or MetaData()
开发者ID:Kozea,项目名称:pypet,代码行数:8,代码来源:__init__.py
示例17: __init__
def __init__(self, itemtype, itemcount):
self.itemtype = itemtype
self.itemcount = itemcount
self.query = select(
[cast(func.sum(Item.itemcount), Integer)],
and_(Item.roleid == bindparam("roleid", type_=Integer), Item.itemtype == itemtype),
)
self.what = intern(":".join([self.__class__.__name__, str(itemtype), str(itemcount)]))
开发者ID:texnician,项目名称:py_embed,代码行数:8,代码来源:orm.py
示例18: col
def col(name, table):
try:
return colnamemaps[table][name]
except KeyError:
if cast_nulls:
return sql.cast(sql.null(), types[name]).label(name)
else:
return sql.type_coerce(sql.null(), types[name]).label(name)
开发者ID:Am3s,项目名称:CouchPotatoServer,代码行数:8,代码来源:util.py
示例19: allTransactionMonths
def allTransactionMonths():
session = requireSession()
parts = "year", "month"
query = session \
.query(*[cast(date_part(p, M.Transaction.date), INT)
.label(p) for p in parts]) \
.order_by(*[asc(p) for p in parts]) \
.distinct()
return list(query)
开发者ID:georgevdd,项目名称:bank-account-reporting,代码行数:9,代码来源:Queries.py
示例20: filter_effective
def filter_effective(cls, today=None, timez='UTC'):
"""Select items for which the effective date has been reached"""
if not today:
today = datetime.today()
return sql.func.coalesce(
cls.effective,
sql.cast('-infinity', DateTime(timezone=timez))
) <= today
开发者ID:silenius,项目名称:amnesia,代码行数:9,代码来源:model.py
注:本文中的sqlalchemy.sql.cast函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论