name: gaussdb-adaptation
description: Use this skill when porting SQL Server or vanilla PostgreSQL code to Huawei GaussDB (Kernel 505.x / openGauss-based). TRIGGER when source code or SQL contains any of — Microsoft.Data.SqlClient, SqlBulkCopy, NEXT VALUE FOR, ON COMMIT DROP, CREATE TEMPORARY SEQUENCE, dbo., NVARCHAR, ISNULL(, GETDATE(), OPTION (MAXDOP, TOP N, @@IDENTITY, WITH (NOLOCK), [bracketed] identifiers, #tempTable; OR csproj references DotNetCore.GaussDB, DotNetCore.EntityFrameworkCore.GaussDB, HuaweiCloud.Driver.GaussDB, HuaweiCloud.EntityFrameworkCore.GaussDB, Npgsql.EntityFrameworkCore.PostgreSQL alongside a GaussDB target; OR appsettings has Persistence.Provider=GaussDb; OR user mentions GaussDB / openGauss / 高斯数据库 / SHA256 SASL / password_encryption_type / apuração GaussDB migration.
GaussDB Adaptation
Overview
GaussDB (Huawei, kernel 505.x / openGauss-based) speaks a PG-compatible but not identical dialect. Code that compiles and runs against SQL Server — or even vanilla PostgreSQL — often fails on GaussDB in three categories:
- SQL dialect — e.g.
CREATE TEMPORARY SEQUENCEandON COMMIT DROPare rejected at runtime - Driver / authentication —
DotNetCore.GaussDBfails SHA256-only servers with a cryptic protocol error; Huawei's ownHuaweiCloud.Driver.GaussDBworks but uses a different namespace - Bulk loading —
SqlBulkCopyhas no drop-in replacement; the correct pattern isBeginBinaryImport+COPY ... FROM STDIN BINARY
The skill encodes landmines discovered on a real production port, with concrete before/after pairs.
Quick Start
For any adaptation task, run this 4-step flow:
- Audit — run
scripts/sql_dialect_audit.py <project-root>to locate all anti-patterns, or grep for them manually (trigger list above) - Map SQL dialect — rewrite hits using references/sql-dialect-map.md
- Verify driver + auth — confirm csproj packages +
usingmatch the server'spassword_encryption_typeper references/connectivity-and-auth.md - Validate end-to-end — run
scripts/gaussdb_connect_probe.csagainst the target GaussDB to confirm connection + BINARY COPY +nextvalall work; then build the real project
Workflow Decision Tree
| Task shape | Route |
|---|---|
| One-off SQL rewrite (single query / proc from T-SQL or vanilla PG) | Read sql-dialect-map.md, rewrite category-by-category |
App porting (.NET project with Microsoft.Data.SqlClient / Npgsql) |
Read connectivity-and-auth.md for driver choice, bulk-load-patterns.md for SqlBulkCopy replacement, then dialect-map for any embedded SQL |
| Reviewing new code meant for GaussDB | Scan with sql_dialect_audit.py; cross-reference common-pitfalls.md for subtle issues (copy-paste namespace leaks, wrong package versions, raw-string typos) |
Driver errors at runtime (Invalid username/password, AuthenticationRequest protocol error) |
Jump directly to connectivity-and-auth.md driver decision tree |
Core Rules
- Never use in a GaussDB target:
ON COMMIT DROP,CREATE TEMPORARY SEQUENCE,TOP N,OPTION (...),WITH (NOLOCK),dbo.schema prefix,IDENTITY(…)column type,@@IDENTITY,#tempTable,[bracketed]identifiers,NVARCHAR,ISNULL(,GETDATE(),DATEADD(,NEWID(),LEN(,SET XACT_ABORT,SET NOCOUNT,BEGIN TRY … END CATCH,EXEC proc @p=v,DECLARE @var,MERGE ... OUTPUT,INSERT ... OUTPUT - Always check
SHOW password_encryption_typeon the target server before choosing a driver:0or1→DotNetCore.GaussDB 9.0.0(MD5 path works, net9.0 OK)2(SHA256-only, GaussDB 505+ default) →HuaweiCloud.Driver.GaussDB 0.1.0(only one with working SHA256 SASL for this server family)
- Replace
SqlBulkCopy.WriteToServerAsync(tbl)withusing var w = conn.BeginBinaryImport($"""COPY "{t}" FROM STDIN BINARY"""); foreach row → w.StartRow(); w.Write(v, GaussDBDbType.X); await w.CompleteAsync(ct); - Reserve id blocks via
SELECT nextval('seq') - N + 1in a single roundtrip; neverIDENTITYcolumns in new tables - Temp tables:
CREATE TEMP TABLE x (...) ON COMMIT DELETE ROWS;— preceded byDROP TABLE IF EXISTS x;for reentrant batches - Temp sequences: don't create them. Use a permanent sequence with
DROP SEQUENCE IF EXISTS x; CREATE SEQUENCE x ...;bracket, and a finalDROP SEQUENCE IF EXISTS x;at script end
Default Deliverables
When invoked, produce:
- A hit list from the dialect audit (file:line → category → suggested replacement)
- Rewritten code for each hit, preserving business semantics
- A driver/auth verdict (is current csproj compatible with target server?) with upgrade steps if not
- An e2e verification command the user can run (usually the bundled probe script, parameterized with their DSN)
Sanitization Rules
- Never emit real connection strings, passwords, hostnames, or customer identifiers into checked-in files. Use placeholders:
<host>,<port>,<user>,<pwd>,<database> - When demonstrating a connection in a generated file, read DSN from environment (
GAUSSDB_DSN) rather than hard-coding - Treat private NuGet package names, internal namespaces, and business domain terms in examples as illustrative; genericize when documenting
Script Use
scripts/sql_dialect_audit.py <dir>— stdlib-only Python, walks a tree and reports every anti-pattern by file:line → category. Use to quickly inventory an unfamiliar codebase before planning a port.scripts/gaussdb_connect_probe.cs— single-file .NET 9 probe.GAUSSDB_DSN=... dotnet runto verify a driver + server combo. Exercises connect, encryption check, BINARY COPY,nextval, commit. Use to confirm the environment before touching business code.
Reference Use
Pull in only when the task demands:
- references/sql-dialect-map.md — the authoritative side-by-side rewrite table
- references/connectivity-and-auth.md — driver decision tree, server encryption modes, connection-string keys
- references/bulk-load-patterns.md — BINARY COPY template, id block allocation, reentrant temp tables
- references/common-pitfalls.md — real-world traps: raw-string CS8998, namespace copy-paste leaks, DI that compiles-but-fails-at-runtime, private package namespace moves