Create STRUCT object with data
Stay organized with collections
Save and categorize content based on your preferences.
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.