spanpg

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 5 Imported by: 0

README

spanpg

Go Reference

Experimental, optional layer for PostgreSQL dialect ergonomics around Cloud Spanner — built on top of:

The module API is unstable until declared otherwise.

API (experimental)

  • FormatPostgreSQLType — render a google.spanner.v1.Type using PostgreSQL-dialect spellings (including STRUCT<…> and json / jsonb by annotation).
  • StatementParamKey / PostgreSQLPlaceholder — pair $n placeholders with spanner.Statement.Params keys (p1, p2, …), matching the client convention (see integration/pgtypeannotation).
  • FormatColumnSimple — delegates to spanvalue.SimpleFormatConfig for readable column text.

Status

go.mod pins github.com/apstndb/spanvalue v0.2.1 and github.com/apstndb/spantype v0.3.11. The API remains unstable until declared otherwise.

Integration tests

The nested module integration/pgtypeannotation runs PostgreSQL-dialect Spanner client probes (emulator or real instance). It is not part of root go test ./...; use make test-integration (see Makefile and .github/workflows/go.yml).

Development

go test ./...
go vet ./...

License

MIT — see LICENSE.

Documentation

Overview

Package spanpg provides experimental PostgreSQL-dialect helpers around Cloud Spanner: FormatPostgreSQLType for type strings, placeholder/param-key pairing for PostgreSQL SQL text, and thin bridges to github.com/apstndb/spanvalue formatting.

Behavioral notes (query parameters use cloud.google.com/go/spanner.PGNumeric / cloud.google.com/go/spanner.PGJsonB; row metadata exposes TypeAnnotation on column types) are covered by the nested module `integration/pgtypeannotation` in this repository (see that directory’s README).

Stable cloud.google.com/go/spanner.GenericColumnValue construction remains in github.com/apstndb/spanvalue/gcvctor; [google.spanner.v1.Type] string rendering remains in github.com/apstndb/spantype. PostgreSQL-dialect spellings for cloud.google.com/go/spanner/apiv1/spannerpb.Type are available via FormatPostgreSQLType (see https://docs.cloud.google.com/spanner/docs/reference/postgresql/data-types and https://docs.cloud.google.com/spanner/docs/reference/dialect-differences).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatColumnSimple

func FormatColumnSimple(gcv spanner.GenericColumnValue) (string, error)

FormatColumnSimple formats a spanner.GenericColumnValue using github.com/apstndb/spanvalue.SimpleFormatConfig (human-readable scalar and container output).

func FormatPostgreSQLType

func FormatPostgreSQLType(typ *sppb.Type) string

FormatPostgreSQLType renders a sppb.Type using PostgreSQL-dialect spellings from https://docs.cloud.google.com/spanner/docs/reference/postgresql/data-types (supported types table: bool, bytea, date, float4, float8, bigint, interval, jsonb, numeric, timestamptz, text, uuid, oid, and array declarations). sppb.TypeCode_JSON is formatted as "jsonb" only when the type carries sppb.TypeAnnotationCode_PG_JSONB; otherwise it is formatted as "json" (non-PG JSON shapes are not defined in the PostgreSQL data-types table today, but the label keeps the distinction from PG_JSONB wire types).

sppb.TypeCode_PROTO and sppb.TypeCode_ENUM are not PostgreSQL-interface types: the PostgreSQL dialect does not support Protocol Buffers, so column values of these types are not returned in normal use. Dialect documentation may mention BYTEA or TEXT with CHECK constraints as migration substitutes for GoogleSQL; those are not the same as PROTO or ENUM on the wire. This function therefore formats them as "proto" and "enum"—not as "bytea" or "text"—so wire types are never mislabeled if they appear in metadata or in a future extension.

sppb.TypeCode_STRUCT does not appear in PostgreSQL-dialect metadata in practice today, but the implementation includes provisional formatting so callers are not left with a gap if STRUCT shows up on the wire later. The current output uses GoogleSQL STRUCT<…> declaration syntax (named fields: STRUCT<name type, …>; unnamed: STRUCT<type, …>), with field types spelled using the PostgreSQL data-type names above. When reviewing or updating this behavior, read Working with STRUCT objects from https://docs.cloud.google.com/spanner/docs/structs (e.g. dkcli get docs.cloud.google.com/spanner/docs/structs). The formatting for STRUCT may change once PostgreSQL-dialect support or official guidance for representing composite types is defined (this is not a stability guarantee for the STRUCT branch).

func PostgreSQLPlaceholder

func PostgreSQLPlaceholder(n int) (sql string, ok bool)

PostgreSQLPlaceholder returns the SQL text for the n-th bind placeholder in PostgreSQL dialect ($n, 1-based), e.g. 1 → "$1".

func StatementParamKey

func StatementParamKey(n int) (key string, ok bool)

StatementParamKey returns the map key used in cloud.google.com/go/spanner.Statement.Params for the PostgreSQL-style placeholder $n where n is 1-based. For example, placeholder $1 uses Params key "p1", $2 uses "p2".

This matches the cloud.google.com/go/spanner client convention used with PostgreSQL dialect SQL (placeholders $1, $2, …). See integration coverage in https://github.com/apstndb/spanvalue/pull/45.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL