Create STRUCT object with data

Create a STRUCT object populated with data.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C++

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// Cloud Spanner STRUCT<> types are represented by std::tuple<...>. The
// following represents a STRUCT<> with two unnamed STRING fields.
usingNameType=std::tuple<std::string,std::string>;
autosinger_info=NameType{"Elena","Campbell"};

C#

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

varnameStruct=newSpannerStruct
{
{"FirstName",SpannerDbType.String,"Elena"},
{"LastName",SpannerDbType.String,"Campbell"},
};

Go

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


typenamestruct{
FirstNamestring
LastNamestring
}
varsingerInfo=name{"Elena","Campbell"}

Java

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

Structname=
Struct.newBuilder().set("FirstName").to("Elena").set("LastName").to("Campbell").build();

Node.js

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// Imports the Google Cloud client library
const{Spanner}=require('@google-cloud/spanner');
constnameStruct=Spanner .struct ({
FirstName:'Elena',
LastName:'Campbell',
});

PHP

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

$nameValue = (new StructValue)
 ->add('FirstName', 'Elena')
 ->add('LastName', 'Campbell');
$nameType = (new StructType)
 ->add('FirstName', Database::TYPE_STRING)
 ->add('LastName', Database::TYPE_STRING);

Python

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

record_type = param_types.Struct(
 [
 param_types.StructField("FirstName", param_types.STRING),
 param_types.StructField("LastName", param_types.STRING),
 ]
)
record_value = ("Elena", "Campbell")

Ruby

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

name_struct={FirstName:"Elena",LastName:"Campbell"}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.