From d496461bfe2751449eac72ea0b1590504d31a700 Mon Sep 17 00:00:00 2001 From: Chengxuan Xing Date: Fri, 2 Oct 2026 13:06:13 +0100 Subject: [PATCH 1/2] add default PostgreSQL provider features with the 65535 placeholder limit Signed-off-by: Chengxuan Xing --- pkg/dbsql/postgres_helpers.go | 13 +++++++++++++ pkg/dbsql/postgres_helpers_test.go | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/dbsql/postgres_helpers.go b/pkg/dbsql/postgres_helpers.go index 287eae3..85ede8c 100644 --- a/pkg/dbsql/postgres_helpers.go +++ b/pkg/dbsql/postgres_helpers.go @@ -26,6 +26,19 @@ import ( "github.com/hyperledger-firefly/common/pkg/i18n" ) +// PostgreSQLMaxPlaceholders is the limit on bind parameters in one statement, set by the PostgreSQL wire protocol +const PostgreSQLMaxPlaceholders = 65535 + +// DefaultPostgreSQLProviderFeatures are the features shared by PostgreSQL providers, which can add their own on top +func DefaultPostgreSQLProviderFeatures() SQLFeatures { + features := DefaultSQLProviderFeatures() + features.PlaceholderFormat = sq.Dollar + features.MultiRowInsert = true + features.MaxPlaceholders = PostgreSQLMaxPlaceholders + features.DBOptimizedUpsertBuilder = BuildPostgreSQLOptimizedUpsert + return features +} + // BuildPostgreSQLOptimizedUpsert is a PostgreSQL helper to avoid implementing this lots of times in child packages func BuildPostgreSQLOptimizedUpsert(ctx context.Context, table string, idColumn string, insertCols, updateCols []string, returnCol string, values map[string]driver.Value) (insert sq.InsertBuilder, err error) { insertValues := make([]interface{}, 0, len(insertCols)) diff --git a/pkg/dbsql/postgres_helpers_test.go b/pkg/dbsql/postgres_helpers_test.go index 9ad857c..362bdd0 100644 --- a/pkg/dbsql/postgres_helpers_test.go +++ b/pkg/dbsql/postgres_helpers_test.go @@ -21,6 +21,7 @@ import ( "database/sql/driver" "testing" + sq "github.com/Masterminds/squirrel" "github.com/hyperledger-firefly/common/pkg/fftypes" "github.com/stretchr/testify/assert" ) @@ -60,3 +61,13 @@ func TestBuildPostgreSQLOptimizedUpsertFail(t *testing.T) { assert.Regexp(t, "FF00247", err) } + +func TestDefaultPostgreSQLProviderFeatures(t *testing.T) { + + features := DefaultPostgreSQLProviderFeatures() + assert.Equal(t, sq.Dollar, features.PlaceholderFormat) + assert.True(t, features.MultiRowInsert) + assert.Equal(t, 65535, features.MaxPlaceholders) + assert.NotNil(t, features.DBOptimizedUpsertBuilder) + +} From 7c73deb8e70b98d806ef06c788800c85ed9e413f Mon Sep 17 00:00:00 2001 From: Chengxuan Xing Date: Mon, 26 Oct 2026 11:10:36 +0000 Subject: [PATCH 2/2] update comment Signed-off-by: Chengxuan Xing --- pkg/dbsql/postgres_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/dbsql/postgres_helpers.go b/pkg/dbsql/postgres_helpers.go index 85ede8c..56ac904 100644 --- a/pkg/dbsql/postgres_helpers.go +++ b/pkg/dbsql/postgres_helpers.go @@ -29,7 +29,7 @@ import ( // PostgreSQLMaxPlaceholders is the limit on bind parameters in one statement, set by the PostgreSQL wire protocol const PostgreSQLMaxPlaceholders = 65535 -// DefaultPostgreSQLProviderFeatures are the features shared by PostgreSQL providers, which can add their own on top +// DefaultPostgreSQLProviderFeatures are the features suggested for all PostgreSQL providers, clients can add their own on top func DefaultPostgreSQLProviderFeatures() SQLFeatures { features := DefaultSQLProviderFeatures() features.PlaceholderFormat = sq.Dollar