Here are the examples of the python api sqlalchemy.select.scalar taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
Example 1
Project: sqlalchemy Source File: test_functions.py
@testing.fails_on_everything_except('postgresql')
def test_as_from(self):
# TODO: shouldn't this work on oracle too ?
x = func.current_date(bind=testing.db).execute().scalar()
y = func.current_date(bind=testing.db).select().execute().scalar()
z = func.current_date(bind=testing.db).scalar()
w = select(['*'], from_obj=[func.current_date(bind=testing.db)]).\
scalar()
# construct a column-based FROM object out of a function,
# like in [ticket:172]
s = select([sql.column('date', type_=DateTime)],
from_obj=[func.current_date(bind=testing.db)])
q = s.execute().first()[s.c.date]
r = s.alias('datequery').select().scalar()
assert x == y == z == w == q == r
0
Example 2
Project: zipline Source File: test_assets.py
def test_write_version(self):
version_table = self.metadata.tables['version_info']
version_table.delete().execute()
# Assert that the version is not present in the table
self.assertIsNone(sa.select((version_table.c.version,)).scalar())
# This should fail because the table has no version info and is,
# therefore, consdered v0
with self.assertRaises(AssetDBVersionError):
check_version_info(self.engine, version_table, -2)
# This should not raise an error because the version has been written
write_version_info(self.engine, version_table, -2)
check_version_info(self.engine, version_table, -2)
# Assert that the version is in the table and correct
self.assertEqual(sa.select((version_table.c.version,)).scalar(), -2)
# Assert that trying to overwrite the version fails
with self.assertRaises(sa.exc.IntegrityError):
write_version_info(self.engine, version_table, -3)