Database Reference
In-Depth Information
"
"portfolio_demo.portfolio
(portfolio_id UUID, "
"ticker TEXT, current_price
DECIMAL, "
"current_change DECIMAL, "
"current_change_percent
FLOAT, "
"PRIMARY KEY(portfolio_id,
ticker));")
Writing Data
Once our schema has been created, we can load in some data. In this example, we
will add a couple of rows to our table. Listing 9.19 shows example insert state-
ments.
Listing 9.19 Writing Data in Python
Click here to view code image
def load_data(self):
self.session.execute("INSERT INTO portfo-
lio_demo.portfolio "
"(portfolio_id, ticker, cur-
rent_price, "
" current_change, cur-
rent_change_percent) VALUES "
"(756716f7-2e54-4715-9f00-91dcbea6cf50,
'GOOG', "
" 889.07, -4.00, -0.45);")
self.session.execute("INSERT INTO portfo-
lio_demo.portfolio "
"(portfolio_id, ticker, cur-
rent_price, "
" current_change, cur-
rent_change_percent) VALUES "
"(756716f7-2e54-4715-9f00-91dcbea6cf50,
 
Search WWH ::




Custom Search