@@ -510,16 +510,16 @@ def insert_data_with_timestamp(instance_id, database_id):
510
510
511
511
512
512
# [START spanner_add_timestamp_column]
513
- def add_timestamp_column (database_id , instance_id ):
513
+ def add_timestamp_column (instance_id , database_id ):
514
514
"""Adds a new TIMESTAMP column to the Albums table in the example database."""
515
515
spanner_client = spanner .Client ()
516
516
instance = spanner_client .instance (instance_id )
517
517
518
518
database = instance .database (database_id )
519
519
520
- operation = database .update_ddl (
520
+ operation = database .update_ddl ([
521
521
'ALTER TABLE Albums ADD COLUMN LastUpdateTime TIMESTAMP '
522
- 'OPTIONS(allow_commit_timestamp=true)' )
522
+ 'OPTIONS(allow_commit_timestamp=true)' ] )
523
523
524
524
print ('Waiting for operation to complete...' )
525
525
operation .result ()
@@ -530,20 +530,20 @@ def add_timestamp_column(database_id, instance_id):
530
530
531
531
532
532
# [START spanner_update_data_with_timestamp_column]
533
- def update_data_with_timestamp (database_id , instance_id ):
533
+ def update_data_with_timestamp (instance_id , database_id ):
534
534
"""Updates Performances tables in the database with the COMMIT_TIMESTAMP column.
535
535
536
536
This updates the `MarketingBudget` column which must be created before
537
537
running this sample. You can add the column by running the `add_column`
538
538
sample or by running this DDL statement against your database:
539
539
540
- ALTER TABLE Performances ADD COLUMN MarketingBudget INT64
540
+ ALTER TABLE Albums ADD COLUMN MarketingBudget INT64
541
541
542
542
In addition this update expects the LastUpdateTime column added by
543
543
applying this DDL statement against your database:
544
544
545
- ALTER TABLE Performances ADD COLUMN LastUpdateTime TIMESTAMP
546
- OPTIONS (allow_commit_timestamp=true)
545
+ ALTER TABLE Albums ADD COLUMN LastUpdateTime TIMESTAMP
546
+ OPTIONS(allow_commit_timestamp=true)
547
547
"""
548
548
spanner_client = spanner .Client ()
549
549
instance = spanner_client .instance (instance_id )
@@ -554,11 +554,11 @@ def update_data_with_timestamp(database_id, instance_id):
554
554
batch .update (
555
555
table = 'Albums' ,
556
556
columns = (
557
- 'SingerId' , 'AlbumId' , 'MarketingBudget' ),
557
+ 'SingerId' , 'AlbumId' , 'MarketingBudget' , 'LastUpdateTime' ),
558
558
values = [
559
- (1 , 4 , "2017-10-05" , 11000 , spanner .COMMIT_TIMESTAMP ),
560
- (1 , 19 , "2017-11-02" , 15000 , spanner .COMMIT_TIMESTAMP ),
561
- (2 , 42 , "2017-12-23" , 7000 , spanner .COMMIT_TIMESTAMP )])
559
+ (1 , 4 , 11000 , spanner .COMMIT_TIMESTAMP ),
560
+ (1 , 19 , 15000 , spanner .COMMIT_TIMESTAMP ),
561
+ (2 , 42 , 7000 , spanner .COMMIT_TIMESTAMP )])
562
562
563
563
print ('Updated data.' )
564
564
# [END spanner_update_data_with_timestamp_column]
@@ -584,8 +584,8 @@ def query_data_with_timestamp(instance_id, database_id):
584
584
585
585
with database .snapshot () as snapshot :
586
586
results = snapshot .execute_sql (
587
- 'SELECT SingerId, AlbumId, AlbumTitle FROM Albums'
588
- 'FROM Albums ORDER BY LastUpdateTime DESC' )
587
+ 'SELECT SingerId, AlbumId, AlbumTitle FROM Albums '
588
+ 'ORDER BY LastUpdateTime DESC' )
589
589
590
590
for row in results :
591
591
print (u'SingerId: {}, AlbumId: {}, AlbumTitle: {}' .format (* row ))
0 commit comments