diff options
| author | Konstantin Prokopenko <[email protected]> | 2025-09-30 17:32:19 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-30 17:32:19 +0300 |
| commit | b0af3149bca0293fb2e60dd33bd3ceca0d837fcc (patch) | |
| tree | 54f933dca9e5615a11f36789e5ec96036b6e33d5 | |
| parent | 440fe541cd8aef6d79663a2ffadc4badb9b5b81c (diff) | |
Added recipe for YDB Go SDK BulkUpsert from CSV (#25755)
| -rw-r--r-- | ydb/docs/en/core/recipes/ydb-sdk/bulk-upsert.md | 54 | ||||
| -rw-r--r-- | ydb/docs/ru/core/recipes/ydb-sdk/bulk-upsert.md | 53 |
2 files changed, 107 insertions, 0 deletions
diff --git a/ydb/docs/en/core/recipes/ydb-sdk/bulk-upsert.md b/ydb/docs/en/core/recipes/ydb-sdk/bulk-upsert.md index c76d1eac671..d6ed1eb1c5e 100644 --- a/ydb/docs/en/core/recipes/ydb-sdk/bulk-upsert.md +++ b/ydb/docs/en/core/recipes/ydb-sdk/bulk-upsert.md @@ -14,6 +14,8 @@ Below are code examples showing the {{ ydb-short-name }} SDK built-in tools for - Go (native) + {% cut "Bulk upsert with native {{ ydb-short-name }} data" %} + ```go package main @@ -84,6 +86,58 @@ Below are code examples showing the {{ ydb-short-name }} SDK built-in tools for } ``` + {% endcut %} + + {% cut "Bulk upsert `CSV` data" %} + + ```go + package main + + import ( + "context" + "fmt" + "os" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/table" + ) + + func main() { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + db, err := ydb.Open(ctx, + os.Getenv("YDB_CONNECTION_STRING"), + ydb.WithAccessTokenCredentials(os.Getenv("YDB_TOKEN")), + ) + if err != nil { + panic(err) + } + defer db.Close(ctx) + + csv := `skip row + + id,val + 42,"text42" + 43,"text43" + 44,hello + ` + + // execute bulk upsert from CSV data + err = db.Table().BulkUpsert(ctx, "/local/bulk_upsert_example", table.BulkUpsertDataCsv( + []byte(csv), + table.WithCsvHeader(), + table.WithCsvSkipRows(2), + table.WithCsvNullValue([]byte("hello")), // "hello" would be interpreted as NULL + )) + if err != nil { + fmt.Printf("unexpected error: %v", err) + } + } + ``` + + {% endcut %} + - Go (database/sql) The implementation of {{ ydb-short-name }} `database/sql` doesn't support bulk nontransactional upsert of data. diff --git a/ydb/docs/ru/core/recipes/ydb-sdk/bulk-upsert.md b/ydb/docs/ru/core/recipes/ydb-sdk/bulk-upsert.md index eb3d7c8d07e..d847415f973 100644 --- a/ydb/docs/ru/core/recipes/ydb-sdk/bulk-upsert.md +++ b/ydb/docs/ru/core/recipes/ydb-sdk/bulk-upsert.md @@ -14,6 +14,8 @@ - Go (native) + {% cut "Пакетная вставка нативных {{ ydb-short-name }} данных" %} + ```go package main @@ -84,6 +86,57 @@ } ``` + {% endcut %} + + {% cut "Пакетная вставка `CSV`" %} + + ```go + package main + + import ( + "context" + "fmt" + "os" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/table" + ) + + func main() { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + db, err := ydb.Open(ctx, + os.Getenv("YDB_CONNECTION_STRING"), + ydb.WithAccessTokenCredentials(os.Getenv("YDB_TOKEN")), + ) + if err != nil { + panic(err) + } + defer db.Close(ctx) + + csv := `skip row + + id,val + 42,"text42" + 43,"text43" + 44,hello + ` + + err = db.Table().BulkUpsert(ctx, "/local/bulk_upsert_example", table.BulkUpsertDataCsv( + []byte(csv), + table.WithCsvHeader(), + table.WithCsvSkipRows(2), + table.WithCsvNullValue([]byte("hello")), // строка "hello" будет восприниматься как NULL + )) + if err != nil { + fmt.Printf("unexpected error: %v", err) + } + } + ``` + + {% endcut %} + - Go (database/sql) Реализация `database/sql` драйвера для {{ ydb-short-name }} не поддерживает нетранзакционную пакетную вставку данных. |
