pgtext

package
v1.154.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pgtext reads and writes the text forms PostgreSQL gives the values of its structured types (#2455): a range, a multirange, a composite row, an hstore and pgvector's vector. The application-database kind returns each as JSON a script reads, and accepts the same JSON as a bound parameter, which it writes back in these forms for the server to parse by the parameter's own type.

It knows only the syntax. What a range's bounds or a row's fields mean is their element types', which the caller maps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatComposite

func FormatComposite(fields []*string) string

FormatComposite writes fields in the form ParseComposite reads, a nil field as null.

func FormatHstore

func FormatHstore(keys []string, pairs map[string]*string) string

FormatHstore writes pairs in the form ParseHstore reads, a nil value as NULL. keys gives the order.

func FormatMultirange

func FormatMultirange(ranges []Range) string

FormatMultirange writes ranges in the form ParseMultirange reads.

func FormatRange

func FormatRange(r Range) string

FormatRange writes r in the form ParseRange reads.

func ParseComposite

func ParseComposite(s string) ([]*string, error)

ParseComposite reads a row: parentheses around fields separated by commas, an empty field being null.

func ParseHstore

func ParseHstore(s string) (map[string]*string, error)

ParseHstore reads an hstore: "key"=>"value" pairs separated by commas, a value written NULL being null.

func ParseVector

func ParseVector(s string) ([]float64, error)

ParseVector reads a pgvector vector: brackets around numbers separated by commas.

func Quote

func Quote(s string) string

Quote writes s as a double-quoted item, every quote and backslash in it escaped, which every one of these forms reads as s.

Types

type Range

type Range struct {
	Empty    bool
	Lower    *string
	Upper    *string
	LowerInc bool
	UpperInc bool
}

Range is one range value. A nil bound is unbounded (infinite); Empty is the range with no points, whose bounds are not meaningful.

func ParseMultirange

func ParseMultirange(s string) ([]Range, error)

ParseMultirange reads a multirange: braces around ranges separated by commas.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange reads a range as PostgreSQL writes it: empty, or a bracket or parenthesis, the lower bound, a comma, the upper bound and a closing bracket or parenthesis, a missing bound being unbounded.

Jump to

Keyboard shortcuts

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