Documentation
¶
Overview ¶
Package spanpg provides experimental PostgreSQL-dialect helpers around Cloud Spanner: catalog-style type spellings, 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 catalog spellings for cloud.google.com/go/spanner/apiv1/spannerpb.Type values 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 is formatted as GoogleSQL STRUCT<…> declaration syntax. 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) rather than ad-hoc page fetches. That page notes that the STRUCT data type is not supported in the PostgreSQL interface for Spanner, so the returned string is not a PostgreSQL-interface type name—it is the Spanner SQL form (named fields: STRUCT<name type, …>; unnamed: STRUCT<type, …>) with field types spelled using the PostgreSQL data-type names above, not Spanner keywords such as STRING.
func PostgreSQLCatalogTypeName ¶
PostgreSQLCatalogTypeName returns a conventional PostgreSQL type spelling for scalar sppb.Type values that carry well-known PostgreSQL dialect TypeAnnotation markers (for example NUMERIC with PG_NUMERIC → "numeric", JSON with PG_JSONB → "jsonb").
It returns ("", false) when the type does not map to a single catalog-style name: nil type, ARRAY or STRUCT, UNSPECIFIED annotation, or an unmapped code/annotation pair.
Display-oriented helpers like this are intentionally not part of github.com/apstndb/spanvalue; see also github.com/apstndb/spantype.FormatType for Spanner-style type strings. For PostgreSQL spellings of every sppb.TypeCode, including ARRAY and STRUCT, use FormatPostgreSQLType.
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.