66
66
* Example code for using the Cloud Spanner PostgreSQL interface.
67
67
*/
68
68
public class PgSpannerSample {
69
+ // [START spanner_postgresql_insert_data]
69
70
static final List <Singer > SINGERS =
70
71
Arrays .asList (
71
72
new Singer (1 , "Marc" , "Richards" ),
@@ -80,6 +81,7 @@ public class PgSpannerSample {
80
81
new Album (2 , 1 , "Green" ),
81
82
new Album (2 , 2 , "Forever Hold Your Peace" ),
82
83
new Album (2 , 3 , "Terrified" ));
84
+ // [END spanner_postgresql_insert_data]
83
85
84
86
/** Class to contain performance sample data. */
85
87
static class Performance {
@@ -201,6 +203,7 @@ static void createPostgreSqlDatabase(DatabaseAdminClient dbAdminClient, Database
201
203
// Initiate the request which returns an OperationFuture.
202
204
Database db = op .get ();
203
205
System .out .println ("Created database [" + db .getId () + "]" );
206
+ createTableUsingDdl (dbAdminClient , id );
204
207
} catch (ExecutionException e ) {
205
208
// If the operation failed during execution, expose the cause.
206
209
throw (SpannerException ) e .getCause ();
@@ -652,6 +655,7 @@ static void writeWithTransactionUsingDml(DatabaseClient dbClient) {
652
655
// [END spanner_postgresql_dml_getting_started_update]
653
656
654
657
// [START spanner_postgresql_create_table_using_ddl]
658
+ // [START spanner_postgresql_create_database]
655
659
static void createTableUsingDdl (DatabaseAdminClient dbAdminClient , DatabaseId id ) {
656
660
OperationFuture <Void , UpdateDatabaseDdlMetadata > op =
657
661
dbAdminClient .updateDatabaseDdl (
@@ -685,6 +689,7 @@ static void createTableUsingDdl(DatabaseAdminClient dbAdminClient, DatabaseId id
685
689
throw SpannerExceptionFactory .propagateInterrupt (e );
686
690
}
687
691
}
692
+ // [END spanner_postgresql_create_database]
688
693
// [END spanner_postgresql_create_table_using_ddl]
689
694
690
695
// [START spanner_postgresql_read_stale_data]
@@ -1319,7 +1324,7 @@ static void run(
1319
1324
String command ,
1320
1325
DatabaseId database ) {
1321
1326
switch (command ) {
1322
- case "createpgdatabase " :
1327
+ case "createdatabase " :
1323
1328
createPostgreSqlDatabase (dbAdminClient , database );
1324
1329
break ;
1325
1330
case "write" :
@@ -1467,7 +1472,7 @@ static void printUsageAndExit() {
1467
1472
System .err .println (" PgSpannerExample <command> <instance_id> <database_id>" );
1468
1473
System .err .println ();
1469
1474
System .err .println ("Examples:" );
1470
- System .err .println (" PgSpannerExample createpgdatabase my-instance example-db" );
1475
+ System .err .println (" PgSpannerExample createdatabase my-instance example-db" );
1471
1476
System .err .println (" PgSpannerExample write my-instance example-db" );
1472
1477
System .err .println (" PgSpannerExample delete my-instance example-db" );
1473
1478
System .err .println (" PgSpannerExample query my-instance example-db" );
0 commit comments