CData Python Connector for Google Analytics

Build 20.0.7587

Other SQL Clauses

SQLAlchemy ORM also exposes support for other clauses in SQL, such as ORDER BY, GROUP BY, LIMIT, and OFFSET. All of these are supported by this connector:

ORDER BY

The below example sorts by a specified column using the session object's query() method.

for instance in session.query(Traffic).order_by(Traffic.AnnualRevenue):
	print("Id: ", instance.Id)
	print("Browser: ", instance.Browser)
	print("DeviceCategory: ", instance.DeviceCategory)
	print("---------")

Alternatively, you can perform an ORDER BY using the session object's execute() method.

for instance in session.execute(Traffic_table.select().order_by(Traffic_table.c.AnnualRevenue)):

GROUP BY

The below example groups records with a specified column using the session object's query() method.

for instance in session.query(func.count(Traffic.Id).label("CustomCount"), Traffic.Browser).group_by(Traffic.Browser):
	print("Count: ", instance.CustomCount)
	print("Browser: ", instance.Browser)
	print("---------")

Alternatively, you can perform a GROUP BY using the session object's execute() method.

for instance in session.execute(Traffic_table.select().with_only_columns([func.count(Traffic_table.c.Id).label("CustomCount"), Traffic_table.c.Browser])group_by(Traffic_table.c.Browser)):

LIMIT and OFFSET

The below example skips the first 100 records and fetches the following 25 using the session object's query() method.

for instance in session.query(Traffic).limit(25).offset(100):
	print("Id: ", instance.Id)
	print("Browser: ", instance.Browser)
	print("DeviceCategory: ", instance.DeviceCategory)
	print("---------")

Alternatively, you can set a LIMIT or OFFSET using the session object's execute() method.

for instance in session.execute(Traffic_table.select().limit(25).offset(100)):

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587