Writing Data to a Greenplum Table

A newer version of this documentation is available. Use the version menu above to view the most up-to-date release of the Greenplum 6.x documentation.

Writing Data to a Greenplum Table

After opening a Greenplum Database table with a specific open mode, a GPSS client can write one or more rows of data to the table. The client must map the source data to a gRPC data type. The GPSS server maps the gRPC type to a Greenplum Database type as specified in Data Type Mapping.

The Write service definition and relevant messages follow:

rpc Write(WriteRequest) returns(google.protobuf.Empty) {}

message DBValue {
  oneof DBType {
    int32 Int32Value = 1;
    int64 Int64Value = 2;
    float Float32Value = 5;
    double Float64Value = 6;
    string StringValue = 7;
    bytes BytesValue = 8;
    google.protobuf.Timestamp TimeStampValue = 10;
    google.protobuf.NullValue NullValue = 11;

message Row {
  repeated DBValue Columns = 1;

message RowData {    
  bytes Data = 1;

message WriteRequest {
  Session Session = 1;
  repeated RowData Rows = 2;

Sample Java code to write two rows of data to the loaninfo table that you opened in insert mode in the previous section follows:

// create an array of rows
ArrayList<RowData> rows = new ArrayList<>();
for (int row = 0; row < 2; row++) {
  // create a row builder
  api.Row.Builder builder = api.Row.newBuilder();

  // create builders for each column, in order, and set values - text, int, text
  api.DBValue.Builder colbuilder1 = api.DBValue.newBuilder();
  api.DBValue.Builder colbuilder2 = api.DBValue.newBuilder();
  api.DBValue.Builder colbuilder3 = api.DBValue.newBuilder();

  // build the row
  RowData.Builder rowbuilder = RowData.newBuilder().setData(builder.build().toByteString());

  // add the row

// create a write request builder
WriteRequest wReq = WriteRequest.newBuilder()

// use the blocking stub to call the Write service; it returns nothing

The client determines the success or failure of the write operation from the TransferStats returned when the client closes the table.