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 ¶
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 ¶
PostgreSQLPlaceholder returns the SQL text for the n-th bind placeholder in PostgreSQL dialect ($n, 1-based), e.g. 1 → "$1".
func StatementParamKey ¶
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.