Documentation
¶
Overview ¶
Package dbmeta provides database metadata for many databases.
Metadata means the description of what a database contains: its catalogs, schemas, tables, columns, indexes, constraints, functions, sequences and the privileges on them. dbmeta reads that description. It does not change it and it does not render it.
One API answers for every database. The caller asks for tables without knowing which database answers, and receives the same types whichever one does.
PostgreSQL is the model. The shape of every answer follows the metadata commands of psql, the PostgreSQL command line client, because bringing that experience to other databases is the purpose of this package. A database answers for the objects it has, and reports the ones it does not.
Queries vary by version ¶
A database changes its metadata between releases, so a query does too. Each query is a set of SQL fragments, and each fragment carries the lowest server version it applies to. dbmeta reads the version once per connection and merges the fragments that apply.
A fragment never changes the set of columns a query returns. When a column has no source on an older server, the fragment selects it as a literal NULL under the same name, so one result shape fits every version.
The caller drives ¶
dbmeta does not open a connection, does not import a database driver, and does not detect anything. The caller opens the connection, names the dialect, and supplies the version. Any type that satisfies Queryer works, which includes database/sql.DB and database/sql.Tx. Pass a transaction to read more than one catalog in one snapshot.
Every function that reads from a database takes a context.Context first.
A caller reads the version by asking for the query and running it:
query, _, ok := dbmeta.PostgreSQL.VersionQuery() // caller runs query and scans the columns as strings versions, err := dbmeta.PostgreSQL.ParseVersion(cols) m, err := dbmeta.New(dbmeta.PostgreSQL, versions)
One dialect can need a second statement. Dialect.FollowUpQuery says whether it does for the server the first one found, and Dialect.ParseFollowUp reads its columns. Dialect.Version runs both. A caller that runs the statements itself asks for the follow-up after every first statement, because the answer depends on the server and not on the dialect alone. See D92.
The version can be anything the caller chooses. Overriding it matters for a proxy that hides the server, for a product that reports a version it does not behave like, and for a generator with no server at all.
Asking for an object ¶
There is one Query value per kind of object. Name the value, and the result type follows from it:
for t, err := range dbmeta.Tables.All(ctx, m, db, dbmeta.Args{Schema: "public"}.Map()) {
...
}
An iterator holds a database connection until it ends. Stopping early releases it, and so does canceling the context. Do not open a second iterator inside the body of the first, because that needs a second connection and deadlocks on a pool of one.
A caller that runs the statement itself asks for it instead:
query, args, err := dbmeta.Tables.Build(m, map[string]any{"schema": "public"})
Query.Fields and Query.Params describe what a query returns and takes. Query.Support says whether it can be asked at all, and tells a database that has no such object apart from a model that was left out of the build.
Layout ¶
Each model is a package under models, one for each database, and it registers what its dialect provides. The all package imports every model that the build tags select. Callers use this package.
Example ¶
Example shows what a client such as usql or dbtpl does: read the server version, list the tables in a schema, then read the columns of one table.
package main
import (
"context"
"database/sql"
"fmt"
"log"
"github.com/xo/dbmeta"
_ "github.com/xo/dbmeta/all"
)
func main() {
ctx := context.Background()
// The client opens the connection. dbmeta never does, and never imports a
// driver. A real client uses dburl.Open here.
db, err := sql.Open("examplefake", "postgres://localhost/example")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// The client picks the dialect. dbmeta does not detect it. A real client
// takes it from the parsed URL, as dburl.URL.Driver.
dialect := dbmeta.PostgreSQL
// Read the version. dbmeta supplies the statement, runs it against the
// connection the client passed, and parses the answer. A client that
// wants the statement without running it asks for it instead, and a
// client that wants to force a version skips this entirely.
versions, err := dialect.Version(ctx, db)
if err != nil {
log.Fatal(err)
}
fmt.Println(versions)
// The dialect and the version together decide which fragment of each
// query applies. A client that wants to force a version passes its own
// here instead.
m, err := dbmeta.New(dialect, versions)
if err != nil {
log.Fatal(err)
}
// List the tables.
fmt.Println("\ntables:")
for t, err := range dbmeta.Tables.All(ctx, m, db, dbmeta.Args{Schema: "public"}.Map()) {
if err != nil {
log.Fatal(err)
}
line := fmt.Sprintf(" %s.%s (%s)", t.Schema, t.Name, t.Type)
// Comment is a sql.Null[string], so a table with no comment is absent rather than
// empty. Reading .V prints empty for both, which is what a CLI wants.
if t.Comment.Valid {
line += " " + t.Comment.V
}
fmt.Println(line)
}
// Read the columns of one table.
fmt.Println("\ncolumns of public.book:")
args := dbmeta.Args{Schema: "public", Parent: "book"}.Map()
for c, err := range dbmeta.Columns.All(ctx, m, db, args) {
if err != nil {
log.Fatal(err)
}
null := "not null"
if c.Nullable {
null = "null"
}
fmt.Printf(" %d %-10s %-8s %s\n", c.Ordinal, c.Name, c.DataType, null)
}
}
Output: PostgreSQL 16.2 tables: public.author (table) people who write public.book (table) public.recent_book (view) columns of public.book: 1 book_id integer not null 2 title text not null 3 published date null 4 slug text null
Example (OldServer) ¶
Example_oldServer shows the same query against a server too old for one of its columns. The column set does not change: the comment is padded with a literal instead, and the declared field says why.
package main
import (
"fmt"
"log"
"strings"
"github.com/xo/dbmeta"
_ "github.com/xo/dbmeta/all"
)
func main() {
sqlOf := func(ver string) string {
m, err := dbmeta.New(dbmeta.PostgreSQL, versionSet(ver))
if err != nil {
log.Fatal(err)
}
query, _, err := dbmeta.Columns.Build(m, dbmeta.Args{Schema: "public"}.Map())
if err != nil {
log.Fatal(err)
}
return query
}
// attidentity arrived in release 10 and attgenerated in release 12, so an
// older server selects a literal under the same name. The column set never
// changes, which is what lets one scan function read every release.
fmt.Println("9.6 pads identity: ", strings.Contains(sqlOf("9.6.24"), `, NULL AS "identity"`))
fmt.Println("11 reads identity:", strings.Contains(sqlOf("11.22"), `a.attidentity`))
fmt.Println("11 pads generated:", strings.Contains(sqlOf("11.22"), `, NULL AS "generated"`))
fmt.Println("12 reads generated:", strings.Contains(sqlOf("12.18"), `a.attgenerated`))
// a caller tells "absent at this version" from "genuinely null" by the
// minimum the field declares
m, err := dbmeta.New(dbmeta.PostgreSQL, versionSet("9.6.24"))
if err != nil {
log.Fatal(err)
}
fields, err := dbmeta.Columns.Fields(m)
if err != nil {
log.Fatal(err)
}
for _, f := range fields {
if f.Name == "identity" {
fmt.Println("identity present at 9.6:", m.Version().Main().AtLeast(f.Min))
}
}
}
func versionSet(s string) dbmeta.VersionSet {
var v dbmeta.VersionSet
v.Set("", dbmeta.ParseVersion(s))
v.Display = "PostgreSQL " + s
return v
}
Output: 9.6 pads identity: true 11 reads identity: true 11 pads generated: true 12 reads generated: true identity present at 9.6: false
Example (Sql) ¶
Example_sql shows a client taking the statement and running it itself, which is what usql does for a command that prints raw output.
package main
import (
"fmt"
"log"
"github.com/xo/dbmeta"
_ "github.com/xo/dbmeta/all"
)
func main() {
m, err := dbmeta.New(dbmeta.PostgreSQL, versionSet("16.2"))
if err != nil {
log.Fatal(err)
}
query, args, err := dbmeta.Schemas.Build(m, dbmeta.Args{Name: "public"}.Map())
if err != nil {
log.Fatal(err)
}
fmt.Println(query)
fmt.Println("args:", args)
}
func versionSet(s string) dbmeta.VersionSet {
var v dbmeta.VersionSet
v.Set("", dbmeta.ParseVersion(s))
v.Display = "PostgreSQL " + s
return v
}
Output: SELECT current_database() AS "catalog" , n.nspname AS "name" , pg_catalog.pg_get_userbyid(n.nspowner) AS "owner" , pg_catalog.obj_description(n.oid, 'pg_namespace') AS "comment" , pg_catalog.array_to_string(n.nspacl, E'\n') AS "access" FROM pg_catalog.pg_namespace n WHERE ($1 OR (n.nspname !~ '^pg_' AND n.nspname <> 'information_schema')) AND ($2 = '' OR n.nspname LIKE $3) ORDER BY 2 args: [false public public]
Example (Support) ¶
Example_support shows the four states a client must tell apart before it offers a command to a person.
package main
import (
"fmt"
"log"
"github.com/xo/dbmeta"
_ "github.com/xo/dbmeta/all"
)
func main() {
m, err := dbmeta.New(dbmeta.PostgreSQL, versionSet("16.2"))
if err != nil {
log.Fatal(err)
}
fmt.Println("tables: ", dbmeta.Tables.Support(m))
fmt.Println("indexes:", dbmeta.Indexes.Support(m))
// an object this release does not have is a different answer: the product
// has it and the server is too old, which an upgrade fixes. Support says
// so on its own, and Build then returns ErrVersionTooOld. See D63.
old := versionMeta("9.6.24")
fmt.Println("publications on 9.6:", dbmeta.Publications.Support(old))
if _, _, err := dbmeta.Publications.Build(old, nil); err != nil {
fmt.Println("and building it:", err)
}
// a dialect no model was built for is a different answer entirely.
// DynamoDB is one dbmeta has a dialect for and no model, because it has
// no catalog to read. This example moves on when a model arrives, the way
// it moved off Trino, Vertica, YDB, Neo4j and H2.
if _, err := dbmeta.New("dynamodb", dbmeta.VersionSet{}); err != nil {
fmt.Println("dynamodb:", err)
}
}
func versionMeta(ver string) *dbmeta.Meta {
m, err := dbmeta.New(dbmeta.PostgreSQL, versionSet(ver))
if err != nil {
log.Fatal(err)
}
return m
}
func versionSet(s string) dbmeta.VersionSet {
var v dbmeta.VersionSet
v.Set("", dbmeta.ParseVersion(s))
v.Display = "PostgreSQL " + s
return v
}
Output: tables: supported indexes: supported publications on 9.6: version too old and building it: version too old dynamodb: model not built
Example (VersionByHand) ¶
Example_versionByHand shows the two step form, for a client that wants the statement without running it. usql prints the statement in its trace output, so it needs this rather than dbmeta.Dialect.Version.
package main
import (
"fmt"
"log"
"github.com/xo/dbmeta"
_ "github.com/xo/dbmeta/all"
)
func main() {
query, n, ok := dbmeta.PostgreSQL.VersionQuery()
if !ok {
log.Fatal("expected a version query")
}
fmt.Printf("%s (%d column)\n", query, n)
// the client runs it however it likes, then hands the columns back
versions, err := dbmeta.PostgreSQL.ParseVersion([]string{"16.2"})
if err != nil {
log.Fatal(err)
}
fmt.Println(versions)
}
Output: SHOW server_version (1 column) PostgreSQL 16.2
Index ¶
- Variables
- func AlignName(names ...string) func(string) (Align, bool)
- func BinaryNames(names ...string) func(*sql.ColumnType) bool
- func First[T any](seq iter.Seq2[T, error]) (T, bool, error)
- func InList(list, item string) string
- func Like(pattern, s string) bool
- func LikeFold(pattern, s string) bool
- func ListHas(list, word string) bool
- func MySQLVersionNum(s VersionSet) (int, bool)
- func NullAsEmpty(p *string) sql.Scanner
- func PostgresVersionNum(s VersionSet) (int, bool)
- func QuoteIdentifier(name, open, closed string) string
- func QuoteLiteral(s string, q Quoting) string
- func RegisterDialect(d Dialect, info *Info)
- func RightAligned(names ...string) func(*sql.ColumnType) (Align, bool)
- func TimeKinds(kinds map[TimeKind][]string) func(*sql.ColumnType) TimeKind
- type AccessMethod
- type Align
- type AnyQuery
- type Args
- type Batch
- type Binding
- type Cast
- type Choice
- type Collation
- type Column
- type ColumnPrivilege
- type ColumnStat
- type Comment
- type Constraint
- type ConstraintColumn
- type Conversion
- type Database
- type DatabaseName
- type DefaultACL
- type Derived
- type Dialect
- func (d Dialect) ChangePassword(c PasswordChange, q Quoting) (string, error)
- func (d Dialect) Classify(stmt string) (tag string, rows bool)
- func (d Dialect) ColumnAlign(ct *sql.ColumnType) (Align, bool)
- func (d Dialect) CopyFromStdin(stmt string) (bool, error)
- func (d Dialect) DescribeResult(query string) (ResultDescription, error)
- func (d Dialect) Embedded() bool
- func (d Dialect) EveryStatementIsAQuery() bool
- func (d Dialect) FoldIdentifier(name string) string
- func (d Dialect) FollowUpQuery(s VersionSet) (query string, cols int, ok bool)
- func (d Dialect) FormatBinary(ct *sql.ColumnType, b []byte) (string, bool)
- func (d Dialect) Info() (*Info, bool)
- func (d Dialect) ParseFollowUp(s VersionSet, cols []string) (VersionSet, error)
- func (d Dialect) ParseQuoting(cols []string) (Quoting, error)
- func (d Dialect) ParseSuperuser(col string) (bool, error)
- func (d Dialect) ParseVersion(cols []string) (VersionSet, error)
- func (d Dialect) Pattern(p string) (schema, name string)
- func (d Dialect) Placeholder(n int) (string, bool)
- func (d Dialect) Product() (string, bool)
- func (d Dialect) Quoting(ctx context.Context, db Queryer) (Quoting, error)
- func (d Dialect) QuotingQuery() (query string, cols int, ok bool)
- func (d Dialect) ScanTypes() bool
- func (d Dialect) SplitIdentifier(name string) ([]string, error)
- func (d Dialect) SuperuserQuery() (query string, ok bool)
- func (d Dialect) Syntax() (Syntax, bool)
- func (d Dialect) TimeKind(ct *sql.ColumnType) TimeKind
- func (d Dialect) TypeNames(types []TypeRef) (string, error)
- func (d Dialect) Version(ctx context.Context, db Queryer) (VersionSet, error)
- func (d Dialect) VersionNum(s VersionSet) (int, bool)
- func (d Dialect) VersionQuery() (query string, cols int, ok bool)
- func (d Dialect) WritesNeedAutocommit() bool
- type Domain
- type EnumValue
- type Error
- type Event
- type EventTrigger
- type ExtendedStat
- type Extension
- type ExtensionObject
- type Field
- type Fold
- type ForeignDataWrapper
- type ForeignOption
- type ForeignServer
- type ForeignTable
- type Fragment
- type Function
- type Gate
- type Grant
- type Index
- type IndexColumn
- type Info
- type Inherit
- type Language
- type LargeObject
- type MaterializedView
- type MaterializedViewLog
- type Meta
- type NotNull
- type Operator
- type OperatorClass
- type OperatorFamily
- type OperatorFamilyFunction
- type OperatorFamilyOperator
- type Param
- type Partition
- type PartitionFunction
- type PartitionScheme
- type PartitionedTable
- type PasswordChange
- type Policy
- type Privilege
- type Publication
- type PublicationTable
- type Query
- func (q *Query[T]) All(ctx context.Context, m *Meta, db Queryer, args map[string]any) iter.Seq2[T, error]
- func (q *Query[T]) Build(m *Meta, args map[string]any) (string, []any, error)
- func (q *Query[T]) Each(ctx context.Context, m *Meta, db Queryer, args Args) iter.Seq2[T, error]
- func (q *Query[T]) Fields(m *Meta) ([]Field, error)
- func (q *Query[T]) Name() string
- func (q *Query[T]) Params(m *Meta) ([]Param, error)
- func (q *Query[T]) Register(d Dialect, b *Binding[T])
- func (q *Query[T]) Share(from, to Dialect) bool
- func (q *Query[T]) Support(m *Meta) Support
- type Queryer
- type Quoting
- type ResultDescription
- type Returning
- type Role
- type RoleGrant
- type RoleSetting
- type RoutineParameter
- type Rule
- type Schema
- type Sequence
- type Setting
- type SourceLine
- type Statements
- type Stmt
- type Subpartition
- type SubpartitionTemplate
- type Subscription
- type SubscriptionConnection
- type Support
- type Synonym
- type Syntax
- type Table
- type Tablespace
- type Terminator
- type TextSearchConfig
- type TextSearchConfigMap
- type TextSearchDictionary
- type TextSearchParser
- type TextSearchParserFunction
- type TextSearchParserTokenType
- type TextSearchTemplate
- type TimeKind
- type Trigger
- type Type
- type TypeAttribute
- type TypeRef
- type User
- type UserMapping
- type Variant
- type Version
- type VersionSet
- type View
- type ViewDependency
- type XMLSchemaCollection
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Tables lists tables and the relations that behave like them. Tables = NewQuery[Table]("tables") // Schemas lists namespaces. Schemas = NewQuery[Schema]("schemas") // Columns lists the columns of a table. Columns = NewQuery[Column]("columns") // Indexes lists the indexes of a table. Indexes = NewQuery[Index]("indexes") )
Queries. One value per object kind.
var ( // Databases lists the databases of a server. Databases = NewQuery[Database]("databases") // Tablespaces lists the places a server stores data. Tablespaces = NewQuery[Tablespace]("tablespaces") // AccessMethods lists the index and table access methods. AccessMethods = NewQuery[AccessMethod]("access_methods") // Languages lists the procedural languages. Languages = NewQuery[Language]("languages") // Conversions lists the encoding conversions. Conversions = NewQuery[Conversion]("conversions") // Casts lists the conversions between types. Casts = NewQuery[Cast]("casts") // Collations lists the sorting rules. Collations = NewQuery[Collation]("collations") // LargeObjects lists the large objects. LargeObjects = NewQuery[LargeObject]("large_objects") // EventTriggers lists the triggers that fire on a DDL event. EventTriggers = NewQuery[EventTrigger]("event_triggers") // Settings lists the configuration parameters. Settings = NewQuery[Setting]("settings") )
Queries for the objects above.
var ( // Functions lists functions, procedures, aggregates and window functions. Functions = NewQuery[Function]("functions") // Aggregates lists aggregate functions alone. Aggregates = NewQuery[Function]("aggregates") // Types lists data types. Types = NewQuery[Type]("types") // Domains lists types that carry a constraint. Domains = NewQuery[Domain]("domains") // Operators lists operators. Operators = NewQuery[Operator]("operators") )
Queries for routines and types.
var ( // Roles lists the database roles. Roles = NewQuery[Role]("roles") // RoleSettings lists the configuration set for a role. RoleSettings = NewQuery[RoleSetting]("role_settings") // RoleGrants lists role memberships. RoleGrants = NewQuery[RoleGrant]("role_grants") // Privileges lists the grants on tables and their columns. Privileges = NewQuery[Privilege]("privileges") // DefaultACLs lists the grants applied to objects created later. DefaultACLs = NewQuery[DefaultACL]("default_acls") // ForeignDataWrappers lists the wrappers that reach outside data. ForeignDataWrappers = NewQuery[ForeignDataWrapper]("foreign_data_wrappers") // ForeignServers lists the servers reached through a wrapper. ForeignServers = NewQuery[ForeignServer]("foreign_servers") // UserMappings lists the local roles mapped onto a foreign server. UserMappings = NewQuery[UserMapping]("user_mappings") // ForeignTables lists the tables on a foreign server. ForeignTables = NewQuery[ForeignTable]("foreign_tables") // ForeignOptions lists the options of the foreign data wrappers, the // foreign servers, the user mappings and the foreign tables, one row for // each option. See D201. ForeignOptions = NewQuery[ForeignOption]("foreign_options") // ColumnPrivileges lists the access privileges of the columns, one row for // each entry. See D201. ColumnPrivileges = NewQuery[ColumnPrivilege]("column_privileges") )
Queries for roles, privileges and foreign data.
var ( // Publications lists the sets of changes offered for replication. Publications = NewQuery[Publication]("publications") // PublicationTables lists the tables each publication offers. PublicationTables = NewQuery[PublicationTable]("publication_tables") // Subscriptions lists the subscriptions to a publication. Subscriptions = NewQuery[Subscription]("subscriptions") // SubscriptionConnections lists the connection string of each // subscription. Only a superuser can read it. See D201. SubscriptionConnections = NewQuery[SubscriptionConnection]("subscription_connections") // TextSearchParsers lists the parsers that split text into tokens. TextSearchParsers = NewQuery[TextSearchParser]("text_search_parsers") // TextSearchParserFunctions lists the five functions of each text search // parser. See D201. TextSearchParserFunctions = NewQuery[TextSearchParserFunction]("text_search_parser_functions") // TextSearchParserTokenTypes lists the kinds of token that each text search // parser returns. See D262. TextSearchParserTokenTypes = NewQuery[TextSearchParserTokenType]("text_search_parser_token_types") // TextSearchDictionaries lists the dictionaries that normalize tokens. TextSearchDictionaries = NewQuery[TextSearchDictionary]("text_search_dictionaries") // TextSearchTemplates lists the code behind the dictionaries. TextSearchTemplates = NewQuery[TextSearchTemplate]("text_search_templates") // TextSearchConfigs lists the configurations. TextSearchConfigs = NewQuery[TextSearchConfig]("text_search_configs") // TextSearchConfigMaps lists the dictionaries each configuration consults // for each kind of token. TextSearchConfigMaps = NewQuery[TextSearchConfigMap]("text_search_config_maps") // OperatorClasses lists the operator classes. OperatorClasses = NewQuery[OperatorClass]("operator_classes") // OperatorFamilies lists the operator families. OperatorFamilies = NewQuery[OperatorFamily]("operator_families") // OperatorFamilyOperators lists the operators of each family. OperatorFamilyOperators = NewQuery[OperatorFamilyOperator]("operator_family_operators") // OperatorFamilyFunctions lists the support functions of each family. OperatorFamilyFunctions = NewQuery[OperatorFamilyFunction]("operator_family_functions") // Extensions lists the installed extensions. Extensions = NewQuery[Extension]("extensions") // ExtensionObjects lists the objects each extension owns. ExtensionObjects = NewQuery[ExtensionObject]("extension_objects") // ExtendedStats lists the statistics objects over several columns. ExtendedStats = NewQuery[ExtendedStat]("extended_stats") // Comments lists the comments on objects. Comments = NewQuery[Comment]("comments") )
Queries for replication, text search, operator families and extensions.
var ( // IndexColumns lists the columns of each index, in index order. IndexColumns = NewQuery[IndexColumn]("index_columns") // Constraints lists the constraints on a table. Constraints = NewQuery[Constraint]("constraints") // Triggers lists the triggers on a table. Triggers = NewQuery[Trigger]("triggers") // Sequences lists sequences and their bounds. Sequences = NewQuery[Sequence]("sequences") // PartitionedTables lists the tables split into partitions. PartitionedTables = NewQuery[PartitionedTable]("partitioned_tables") // Partitions lists the partitions of each partitioned table. Partitions = NewQuery[Partition]("partitions") // Inherits lists the inheritance of one table from another. Inherits = NewQuery[Inherit]("inherits") // Policies lists the row level security policies of a table. Policies = NewQuery[Policy]("policies") // Rules lists the rewrite rules of a table. Rules = NewQuery[Rule]("rules") // NotNulls lists the NOT NULL constraints of a table, as PostgreSQL // 18 records them. NotNulls = NewQuery[NotNull]("not_nulls") )
Queries for the detail of a table.
var ( // ConstraintColumns lists the columns of each constraint, in order. ConstraintColumns = NewQuery[ConstraintColumn]("constraint_columns") // RoutineParameters lists the parameters of each function and procedure. RoutineParameters = NewQuery[RoutineParameter]("routine_parameters") // EnumValues lists the labels of each enumerated type, in sort order. EnumValues = NewQuery[EnumValue]("enum_values") // Views lists views and the statements that define them. Views = NewQuery[View]("views") // ViewDependencies lists, for each view, the relations that its query reads, // which a dump needs to write one view after the views it reads. See D278. ViewDependencies = NewQuery[ViewDependency]("view_dependencies") // Source lists the lines of the source text of a stored program, a package, a // type or a trigger, which a product keeps one line to a row. A dump joins the // lines to write the object again. See D289. Source = NewQuery[SourceLine]("source") // Synonyms lists the synonyms, which are other names for an object, where the // product has them. A dump writes them back. See D289. Synonyms = NewQuery[Synonym]("synonyms") // MaterializedViews lists the materialized views of a product that keeps them // apart from its views, with the clauses that build and refresh them. A dump // needs the query and the clauses. See D289. MaterializedViews = NewQuery[MaterializedView]("materialized_views") // Events lists the scheduled events of a product that has them, with the schedule // and the statement that runs. A dump writes them back. See D296. Events = NewQuery[Event]("events") // MaterializedViewLogs lists the logs that record the changes to a table, for a // product that has them, such as the materialized view log of Oracle. A dump // writes them back, and leaves out the table that holds each one. See D296. MaterializedViewLogs = NewQuery[MaterializedViewLog]("materialized_view_logs") // XMLSchemaCollections lists the XML schema collections of a product that has // them, with the text of each. A dump writes them back. See D296. XMLSchemaCollections = NewQuery[XMLSchemaCollection]("xml_schema_collections") // SubpartitionTemplates lists the subpartitions that a partitioned table gives each of // its partitions, for a product that has such a template. See D297. SubpartitionTemplates = NewQuery[SubpartitionTemplate]("subpartition_templates") // Subpartitions lists the subpartitions of the partitions of a table, one for each row, // for a product that splits a partition again. See D299. Subpartitions = NewQuery[Subpartition]("subpartitions") // Grants lists the privileges that were given on objects and on columns, one for each // row, for a product that records them. Privileges is the gathered list that psql // prints, and a dump needs each privilege on its own. See D298. Grants = NewQuery[Grant]("grants") // PartitionFunctions lists the functions that decide which partition a row is in, // for a product that keeps them apart from its tables. See D296. PartitionFunctions = NewQuery[PartitionFunction]("partition_functions") // PartitionSchemes lists the schemes that put the partitions of a function on // storage, for a product that keeps them apart from its tables. See D296. PartitionSchemes = NewQuery[PartitionScheme]("partition_schemes") // TypeAttributes lists the attributes of each object type, in order, which a // dump needs to read and write a column of such a type. See D289. TypeAttributes = NewQuery[TypeAttribute]("type_attributes") // ColumnStats lists what the planner knows about a column's values. ColumnStats = NewQuery[ColumnStat]("column_stats") // CurrentSchema returns the schema an unqualified name resolves in. // // It is session dependent. It answers one row and, with [CurrentUser], it // describes the connection rather than the database. A caller reads it // with [First]. CurrentSchema = NewQuery[Schema]("current_schema") // CurrentUser returns who the connection is authenticated as. // // Like [CurrentSchema] it is session dependent, answers one row and // describes the connection rather than the database. A caller reads it // with [First]. // // It is here because it is database specific SQL that a client otherwise // carries itself: usql writes SELECT current_user for most products and // SELECT user FROM dual for Oracle. See D55. CurrentUser = NewQuery[User]("current_user") // CurrentDatabase returns the name of the database that the connection is // using, which is psql's %/ and what \conninfo calls the database. // // It is session dependent and answers one row. The name is absent when the // connection has chosen no database, as MySQL's DATABASE() is. A product // with no such notion has no model for it, and a caller falls back to // what it was given. [CurrentSchema] reports the catalog of a schema, which // is not always the database. See D265. CurrentDatabase = NewQuery[DatabaseName]("current_database") )
Queries for the kinds psql has no command for.
Functions ¶
func AlignName ¶ added in v0.18.0
AlignName is RightAligned for a type name that a model has already taken from the column, because the driver wraps it, as YDB does in Optional<Int32>. A name matches in any case and without its size, so DECIMAL(10,2) matches DECIMAL, and an empty name says nothing.
func BinaryNames ¶ added in v0.27.0
func BinaryNames(names ...string) func(*sql.ColumnType) bool
BinaryNames returns a function for Info.IsBinary that says a column is binary when it has one of the named types. The names are the strings that sql.ColumnType.DatabaseTypeName returns through the drivers of the product, and a name matches in any case and without its size. A column with any other type, and a column with no name, is not binary. See D258.
func First ¶
First returns the first value the sequence yields.
The second result reports whether there was one, so a caller can tell an empty result from a zero value. An empty result is not an error: it means the database has no such object.
func InList ¶
InList is the SQL condition that item is one of the items of list, where list is a string of items joined by commas, which is how a list parameter such as types is bound. It joins strings with ||, which most products accept. A model whose product joins strings another way writes the same condition itself. It does not handle an empty list, which means every item, because a product spells the empty string differently: Oracle and Exasol read it as NULL. See D138.
func Like ¶
Like reports whether s matches pattern the way SQL's LIKE does: % is any run of characters, _ is one, and a backslash makes the next character its own. An empty pattern matches everything, which is what every parameter here means by empty. It is for a query that Binding.Walk answers, whose statements cannot take the pattern, so the rows are matched here. See D146.
func LikeFold ¶ added in v0.10.0
LikeFold is Like with the case of letters ignored, for a product whose unquoted names are case insensitive, as CQL's are. A caller passes the pattern the way a person typed it, and the model folds both sides. See D202.
func ListHas ¶ added in v0.10.0
ListHas reports whether list, which is words joined by commas, is empty or names word. It reads a parameter such as types, which holds a list, for a model that filters in Go. An empty list means every word, as every parameter here means by empty. InList is the same test as SQL.
func MySQLVersionNum ¶ added in v0.52.0
func MySQLVersionNum(s VersionSet) (int, bool)
MySQLVersionNum is Info.VersionNum for the MySQL family. It builds the integer that the client library of MySQL gives for the server version, which is the major release times 10000, plus the minor release times 100, plus the patch, so 8.0.36 is 80036. It returns false for an unknown version. See D309.
func NullAsEmpty ¶
NullAsEmpty returns a scanner that reads a text column into a plain string, and reads NULL as the empty string.
It is for a product that cannot store the empty string. Oracle and Exasol both read one as NULL, so a statement that selects the empty string for a field that is empty, or wraps a column in NVL with the empty string, gets NULL back, and a NULL cannot be scanned into a string. A model for such a product scans each plain string field that can be empty through this. D87 found it on Exasol, and D127 put the one copy here, because two models need it.
This is not the COALESCE docs/NULLS.md forbids. That rule protects a NULL that means something different from the empty string. A field whose type is sql.Null keeps its NULL, and is never scanned through this. A plain string field is one the object model says is never absent, and on these products NULL is the only way to write it empty.
func PostgresVersionNum ¶ added in v0.52.0
func PostgresVersionNum(s VersionSet) (int, bool)
PostgresVersionNum is Info.VersionNum for a product that reports the release of PostgreSQL that it is or claims to be, with the main version. It builds the integer that PostgreSQL gives as server_version_num. Release 10 and later give the major release times 10000 plus the minor release, so 18.6 is 180006. Earlier releases give three numbers of two digits, so 9.6.24 is 90624. It returns false for an unknown version. See D309.
func QuoteIdentifier ¶
QuoteIdentifier returns name quoted with the pair given, doubling the closing character inside it.
PostgreSQL passes a double quote for both, SQL Server passes a bracket pair, and MySQL passes a backtick. Doubling the closer is what every one of them specifies.
func QuoteLiteral ¶
QuoteLiteral returns s as a single quoted SQL string literal.
It doubles the quote always, and doubles a backslash when the session says a backslash escapes. That second part is why this takes the state rather than being a plain function: on MySQL and MariaDB the answer changes with sql_mode, and on Vertica with standard_conforming_strings.
It is exported because a model outside this repository needs the same rule, and because the rule is the thing worth reviewing once.
func RegisterDialect ¶
RegisterDialect records what a model declares about its database. A model package calls this from its init. Registering twice panics, the way database/sql.Register does, because two models for one dialect is a build mistake rather than a run time condition.
func RightAligned ¶ added in v0.18.0
func RightAligned(names ...string) func(*sql.ColumnType) (Align, bool)
RightAligned returns a function for Info.ColumnAlign that follows the rule of psql: a column of a numeric type prints on the right, and a column of any other type prints on the left. The names are the strings that sql.ColumnType.DatabaseTypeName returns through the drivers of the product, and a name matches in any case. A model lists the names that it measured, one for each driver that reports a name of its own. See D245.
func TimeKinds ¶ added in v0.52.0
func TimeKinds(kinds map[TimeKind][]string) func(*sql.ColumnType) TimeKind
TimeKinds returns a function for Info.TimeKind that gives the kind of a column from the name that the driver reports for its type. A name matches in any case and without its size, and a column with any other name, and a column with no name, has no kind. See D309.
Types ¶
type AccessMethod ¶
type AccessMethod struct {
Name string
Type string
Handler sql.Null[string]
Comment sql.Null[string]
}
AccessMethod is an index or table access method. psql lists them with \dA.
type Align ¶ added in v0.18.0
type Align uint8
Align says on which side a client prints the values of a column.
The alignments. The zero value is none, which Dialect.ColumnAlign returns with false for a dialect that records nothing.
func (Align) String ¶ added in v0.18.0
String satisfies fmt.Stringer.
type AnyQuery ¶
type AnyQuery interface {
// Name returns the name of the object kind.
Name() string
// Support says whether the query can be asked of m.
Support(m *Meta) Support
// Fields returns the result columns for m, in order.
Fields(m *Meta) ([]Field, error)
// Params returns the parameters the query takes for m.
Params(m *Meta) ([]Param, error)
// Build returns the statement for m and the arguments in order.
Build(m *Meta, args map[string]any) (string, []any, error)
}
AnyQuery is a query with its result type erased, so that a caller can list every query and describe it without naming every result type. Query satisfies it.
Use it to list what dbmeta knows. To read rows, use the Query value itself, which keeps the result type.
func Queries ¶
func Queries() []AnyQuery
Queries returns every query dbmeta knows, in the order they were declared. A caller lists them to show a person what it can ask for, and calls AnyQuery.Support to find out which of them this database answers.
type Args ¶
type Args struct {
// Catalog is the name pattern of the catalog an object belongs to.
Catalog string
// Schema is the name pattern of the schema an object belongs to.
Schema string
// Parent is the name pattern of the object that contains this one, such as
// the table a column belongs to.
Parent string
// Name is the name pattern the object itself must match.
Name string
// ParentSchema is the name pattern of the schema of the parent, for a
// kind whose rows name a parent of their own, such as the parents that
// Inherits reads. Partition and PartitionSchema are the same for the
// partition that Partitions reads. See D201.
ParentSchema string
PartitionSchema string
// Types narrows a table to the kinds named, by Table.Type, such as table
// and view. Only Tables takes it, and every model's Tables does. It is
// bound as one string with the items joined by commas. See D138.
Types []string
// AccessMethod is the name pattern of an access method, which the
// operator classes and families of PostgreSQL take.
AccessMethod string
// Type is the name pattern of a type, which the operator classes and the
// operator families of PostgreSQL take, as the second pattern of psql's
// \dAc and \dAf does. An operator class matches it against its input type
// and an operator family against the types of its classes. See D309.
Type string
// Server is the name pattern of a foreign server, which the user mappings
// of PostgreSQL and the foreign tables of CrateDB take.
Server string
// Database is the name pattern of a database, which the role settings of
// PostgreSQL take.
Database string
// WithSystem includes the objects the database keeps for itself.
WithSystem bool
// WithIndexes adds the indexes that Partitions and Inherits leave out, so
// that a partitioned index has partitions and an index partition has a
// parent. See D262.
WithIndexes bool
// WithImplicit adds the tables that a publication of a schema or of
// every table offers without naming them, which PublicationTables reads.
// See D199 and D201.
WithImplicit bool
// WithTableInfo asks for the size, the row count and the options of a
// table from SVV_TABLE_INFO, which the Tables of Redshift reads only on
// request. Only a superuser or a user with SELECT on that view can read
// it, and a user without the right gets the error 42501 for the whole
// kind. Without it Size, Rows and Options are NULL. No other model takes
// it, so Query.All refuses it there and Query.Each leaves it out. See
// D232.
WithTableInfo bool
// ArgTypes narrows a function or an operator by the types of its
// arguments, as the type patterns of psql's \df and \do do. Each item is
// a name pattern for the type at that position, matched against the
// internal name of the type and the name that format_type gives, and the
// item - means that there is no argument at that position. For an operator
// the first item is the left operand and the second is the right one. An
// item can name a schema, such as pg_catalog.int4. A name that is not
// quoted must be in lower case, because the model reads the aliases int,
// float and decimal and the rest as psql does, and does not fold case.
// Only the Functions, Aggregates and Operators of PostgreSQL take it, so
// Query.All and Query.Each refuse it where it is not taken. See D272.
ArgTypes []string
}
Args builds the argument map for a query from the usual filter axes. It is a convenience: a caller can pass a plain map instead.
Only the fields that are set are included, so a query that does not take a parameter never receives it.
type Batch ¶
Batch is a statement that opens a batch and the one that closes it, such as CQL's BEGIN BATCH and APPLY BATCH.
type Binding ¶
type Binding[T any] struct { // Stmt is the versioned statement. Stmt Stmt // Variants are the statements that replace Stmt when their parameter is // true. The first one that applies wins. Nil for every model but // Redshift's Tables. See D232. Variants []Variant // Fields are the result columns, in the order the statement returns them. Fields []Field // Params are the parameters the statement takes. Params []Param // Derived are the values the statement reads that a caller does not pass. // They are not in Params. Derived []Derived // Scan reads one row. The model writes it by hand, so no reflection is // needed. Scan func(*sql.Rows) (T, error) // Keep decides whether a row is yielded. It is for a product that cannot // filter in SQL, such as Cassandra, where CQL has no OR and no IS NULL, so // every statement returns every row. Query.All calls it after Scan, with // the row and the arguments with the defaults filled in, which is the map // that Walk receives. A row for which it returns false is not yielded. A // model that filters in its statement leaves it nil, and every row is // yielded. A consumer does not narrow the rows itself, so it needs no // knowledge of the product. The match is the model's, and the model // usually makes it with [Like]. It is not called for a row that Scan // failed to read, and it is not used when Walk is set. See D200. Keep func(row T, args map[string]any) bool // Walk answers the query with several statements, for a product whose // catalog lists a kind only inside one parent at a time, as Impala lists // tables only with SHOW TABLES IN one database. It runs its statements // through db, each to its end before the next, so that it holds one // connection at a time. args holds every parameter, with the defaults // filled in. Nil for every model but Impala's. When it is set, Stmt and // Scan are unused, and Build returns ErrSeveralStatements, because there // is no one statement to return. See D146. Walk func(ctx context.Context, db Queryer, args map[string]any) iter.Seq2[T, error] }
Binding is everything one dialect provides for one query.
type Cast ¶
type Cast struct {
Source string
Target string
Function sql.Null[string]
Implicit string
LeakProof sql.Null[bool]
Comment sql.Null[string]
}
Cast converts one type to another. psql lists them with \dC.
type Choice ¶
type Choice []Fragment
Choice holds the alternatives for one piece of a statement. Exactly one is used, and Choice.Resolve says which.
A piece is usually one column of the select list, because that is what changes between releases.
Every alternative of a Choice must produce the same column, under the same name. That rule is what lets one Go type read the result of every supported version, and nothing here can check it. Whichever side lacks a source pads, old or new, by selecting a literal NULL under that name. Where the type differs between releases, each alternative casts to one common type.
func (Choice) Resolve ¶
func (c Choice) Resolve(versions VersionSet) (string, error)
Resolve returns the SQL of the alternative that applies to versions.
Three rules decide it, in order. An alternative whose gate the server does not meet is out. Among those left, a named key beats the empty key, because a fragment written for one product is more specific than one written for the family. Among those sharing a key, the highest Min wins.
Two alternatives naming different keys, both met, return ErrAmbiguousFragment. Nothing decides between them, and a guess picks by a number that means something different on each side. It is a fault in the model.
A Choice where every alternative names a key and the server reports none of them returns ErrNotSupported rather than ErrVersionTooOld. The server is not too old for this piece. It is the wrong product for it, and no upgrade changes that. A server that does report the key and is below the Min is too old, which an upgrade fixes, so that stays ErrVersionTooOld.
type Collation ¶
type Collation struct {
Schema string
Name string
Provider sql.Null[string]
Collate sql.Null[string]
CType sql.Null[string]
Locale sql.Null[string]
Deterministic sql.Null[bool]
Comment sql.Null[string]
// Rules is the tailoring rules of an ICU collation, as psql's \dO+
// prints them. PostgreSQL 16 added them. See D147.
Rules sql.Null[string]
}
Collation is a sorting rule. psql lists them with \dO.
type Column ¶
type Column struct {
Catalog string
Schema string
Table string
Name string
Ordinal int
DataType string
Nullable bool
Default sql.Null[string]
// PrimaryKey reports whether the column is part of the primary key.
//
// psql does not print this and it is here under D47, because two
// consumers read it per column and every database can answer it without a
// second statement: MySQL has COLUMN_KEY, SQLite has the pk column of
// pragma_table_xinfo, and PostgreSQL reaches it with one more join.
PrimaryKey bool
// Identity is the identity kind, empty when the column is not an identity.
// PostgreSQL gained it in release 11, so an older server reports it absent
// under the padding rule, and [Field.Present] says which is which.
Identity sql.Null[string]
// Generated is the generated kind, empty when the column is not
// generated. PostgreSQL gained it in release 12.
Generated sql.Null[string]
Comment sql.Null[string]
// Collation is the name of the column's collation, and absent for a
// type that has none or a product that records none. It is here under
// D47, because psql prints it in \d and it is a column of the same
// catalog row. psql prints it only where it differs from the type's
// default, and a caller decides that. See D139.
Collation sql.Null[string]
// Storage is how PostgreSQL stores a value that is too large for a page:
// plain, main, external or extended. It is absent where the product has
// no such choice. See D198.
Storage sql.Null[string]
// Compression is the compression method that is set on the column, such
// as pglz or lz4. It is absent when the column uses the server default,
// and on a server that has no such setting, which is every release before
// 14. [Field.Present] says which. See D198.
Compression sql.Null[string]
// StatsTarget is the statistics target that was set on the column with
// ALTER TABLE, and absent when the column uses the default. See D198.
StatsTarget sql.Null[int64]
// DefaultIsLiteral says that Default is the value and not an expression, so
// that a statement that sets it must quote it. MySQL gives the text of a
// string default with no quotes, and that is the only product that does.
// It is absent where Default is already the text of SQL, which is every
// other model. See D276.
DefaultIsLiteral sql.Null[bool]
// Invisible says that the column is hidden from SELECT * and from the column
// list of an INSERT, as an INVISIBLE column of Oracle or MySQL is. It is absent
// where the product has no such column. See D294.
Invisible sql.Null[bool]
// NestedStorage is the name of the table that stores the rows of a nested
// table column, and absent for any other column. Oracle makes it with STORE AS.
NestedStorage sql.Null[string]
// OnUpdate is the expression that a column takes when its row is updated, such
// as CURRENT_TIMESTAMP in MySQL, and absent for a column that has none.
OnUpdate sql.Null[string]
// DefaultName is the name that a person gave the default constraint of the
// column, for a product that names them. It is absent when the system named it
// or the product has none. See D296.
DefaultName sql.Null[string]
}
Column is one column of a table.
type ColumnPrivilege ¶ added in v0.9.0
type ColumnPrivilege struct {
Schema string
Table string
Column string
Ordinal int64
Access string
Grantee sql.Null[string]
Grantor sql.Null[string]
Privileges string
}
ColumnPrivilege is one entry of the access privileges of a column, which psql prints under its name in the Column privileges of \dp. It is one row for each entry, in the order the catalog holds them, so a column with two grantees is two rows. Access is the entry as psql prints it, such as pd_writer=w/postgres. Grantee is absent for public. Privileges are the letters of the entry, such as arw*. See D201.
type ColumnStat ¶
type ColumnStat struct {
Catalog string
Schema string
Table string
Name string
// AvgWidth is the average size of a value in bytes.
AvgWidth sql.Null[int64]
// NullFrac is the fraction of values that are null, from zero to one.
NullFrac sql.Null[float64]
// Distinct is the number of distinct values. A negative number is a
// fraction of the row count, which is how PostgreSQL records a column
// whose distinct count grows with the table.
Distinct sql.Null[float64]
Min sql.Null[string]
Max sql.Null[string]
Mean sql.Null[string]
// TopN holds the most common values and TopNFreqs their frequencies, both
// as text, one entry per line. They are the same length.
TopN sql.Null[string]
TopNFreqs sql.Null[string]
}
ColumnStat is what the planner knows about the values in a column.
It is runtime and it can be stale. Every database here computes it when asked, by ANALYZE or its equivalent, and not when the data changes. A column never analyzed has no row.
usql shows this with \ss, which psql does not have.
type Comment ¶
type Comment struct {
Schema string
Name string
Type string
Comment string
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
}
Comment is a comment on any object. psql shows them with \dd.
type Constraint ¶
type Constraint struct {
Schema string
Table string
Name string
Type string
Definition sql.Null[string]
Deferrable bool
Deferred bool
Comment sql.Null[string]
// OnUpdate and OnDelete are what a foreign key does to the row that points at
// a changed or removed row, such as CASCADE, SET NULL, RESTRICT or NO ACTION.
// They are absent for any other constraint and where Definition holds the
// whole text of the key, which is every model but the MySQL one. See D276.
OnUpdate sql.Null[string]
OnDelete sql.Null[string]
// Enforced reports whether the server checks the constraint. It is absent
// where the model does not read it, which is every model but Snowflake.
// Snowflake records a key and checks none, so it reads false for each of
// them, and deferred of true beside it means only that the server says so.
// See D203.
Enforced sql.Null[bool]
}
Constraint is a check, unique, primary key, foreign key or exclusion constraint. psql shows them inside \d name.
Definition is absent where the database records no expression for the kind of constraint. Read through information_schema, only a check constraint has one, because check_clause is the only expression the standard records.
type ConstraintColumn ¶
type ConstraintColumn struct {
Catalog string
Schema string
Table string
Constraint string
Name string
Ordinal int64
ForeignCatalog sql.Null[string]
ForeignSchema sql.Null[string]
ForeignTable sql.Null[string]
ForeignName sql.Null[string]
}
ConstraintColumn is one column of a constraint, in constraint order.
It is durable. psql prints a constraint as one line of text, which Constraint.Definition still holds, and this is the same fact in parts. A code generator reads a foreign key from here, because parsing a rendered definition is not something to rely on.
A composite key is several rows sharing Constraint, told apart by Ordinal. The Foreign fields are set only for a foreign key and name what the column points at.
type Conversion ¶
type Conversion struct {
Schema string
Name string
Source string
Target string
Default bool
Comment sql.Null[string]
}
Conversion is an encoding conversion. psql lists them with \dc.
type Database ¶
type Database struct {
Name string
Owner string
Encoding string
Collate string
CType string
Access sql.Null[string]
Tablespace sql.Null[string]
Size sql.Null[string]
Comment sql.Null[string]
// LocaleProvider is libc, icu or builtin. It is libc below release 15,
// which had no other provider. Locale is the ICU or builtin locale, and
// absent for libc. ICURules are the tailoring rules of an ICU locale, from
// release 16. See D201.
LocaleProvider sql.Null[string]
Locale sql.Null[string]
ICURules sql.Null[string]
}
Database is a database within a server. psql lists them with \l.
type DatabaseName ¶ added in v0.31.0
DatabaseName is the name of the database that a connection is using. It is absent when the connection has chosen none.
type DefaultACL ¶
DefaultACL is a default grant applied to objects created later. psql lists them with \ddp.
type Derived ¶ added in v0.10.0
Derived is a value that a statement reads as a parameter and a caller never passes. From computes it from the arguments of the call, with the defaults filled in, so a statement can use a fact that no single argument holds, such as the scope of a SHOW that depends on whether two patterns are exact names.
It is for a dialect that sets Info.Literal, where what From returns is rendered by that function, so the dialect decides how a derived value is written. A statement names it with an at sign, as it names a Param, and a caller that passes its name gets ErrUnknownParam. Only the Snowflake model has one. See D203.
type Dialect ¶
type Dialect string
Dialect names one database family. Its value is the dburl driver name of the scheme that is canonical for the product, and a consumer with a dburl URL reads it from URL.Dialect, which dburl sets from v0.32.0.
Read URL.Dialect and never URL.Driver. A product with two Go drivers has two schemes, and URL.Driver names the driver: pgx and postgres, moderncsqlite and sqlite3. Each pair has one Dialect. dbmeta holds no such list, because hard rule 1 keeps that taxonomy in dburl. See D99.
A product that speaks another product's wire protocol has a Dialect of its own, as dburl gives it from v0.36.0. CockroachDB, CrateDB, QuestDB and Redshift speak PostgreSQL's protocol, and SingleStore, TiDB and Vitess speak MySQL's, and each has its own dialect, because its catalog is its own. A model for one of them can share the statements of the product it imitates, as the CockroachDB model does (dburl D30 and D37, D123, D125).
A dialect names the family and never the release. A release arrives as a VersionSet value, because D8 resolves version differences at run time. See New.
const ( // ArangoDB is queried in AQL rather than SQL, over HTTP. ArangoDB Dialect = "arangodb" // Athena is Amazon Athena. The value was awsathena while dburl v0.49.0 named // the scheme that way, and it is athena since dburl renamed it, as the // driver of dbimp is named. See D227. Athena Dialect = "athena" // Avatica is the standalone Avatica server, which stands in front of // HSQLDB and which dbimp's avatica driver reaches. Phoenix speaks the same // protocol and has no model. See D186. Avatica Dialect = "avatica" BigQuery Dialect = "bigquery" Cassandra Dialect = "cassandra" Chai Dialect = "chai" ClickHouse Dialect = "clickhouse" // CockroachDB speaks PostgreSQL's protocol, and pgx reaches it. CockroachDB Dialect = "cockroachdb" Couchbase Dialect = "couchbase" Cosmos Dialect = "cosmos" // CrateDB speaks PostgreSQL's protocol on its port 5432, and pgx reaches // it. CrateDB Dialect = "cratedb" CSVQ Dialect = "csvq" Databricks Dialect = "databricks" Databend Dialect = "databend" // Drill is Apache Drill, which dbimp's drill driver reaches on the REST // interface of a Drillbit. See D178. Drill Dialect = "drill" // Druid is Apache Druid, which dbimp's druid driver reaches on the SQL // API of the Router. See D171. Druid Dialect = "druid" DuckDB Dialect = "duckdb" DynamoDB Dialect = "dynamodb" // Elasticsearch reaches its SQL on /_sql, through dbimp's elasticsearch // driver. See D177. Elasticsearch Dialect = "elasticsearch" Exasol Dialect = "exasol" Firebird Dialect = "firebirdsql" Hive Dialect = "hive" HANA Dialect = "hdb" // Impala is Apache Impala, which serves HiveServer2's protocol and has // a catalog of its own. See D145. Impala Dialect = "impala" InfluxDB Dialect = "influxdb" InfluxQL Dialect = "influxql" // LibSQL is libSQL, the fork of SQLite by Turso, which sqld serves // over HTTP. LibSQL Dialect = "libsql" MaxCompute Dialect = "maxcompute" // MemSQL is SingleStore, which speaks MySQL's protocol. dburl names // its scheme memsql, the name SingleStore had until 2020. MemSQL Dialect = "memsql" MySQL Dialect = "mysql" Neo4j Dialect = "neo4j" // OpenSearch reaches its SQL on /_plugins/_sql, through dbimp's opensearch // driver. See D181. OpenSearch Dialect = "opensearch" Oracle Dialect = "oracle" Pinot Dialect = "pinot" Presto Dialect = "presto" PostgreSQL Dialect = "postgres" // QuestDB speaks PostgreSQL's protocol on its port 8812, and pgx // reaches it. QuestDB Dialect = "questdb" // Redshift speaks PostgreSQL's protocol, and pgx reaches it. Redshift Dialect = "redshift" // Rqlite is rqlite, which runs SQLite behind an HTTP API. Rqlite Dialect = "rqlite" Snowflake Dialect = "snowflake" // Solr is Apache Solr, which dbimp's solr driver reaches on the SQL handler // of a collection. See D179. Solr Dialect = "solr" Spanner Dialect = "spanner" SQLite3 Dialect = "sqlite3" SQLServer Dialect = "sqlserver" SurrealDB Dialect = "surrealdb" Tablestore Dialect = "tablestore" // TiDB speaks MySQL's protocol, and the mysql driver reaches it. TiDB Dialect = "tidb" Trino Dialect = "trino" Vertica Dialect = "vertica" // Vitess speaks MySQL's protocol, and the mysql driver reaches it. Vitess Dialect = "vitess" // YDB is Yandex's distributed database, which ydb-go-sdk reaches over // gRPC. See D161. YDB Dialect = "ydb" )
Dialect values. One per database family.
The name is what the database calls itself. The value is the `dburl` driver name, which is not always the same word. PostgreSQL calls itself PostgreSQL and its driver is postgres. Cassandra calls itself Cassandra and its driver is cassandra, since the driver moved from github.com/xo/cql to github.com/xo/cassandra and dburl v0.47.0 renamed its scheme (D196). Couchbase was n1ql until dburl v0.33.0 renamed its scheme couchbase, when the driver moved to github.com/xo/dbimp (D101). Read these as constants and never as literals.
func Dialects ¶
func Dialects() []Dialect
Dialects returns every dialect built into this binary, which depends on the build tags. See D31.
func (Dialect) ChangePassword ¶
func (d Dialect) ChangePassword(c PasswordChange, q Quoting) (string, error)
ChangePassword returns the statement that sets the password, and does not run it.
It takes no database on purpose. dbmeta executes reads and this is not one, so the caller runs it, logs what it chooses to log, and decides what to do with the text afterwards. The text contains the password in clear, because the server requires that, so a caller must keep it out of its logs.
It returns ErrModelNotBuilt when the model is not built, ErrNotSupported when the product has no such statement, and ErrQuotingUnknown when the product needs session state that Quoting does not carry.
func (Dialect) Classify ¶ added in v0.31.0
Classify says what a client does with a statement. It returns the command tag that a client prints after a statement that returns no rows, such as INSERT or CREATE TABLE, and whether the statement returns rows, so that the client passes it to a query and not to an exec.
The decision reads the whole statement, outside of strings, quoted names and comments, by the lexical forms of the dialect (Syntax). It does not need the release, because a release that lacks a clause refuses the statement, and the client prints the error. A statement that has a RETURNING clause at its top level returns rows, and so does an OUTPUT clause of SQL Server that has no INTO. A statement of an unknown dialect is read with the same rules and none of the product's clauses. See D264.
func (Dialect) ColumnAlign ¶ added in v0.18.0
func (d Dialect) ColumnAlign(ct *sql.ColumnType) (Align, bool)
ColumnAlign returns the alignment of a column of d, from the type that the driver reports for it. The second result is false when the model of d records no alignment, or no model was built for d, and then a client falls back to aligning by the values. See Info.ColumnAlign.
func (Dialect) CopyFromStdin ¶ added in v0.51.0
CopyFromStdin says whether stmt is a COPY that reads its rows from the client, such as COPY t (a, b) FROM STDIN. The client sends the rows after the statement, up to a line that holds only \., and it can do that only when the COPY is the one statement of the text. If the text holds a COPY FROM STDIN and any other statement, it returns true and ErrCopyFromStdinNotAlone. A STDIN inside a string, a quoted name or a comment does not count, and neither does a COPY TO STDOUT, a COPY from a file or a COPY from a program. A dialect that does not read rows from the client returns false. See D307.
func (Dialect) DescribeResult ¶ added in v0.36.0
func (d Dialect) DescribeResult(query string) (ResultDescription, error)
DescribeResult returns the statement that describes the first result of query without running it.
It describes one statement. A batch is described by its first statement, so the caller refuses anything that is not a single statement. It returns ErrModelNotBuilt when the model is not built, ErrNotSupported when the product cannot describe a query in one statement, and ErrMissingParam for an empty query. SQL Server is the one product that answers. A caller with another product describes the result through its driver, or by running the query with no rows wanted, which it decides, because that runs the query.
func (Dialect) Embedded ¶
Embedded reports whether the database is a library rather than a server.
It is false for a dialect no model was built for, the same as for a server, because the question cannot be answered without the model. See Info.Embedded.
func (Dialect) EveryStatementIsAQuery ¶ added in v0.14.0
EveryStatementIsAQuery reports whether every statement of the product's language returns a result and the server sends no count, so that a client runs each statement as a query and never as an exec. See Info.EveryStatementIsAQuery.
It is false for a dialect that no model was built for.
func (Dialect) FoldIdentifier ¶
FoldIdentifier returns name as the product stores it, so that a caller can match it against the catalog. A name between double quotes, or between backticks where the product quotes with them, is returned without the quotes and as it is written, with a doubled quote made single. Any other name is folded as the product folds it. A dialect that no model is registered for returns name as it is.
psql folds a pattern the same way before it matches the catalog, which is why \d book finds BOOK on Oracle. See D143.
func (Dialect) FollowUpQuery ¶
func (d Dialect) FollowUpQuery(s VersionSet) (query string, cols int, ok bool)
FollowUpQuery returns the second version statement for s, the set that Dialect.ParseVersion returned, and how many columns it returns.
The caller runs it after the first statement and passes its columns to Dialect.ParseFollowUp. The third result is false when the dialect needs no second statement for this server, which is every dialect but cassandra, and cassandra on Cassandra. See D92.
func (Dialect) FormatBinary ¶ added in v0.27.0
FormatBinary returns the text of the value b of a column in the one form that every dialect uses, which is the form that psql prints for bytea: \x and the bytes in lower case hex, and \x alone for an empty value. It returns false when the column is not binary in this dialect or the dialect records nothing, so that a caller leaves the value alone. The caller does not call it for a NULL, because it cannot tell one from an empty value. The one exception is a value of 16 bytes in a column that the model says is a GUID, which is written as a lower case UUID with dashes, in the order of the bytes. See D258 and D263.
func (Dialect) Info ¶
Info returns what d declares. The second result is false when no model for d was built into this binary, which is not the same as the database being unable to answer. See ErrModelNotBuilt.
func (Dialect) ParseFollowUp ¶
func (d Dialect) ParseFollowUp(s VersionSet, cols []string) (VersionSet, error)
ParseFollowUp adds the columns returned by Dialect.FollowUpQuery to s.
func (Dialect) ParseQuoting ¶
ParseQuoting turns the columns returned by Dialect.QuotingQuery into the state.
func (Dialect) ParseSuperuser ¶ added in v0.52.0
ParseSuperuser reads the column that Dialect.SuperuserQuery returns. It accepts on, true, t, yes and 1, and off, false, f, no and 0, in any case, which are the forms that the products give. Any other text is ErrInvalidSuperuser.
func (Dialect) ParseVersion ¶
func (d Dialect) ParseVersion(cols []string) (VersionSet, error)
ParseVersion turns the columns returned by Dialect.VersionQuery into a version set carrying both the comparable version and the line to show a person.
func (Dialect) Pattern ¶
Pattern splits a psql pattern, such as public.film*, into a schema pattern and a name pattern that a query takes, as psql does before it matches the catalog.
The pattern splits at the first dot outside double quotes. Text outside double quotes is folded as the product folds a name, which is FoldIdentifier, and text inside them is kept as it is written, with a doubled quote made single. Outside double quotes, * becomes % and ? becomes _. A pattern with no dot is a name pattern, and the schema pattern is empty. A % or an _ in the pattern stays a wildcard, because the queries take a LIKE pattern with no escape.
func (Dialect) Placeholder ¶ added in v0.14.0
Placeholder writes the bind parameter for position n, counting from 1, as the product writes it: $1, ?, :1 or @p1. The second result is false when the dialect has no model and no row of its own, or when its model sets no Info.Placeholder. It is the form that a client writes into an INSERT statement, as usql does for \copy.
A product that cannot bind in a statement of dbmeta, such as Apache Hive and Snowflake, writes its values with Info.Literal there. This method still returns the placeholder that a client writes in its own statement.
func (Dialect) Product ¶ added in v0.14.0
Product returns the text to show for the version of a product that has no statement that reads its version, such as Amazon DynamoDB and Apache Pinot. The second result is false when the dialect has no such text, which is every dialect that has a Info.VersionQuery.
A model can set Info.Product and a dialect with no model has a row of its own, so this works for both. See D230.
func (Dialect) Quoting ¶
Quoting reads the session state from the server.
This is a read and it runs a query, the same way Dialect.Version does. A caller that runs the statement itself uses Dialect.QuotingQuery and Dialect.ParseQuoting.
A product with no such state returns the zero value and no error.
func (Dialect) QuotingQuery ¶
QuotingQuery returns the statement that reads the session state Dialect.ChangePassword needs, and how many columns it returns.
The result is false when the product needs none, which is not an error: SQL Server has no setting that changes how a literal is escaped.
func (Dialect) ScanTypes ¶ added in v0.14.0
ScanTypes reports whether a client must scan each column into the Go type that the driver reports. See Info.ScanTypes.
It is false for a dialect that no model was built for.
func (Dialect) SplitIdentifier ¶ added in v0.53.0
SplitIdentifier splits a qualified name, such as dbo.[my table] or "Sch"."t", into its parts as the database reads it, and folds each part as Dialect.FoldIdentifier does.
A dot outside a quote separates two parts. A part is quoted with double quotes, with backticks where the product quotes with them, and with brackets where the product writes them, which SQL Server and SQLite do. A doubled closing quote inside a quoted part is one quote. Space outside a quote is dropped. A part that is empty stays empty, because SQL Server reads db..t as the default schema of db, and the caller decides what an empty part means. A quote that is never closed, a character after a closing quote that is not a dot, and a name with no text are ErrInvalidIdentifier. A dialect that no model is registered for returns ErrModelNotBuilt. See D312.
func (Dialect) SuperuserQuery ¶ added in v0.52.0
SuperuserQuery returns the statement that reads whether the session user is a superuser, and how it reads. The caller runs it, scans the one column as a string and passes it to Dialect.ParseSuperuser.
The second result is false when the model was not built, or the product has no superuser, or the model measured no statement for it. A client treats that as unknown. See D309.
func (Dialect) Syntax ¶
Syntax returns the lexical forms of the dialect's SQL, and false when no model is registered for it.
func (Dialect) TimeKind ¶ added in v0.52.0
func (d Dialect) TimeKind(ct *sql.ColumnType) TimeKind
TimeKind returns what the column holds when it is a date or a time, from the type that the driver reports for it. It returns zero when the column is neither, when the model of d records no kinds, or when no model was built for d. See Info.TimeKind.
func (Dialect) TypeNames ¶ added in v0.36.0
TypeNames returns the statement that names the types of the columns of a result, and does not run it. The rows have two columns, ord and type. The first is the place of the type in types, counted from 1, and the second is its name as the product spells it in SQL, such as "character varying(10)".
It is for a product that describes a result with numbers, which is PostgreSQL and the products that speak its protocol and keep format_type. It returns ErrNotSupported for any other and ErrMissingParam for an empty list.
func (Dialect) Version ¶
Version runs the version statement against db and returns the parsed result.
It is the steps above done together, because every caller needs both and doing them by hand means building a slice of pointers into a slice of strings. A caller that wants the statement without running it, to print it or to run it its own way, uses Dialect.VersionQuery and Dialect.ParseVersion instead.
This does not detect anything on the caller's behalf. The caller decides whether to call it, and is free to build a VersionSet by hand and pass that to New instead. Overriding the version is the point of D36 and this method does not take it away.
A database that reports no version returns an unknown version and no error. An unknown version selects the newest fragment of every piece.
func (Dialect) VersionNum ¶ added in v0.52.0
func (d Dialect) VersionNum(s VersionSet) (int, bool)
VersionNum returns the integer form of the version in s, such as 180006 for PostgreSQL 18.6, which a client shows as SERVER_VERSION_NUM. The second result is false when the product has no such form, when no model was built for d, or when the version is unknown. See Info.VersionNum.
func (Dialect) VersionQuery ¶
VersionQuery returns the statement that reads the server version, and how many columns it returns.
dbmeta cannot run it. The caller runs it as its first statement, scans the columns as strings, and passes them to Dialect.ParseVersion. See D38.
The second result is false when the model was not built or the database reports no version.
func (Dialect) WritesNeedAutocommit ¶ added in v0.14.0
WritesNeedAutocommit reports whether a write must run outside a transaction. See Info.WritesNeedAutocommit.
It is false for a dialect that no model was built for.
type Domain ¶
type Domain struct {
Catalog string
Schema string
Name string
DataType string
Collation string
Nullable bool
Default sql.Null[string]
Constraints string
Access sql.Null[string]
Comment sql.Null[string]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
}
Domain is a type with a constraint. psql lists them with \dD.
type EnumValue ¶
EnumValue is one label of an enumerated type, in sort order.
It is durable. Type.Elements holds the labels joined into one string, which is what psql prints, and this is the same fact in rows. A label can contain a comma, so splitting that string is not a substitute.
MySQL has no enum type, only an enum column, and the mysql model does not answer this kind.
type Error ¶
type Error string
Error is an error.
const ( // ErrNotSupported is the not supported error. The model exists and the // database cannot answer for that object. ErrNotSupported Error = "not supported" // ErrCopyFromStdinNotAlone is the copy from stdin not alone error. The // text holds a COPY that reads its rows from the client and another // statement, so the rows cannot follow the COPY. See [Dialect.CopyFromStdin]. ErrCopyFromStdinNotAlone Error = "copy from stdin is not the only statement" // ErrModelNotBuilt is the model not built error. The model was left out of // this binary by a build tag. It says nothing about what the database can // do. ErrModelNotBuilt Error = "model not built" // ErrNotFound is the not found error. The database has no object of that // name. An empty result means the same thing and is not an error. ErrNotFound Error = "not found" // ErrPermissionDenied is the permission denied error. The connected user // cannot read that part of the catalog. ErrPermissionDenied Error = "permission denied" // ErrVersionTooOld is the version too old error. The server is older than // the oldest version the model supports. ErrVersionTooOld Error = "version too old" // ErrInvalidVersion is the invalid version error. ErrInvalidVersion Error = "invalid version" // ErrInvalidSuperuser is the invalid superuser error. The column that // the superuser query returned is not a boolean in a form that // [Dialect.ParseSuperuser] knows. ErrInvalidSuperuser Error = "invalid superuser" // ErrEmptyQuery is the empty query error. A statement resolved to no SQL. ErrEmptyQuery Error = "empty query" // ErrUnknownParam is the unknown parameter error. An argument was given a // name the statement does not take. It is never ignored, because ignoring // it turns a typo into a query that silently drops a filter. ErrUnknownParam Error = "unknown parameter" // ErrMissingParam is the missing parameter error. The statement names a // parameter that the arguments do not supply. ErrMissingParam Error = "missing parameter" // ErrSeveralStatements is the several statements error. The query is // answered with more than one statement, which Query.All runs, so Build // has no one statement to return. See D146. ErrSeveralStatements Error = "answered with several statements" // ErrInvalidParam is the invalid parameter error. A value cannot be // rendered into a statement by a dialect that has no way to bind one. // Only Apache Hive can return it, because only Hive renders literals, // and it returns one rather than guessing at a value it cannot escape // safely. See [Info.Literal] and D78. ErrInvalidParam Error = "invalid parameter" // ErrQuotingUnknown is the quoting unknown error. Building a statement // that carries a password needs session state the caller did not read, // and guessing it can let the password escape its own literal. See D56. ErrQuotingUnknown Error = "quoting unknown" // ErrInvalidPassword is the invalid password error. A password or a user // name holds a character the product cannot carry in the statement: a NUL // on every product, and a double quote on Oracle, which takes both // between double quotes and has no escape for one. ErrInvalidPassword Error = "invalid password" // ErrInvalidString is the invalid string error. A value holds a character // that the product cannot carry in a literal or in a quoted name: a NUL on // every product, and a double quote in a name on Oracle, which has no // escape for one. ErrInvalidString Error = "invalid string" // ErrInvalidIdentifier is the invalid identifier error. A qualified name has // a quote that is never closed, text after a quoted part, or no text at all. ErrInvalidIdentifier Error = "invalid identifier" // ErrAmbiguousFragment is the ambiguous fragment error. Two alternatives // of one choice name different versions and the server reports both, so // nothing decides between them. It is a fault in the model, not in the // database or the call. See D44. ErrAmbiguousFragment Error = "ambiguous fragment" )
Error values.
type Event ¶ added in v0.45.0
type Event struct {
Schema string
Name string
// Definer is the account that runs the event, as user@host.
Definer string
// Kind is one time or recurring.
Kind string
// ExecuteAt is the instant of a one time event.
ExecuteAt sql.Null[string]
// IntervalValue and IntervalField are the period of a recurring event, such as
// 1 and DAY.
IntervalValue sql.Null[string]
IntervalField sql.Null[string]
// Starts and Ends bound a recurring event, and are absent when it has no bound.
Starts sql.Null[string]
Ends sql.Null[string]
// Status is enabled, disabled or slaveside_disabled.
Status string
// OnCompletion is preserve or not preserve.
OnCompletion string
// Body is the statement that the event runs.
Body string
Comment sql.Null[string]
SQLMode sql.Null[string]
}
Event is a statement that the server runs on a schedule, as a MySQL or a MariaDB event does. A dump writes it back with CREATE EVENT.
type EventTrigger ¶
type EventTrigger struct {
Name string
Event string
Owner string
Enabled string
Function string
Tags sql.Null[string]
Comment sql.Null[string]
// Definition is the statement that makes the trigger, for a product that keeps
// one, and absent where it keeps none. See D296.
Definition sql.Null[string]
}
EventTrigger fires on a DDL event. psql lists them with \dy.
type ExtendedStat ¶
type ExtendedStat struct {
Schema string
Name sql.Null[string]
Owner sql.Null[string]
Table string
Kinds string
Comment sql.Null[string]
// Definition is the columns and expressions the statistics cover and
// their table, as psql's \dX prints it. See D147.
Definition sql.Null[string]
// Ndistinct, Dependencies and MCV say which of the three kinds the object
// was made with, as the columns of psql's \dX do. Kinds holds the same
// letters, except on SAP HANA, where it holds the type of the statistic in
// lower case. MCV arrived in PostgreSQL 12.
Ndistinct bool
Dependencies bool
MCV bool
// StatsTarget is the statistics target of the object, and absent for the
// default. PostgreSQL has it from release 13. See D199.
StatsTarget sql.Null[int64]
// TableVisible reports that the table is on the search path of the
// session, so that psql prints its name with no schema. See D201.
TableVisible sql.Null[bool]
}
ExtendedStat is a statistics object over several columns. psql lists them with \dX.
type Extension ¶
type Extension struct {
Name string
Version string
Schema string
Comment sql.Null[string]
// DefaultVersion is the version the server installs by default, from the
// control file of the extension. It is absent when the files of the
// extension are not on the server. psql's \dx prints it. See D201.
DefaultVersion sql.Null[string]
}
Extension is an installed extension. psql lists them with \dx.
type ExtensionObject ¶
ExtensionObject is one object an extension owns. psql lists them with \dx+.
type Field ¶
type Field struct {
Name string
Desc string
// Min and Key are the gate that gives the field a real source. They mean
// what they mean on a [Gate].
Min Version
Key string
// Also holds further gates, for a field that arrived in a different
// release of each product. The field has a source when the gate above is
// met or any gate here is met. MariaDB recorded a check constraint from
// 10.2 and MySQL from 8.0.16, and no single number says both.
Also []Gate
}
Field is a result column that a query declares.
The set of fields is fixed for every version. Min and Key record the oldest version where the field has a real source, so a caller can tell a value that is null from a field the server has no source for. Below that the column is padded with NULL. Read Field.Present rather than the gate, which cannot tell an absent key from an old server on its own.
func (Field) Present ¶
func (f Field) Present(versions VersionSet) bool
Present reports whether the field has a real source on this server. A field that is not present is padded with NULL, so a caller reading NULL calls this to find out which of the two it has.
type Fold ¶
type Fold int
Fold is what a product does to the case of a name that is not quoted.
const ( // FoldNone keeps a name as it is written, and the product either // compares names with their case or compares them without it. MySQL, // SQL Server and SQLite are the cases. FoldNone Fold = iota // FoldLower stores a name in lower case, as PostgreSQL does. FoldLower // FoldUpper stores a name in upper case, as Oracle does. FoldUpper )
Fold values.
type ForeignDataWrapper ¶
type ForeignDataWrapper struct {
Name string
Owner string
Handler sql.Null[string]
Validator sql.Null[string]
Access sql.Null[string]
Options sql.Null[string]
Comment sql.Null[string]
}
ForeignDataWrapper reaches data outside the database. psql lists them with \dew.
type ForeignOption ¶ added in v0.9.0
type ForeignOption struct {
Kind string
Schema sql.Null[string]
Name sql.Null[string]
Server sql.Null[string]
Ordinal int64
Option string
Value string
Quoted string
}
ForeignOption is one option of a foreign data wrapper, a foreign server, a user mapping or a foreign table. The Options field of each of them is the catalog text, name=value joined by a comma and a space, which cannot be split back when a value holds that text. This is the same fact in parts, one row for each option, as D47 asks. See D201.
Kind is foreign data wrapper, foreign server, user mapping or foreign table. Name is the name of the object, and for a user mapping it is the name of the local role, public for every role. Schema is set for a foreign table only. Server is set for a user mapping and a foreign table. Ordinal is the position of the option in the list the catalog holds. Quoted is the option as psql prints it in the parentheses, such as "user" 'u', with the name quoted when it needs it and the value always quoted.
type ForeignServer ¶
type ForeignServer struct {
Name string
Owner string
Wrapper string
Type sql.Null[string]
Version sql.Null[string]
Access sql.Null[string]
Options sql.Null[string]
Comment sql.Null[string]
}
ForeignServer is a server reached through a wrapper. psql lists them with \des.
type ForeignTable ¶
type ForeignTable struct {
Schema string
Name string
Server string
Options sql.Null[string]
Comment sql.Null[string]
}
ForeignTable is a table on a foreign server. psql lists them with \det.
type Fragment ¶
Fragment is one alternative for one piece of a statement. It applies when the server meets its gate.
type Function ¶
type Function struct {
Catalog string
Schema string
Name string
// ID identifies the routine where a name does not. PostgreSQL overloads a
// name, so [RoutineParameters] joins on this rather than on Name. A
// database that does not overload reports it absent.
ID sql.Null[string]
Kind string
ResultType sql.Null[string]
ArgTypes sql.Null[string]
Volatility string
Parallel string
Owner sql.Null[string]
Security string
Access sql.Null[string]
Language string
// Source is what the product keeps apart from the whole statement: the
// body, or for a PostgreSQL function in C or internal code, the name of
// the C function it runs. It is absent
// where the product keeps only the whole statement, which is Definition.
// See D147.
Source sql.Null[string]
Comment sql.Null[string]
// Definition is the whole statement that makes the routine, such as
// pg_get_functiondef returns, which psql's \sf prints. It is absent where
// the product keeps only the body, which is Source, or keeps nothing.
// See D147.
Definition sql.Null[string]
// Leakproof reports whether the planner can trust the function not to
// reveal its arguments in an error. It is false where the product has no
// such property. See D198.
Leakproof bool
// Prosrc is the text PostgreSQL stores in pg_proc.prosrc for every
// language: the body for SQL, PL/pgSQL and the other languages, and the
// C function name or the link symbol for internal and C. Source holds it
// only for the last two. It is absent where the product keeps no such
// column. See D198.
Prosrc sql.Null[string]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
// Extension is the extension that owns the object, and absent for an object
// that no extension owns. A dump leaves such an object out and writes CREATE
// EXTENSION instead, because the extension makes it again. It is absent where
// the product has no extensions.
Extension sql.Null[string]
// DataAccess is what the routine says about the data it touches: contains
// sql, no sql, reads sql data or modifies sql data. It is absent where the
// product has no such declaration. See D293.
DataAccess sql.Null[string]
// SQLMode is the sql_mode that the routine was made under, which MySQL and
// MariaDB keep with it, and absent elsewhere. A dump sets it again before
// the statement that makes the routine.
SQLMode sql.Null[string]
}
Function is a function, procedure, aggregate or window function. psql lists them with \df and aggregates alone with \da.
type Gate ¶
Gate is a version test. The server must report Key at Min or newer. A zero Gate is met by every server.
Key names which reported version to compare against. The empty key is the main one, which every server reports. A named key is a fact about the server, and a server that does not report it does not meet the gate however new it is. Two things use a name:
A database that reports several versions that move independently. Cassandra reports three, so a gate on the CQL version sets Key to "cql".
A product that shares a dialect with another product. MariaDB and MySQL share one dialect and one model, and their release numbers have no relation to each other, so a gate on MariaDB 10.3 sets Key to "mariadb" and never applies to MySQL. Comparing the numbers alone is the fault D44 records.
func (Gate) Met ¶
func (g Gate) Met(versions VersionSet) bool
Met reports whether versions satisfies g.
type Grant ¶ added in v0.46.0
type Grant struct {
Schema string
// Object is the name of the object, and the schema itself for a grant on a schema.
Object string
// ObjectType is table, view, sequence, schema, function, procedure, type or another
// word of the product.
ObjectType string
// Arguments are the argument types of a function, which tell one of a name that is
// overloaded from another, and absent for any other object.
Arguments sql.Null[string]
// Column is the column that the grant is on, and absent for a grant on the object.
Column sql.Null[string]
// Grantee is the role or the account that holds the privilege, as the product writes
// it, and empty for every role.
Grantee string
// Privilege is the privilege in upper case, such as SELECT or EXECUTE.
Privilege string
// Grantable says that the grantee can give the privilege to others.
Grantable bool
// Denied says that the entry takes the privilege away, as DENY does in SQL Server.
Denied bool
// GranteeType says what the grantee is, such as user, role or account, for a product
// that tells them apart, and absent otherwise.
GranteeType sql.Null[string]
}
Grant is one privilege that was given to one grantee on one object, or on one column of it. The owner's own privileges are not rows.
type Index ¶
type Index struct {
Catalog string
Schema string
Table string
Name string
Type string
Unique bool
Primary bool
Comment sql.Null[string]
// Owner is the role that owns the index. See D198.
Owner sql.Null[string]
// Persistence is permanent, unlogged or temporary. See D198.
Persistence sql.Null[string]
// Size is the bytes the index takes on disk, as pg_table_size counts
// them. It is absent if the index was dropped while the statement ran.
// See D198.
Size sql.Null[int64]
// Predicate is the WHERE clause of a partial index, as pg_get_expr writes
// it, and absent for an index that covers every row. See D198.
Predicate sql.Null[string]
// Valid is false while an index is built with CONCURRENTLY, and after
// that build failed. The planner does not use an index that is not valid.
Valid sql.Null[bool]
// Clustered reports whether the table was last clustered on this index.
Clustered sql.Null[bool]
// ReplicaIdentity reports whether this index is the table's replica
// identity for logical replication.
ReplicaIdentity sql.Null[bool]
// Partitioned says that the index is a partitioned index, which is the
// index of a partitioned table and has an index on each partition. See
// D262.
Partitioned sql.Null[bool]
// Deferrable and InitiallyDeferred describe the constraint that owns the
// index, and are absent for an index no constraint owns. See D198.
Deferrable sql.Null[bool]
InitiallyDeferred sql.Null[bool]
// Options are the storage parameters set on the index, such as
// fillfactor=70, joined by a comma and a space. See D199.
Options sql.Null[string]
// Definition is the whole CREATE INDEX statement, as pg_get_indexdef
// writes it with the pretty flag, and Using is the part of it that follows
// the first " USING ", which is what psql prints in the Indexes footer of
// \d name. Both keep the operator class and the collation of a key column
// that is not the default. See D201.
Definition sql.Null[string]
Using sql.Null[string]
// ConstraintType is p, u or x for an index that a primary key, a unique
// constraint or an exclusion constraint owns, and absent for any other
// index. ConstraintDefinition is the text of that constraint, as
// pg_get_constraintdef writes it, such as EXCLUDE USING gist (...). psql
// prints it in place of the index text for an exclusion constraint and for
// a constraint WITHOUT OVERLAPS, which ConstraintPeriod reports. It is
// false below release 18, which has none. See D201.
ConstraintType sql.Null[string]
ConstraintDefinition sql.Null[string]
ConstraintPeriod sql.Null[bool]
// TableVisible reports that the table is on the search path of the
// session, so that psql prints its name with no schema. See D201.
TableVisible sql.Null[bool]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
// Invisible says that the optimizer ignores the index, as an INVISIBLE index of
// MySQL or an IGNORED index of MariaDB is. It is absent where the product has no
// such index. See D296.
Invisible sql.Null[bool]
}
Index is an index on a table.
type IndexColumn ¶
type IndexColumn struct {
Schema string
Table string
Index string
Name sql.Null[string]
Ordinal int64
Expression sql.Null[string]
Descending sql.Null[bool]
// Include reports that the column is an INCLUDE column and not a key
// column of the index. It is false below PostgreSQL 11, which has no such
// column, and that is a real false. Every other model leaves it false.
// See D199.
Include bool
// ColumnName, ColumnType, Storage and StatsTarget describe the column of
// the index itself, which is a column of its own in the catalog. For an
// expression such as lower(name) the name is lower and the type is the
// type of the expression, and for an operator class that stores another
// type, such as gin_trgm_ops, the type is the stored one. psql's \d+ of an
// index prints them. Storage is plain, main, external or extended, and
// StatsTarget is absent for the default. See D262.
ColumnName sql.Null[string]
ColumnType sql.Null[string]
Storage sql.Null[string]
StatsTarget sql.Null[int64]
// PrefixLength is the number of characters or bytes of the column that the index
// holds, for an index on a prefix such as name(10), and absent when the index
// holds the whole column. See D296.
PrefixLength sql.Null[int64]
}
IndexColumn is one column of an index, in index order.
type Info ¶
type Info struct {
// Embedded says the database is a library rather than a server.
//
// There is nothing to connect to over a network, nothing to start, no
// release to pin beyond whatever the driver links, and no user to be. Two
// are: SQLite and DuckDB.
//
// A consumer reads it to decide what is worth offering. There is no host
// to report, no server version separate from the driver's, and no second
// principal, so a command that asks about any of those has nothing to
// say. dbmeta branches on it nowhere itself: every query runs the same way
// against a library as against a server.
//
// Hard rule 1 normally sends a fact about a scheme to dburl, and
// dburl carries this one from v0.29.0: it marks file, sqlite3,
// moderncsqlite, csvq, duckdb and chai DeploymentEmbedded, which is the
// same statement about the same six schemes. It is still declared
// here, because dbmeta has no dependencies and never opens a connection,
// so a caller holding a Dialect has no URL to hand to dburl.
//
// The two do not even count the same objects. dburl counts schemes and
// marks three for the two products here, because SQLite has two drivers.
// dbmeta counts models and marks two. See D80.
Embedded bool
// Placeholder writes the bind parameter for position n, counting from 1.
// PostgreSQL writes $1, MySQL writes ?, Oracle writes :1 and SQL Server
// writes @p1. A product that numbers none ignores n. Every model sets it,
// including one that binds with [Info.Literal], because a client writes
// its own INSERT with it. [Dialect.Placeholder] is the accessor, and it
// also answers for a dialect with no model. See D230.
Placeholder func(n int) string
// Named says that the drivers take a named argument only, so that a
// value is bound by its name and never by its position. Under it, the
// parameter at position n is written $p1, $p2 and so on, and its value
// is passed as sql.Named("p1", v), so [Query.Build] still returns the
// values in order and database/sql carries the names. Placeholder is not
// called. False for every product but SurrealDB.
//
// SurrealQL has named parameters only, and $1 is a parse error. dbimp's
// surrealdb driver refuses a positional argument for that reason
// (dbimp D50). See D164.
Named bool
// Literal renders one parameter value as a SQL literal, for a product
// whose protocol cannot carry a parameter at all. Nil for every
// product that can bind, which is every one but Apache Hive, and a
// nil Literal is what says the dialect binds.
//
// This exists because HiveServer2 has no parameter channel. Its
// Thrift request carries a session handle, a statement, a
// configuration overlay, an asynchronous flag and a timeout, and
// nothing else, so no driver can bind and Hive's own JDBC
// PreparedStatement substitutes on the client. A dialect in that
// position either renders its values into the statement or answers
// nothing at all. See D78.
//
// It is deliberately not a general literal mode and it is not a
// switch. The dialect supplies the function, because escaping is per
// product knowledge and one shared rule is not enough: Hive does not
// accept a doubled quote the way [QuoteLiteral] writes one. It reads
// 'a”b' as two literals joined and returns ab, silently, so a
// doubled quote there is a wrong answer rather than an error.
//
// This is the same reasoning D56 used to let ChangePassword build a
// statement: the escaping is the product's and the value cannot be
// bound.
//
// What it renders is a parameter this project declared, never a
// statement. The statement is written here and no caller supplies
// one. A value still reaches it from outside, so an implementation
// refuses what it cannot render rather than guessing, and returns an
// error for a type it does not know and for a string it cannot
// escape safely.
Literal func(v any) (string, error)
// BindValue converts one parameter value before it is bound, for a
// product whose drivers cannot bind every type a parameter here takes.
// Nil for every product but Oracle, and a nil BindValue binds the value
// as it is.
//
// Oracle is the case because it has no boolean before 23ai, and
// go-ora/v3 refuses a Go bool with "no parameter coder registered for
// go type bool". The Oracle model compares with_system with 1, so it
// binds a bool as 1 or 0, which every go-ora release carries. usql found
// it on 2026-09-30. See D136.
BindValue func(v any) any
// VersionQuery reads the server version. An empty string means the database
// reports no version, and a caller uses an unknown version.
VersionQuery string
// VersionColumns is how many columns VersionQuery returns. Most return
// one. SQL Server returns five, and CockroachDB, CrateDB, SingleStore and
// Vitess return two.
VersionColumns int
// ParseVersion turns the columns of the first row into a version set and a
// display line.
ParseVersion func(cols []string) (VersionSet, error)
// FollowUpQuery returns a second version statement, and how many columns
// it returns, when what the first one found calls for it. It returns an
// empty statement when none is needed. Nil for every dialect but cassandra.
//
// It exists because two products share the cassandra dialect and only one
// table both have. ScyllaDB reports the Cassandra release it keeps
// compatible with in system.local, and keeps its own release in
// system.versions, which Cassandra does not have. The first statement
// finds ScyllaDB and this one reads its release. See D92.
FollowUpQuery func(s VersionSet) (query string, cols int)
// ParseFollowUp adds the columns of the follow-up row to the set the
// first statement produced.
ParseFollowUp func(s VersionSet, cols []string) (VersionSet, error)
// QuotingQuery reads the session state that decides how a string literal is
// escaped. Empty when the product has no such state. See D56.
QuotingQuery string
// QuotingColumns is how many columns QuotingQuery returns.
QuotingColumns int
// ParseQuoting turns those columns into the state.
ParseQuoting func(cols []string) (Quoting, error)
// ChangePassword builds the statement that sets a password. It returns
// text and never runs anything. Nil when the product has no such
// statement or the model builds none, as for every embedded database
// here.
ChangePassword func(c PasswordChange, q Quoting) (string, error)
// DescribeResult builds the statement that describes a query without
// running it. Nil when the product has none. See D273.
DescribeResult func(query string) (ResultDescription, error)
// TypeNames builds the statement that names the types a driver reports as
// numbers. Nil when the product has none. See D273.
TypeNames func(types []TypeRef) (string, error)
// OldPassword says ChangePassword needs PasswordChange.Old: the product
// refuses a user's own password change without the current one. SQL
// Server is the case. A caller asks for the old password when it is
// true. See D143.
OldPassword bool
// Syntax is the lexical forms the product's SQL has, for a client that
// splits text into statements. See D143.
Syntax Syntax
// Terminator says what the product does with a semicolon that ends a
// statement. The zero value keeps it. See D143.
Terminator Terminator
// Batches are the statements that open and close a batch, which a client
// sends as one statement with everything between them. See D143.
Batches []Batch
// Fold is what the product does to the case of a name that is not
// quoted. See [Dialect.FoldIdentifier] and D143.
Fold Fold
// Product is the text a client prints for the version of a product that
// has no statement that reads its version, such as "Amazon DynamoDB". Empty
// when the model has a VersionQuery. A dialect with no model has its
// text in a table in the root package, and [Dialect.Product] reads both.
// See D230.
Product string
// EveryStatementIsAQuery says that every statement of the language
// returns a result and the server sends no count, so a client runs each
// statement as a query and never as an exec. True for ArangoDB, Neo4j,
// SurrealDB, InfluxDB and InfluxQL. See D230.
EveryStatementIsAQuery bool
// WritesNeedAutocommit says that a write must not run inside a
// transaction. Trino and Presto start one on BEGIN and then refuse the
// write with AUTOCOMMIT_WRITE_CONFLICT, so a client writes each row on its
// own. Every other product is found by a BeginTx that fails with
// ErrNotSupported in the driver, and is not flagged. See D230.
WritesNeedAutocommit bool
// ScanTypes says that a client must scan each column into the Go type
// that the driver reports, where it otherwise scans into any, so that
// numbers align and times format. True for the MySQL family and for
// Databend. See D230.
ScanTypes bool
// ColumnAlign says on which side a client prints a column, from the type
// that a driver reports for it. Nil when the model records no alignment.
// Each model measured the type names of its drivers against a live server,
// and [RightAligned] builds the function. See D245.
ColumnAlign func(*sql.ColumnType) (Align, bool)
// IsBinary says whether a column holds binary data, from the type that a
// driver reports for it. Nil when the model records nothing. The driver
// scans more than binary types into bytes, such as the text columns of
// MySQL, so the name decides. [Dialect.FormatBinary] writes the value in
// one form for every dialect, and [BinaryNames] builds the function. See
// D258.
IsBinary func(*sql.ColumnType) bool
// SuperuserQuery reads whether the session user is a superuser, as one
// column that [Dialect.ParseSuperuser] reads. Empty when the product has no
// such user or the model measured none. A client shows it as the # of a
// prompt, and it is a read like the version query. See D309.
SuperuserQuery string
// VersionNum builds the one integer form of the version that the product
// reports, such as 180006 for PostgreSQL 18.6, from the version set that
// [Info.ParseVersion] returned. Nil when the product has no such form. See
// [PostgresVersionNum], [MySQLVersionNum] and D309.
VersionNum func(VersionSet) (int, bool)
// TimeKind says whether a column holds a date, a time or a timestamp, with
// or without a zone, from the type that a driver reports for it. Nil when
// the model records none. Each model measured the type names of its drivers
// against a live server, and [TimeKinds] builds the function. See D309.
TimeKind func(*sql.ColumnType) TimeKind
// Statements says what the statements of the product return, for
// [Dialect.Classify]. See D264.
Statements Statements
// IsGUID says whether a binary column holds a GUID, from the type that a
// driver reports for it. Nil when the model records none. [Dialect.FormatBinary]
// writes a value of 16 bytes in such a column as a UUID. Oracle has no UUID
// type and keeps a GUID in a RAW(16). See D263.
IsGUID func(*sql.ColumnType) bool
}
Info is what a model declares about its database.
type Inherit ¶ added in v0.9.0
type Inherit struct {
// Schema and Name name the child table. Type is its relation type.
Schema string
Name string
Type string
// ParentSchema and Parent name the table it inherits from.
ParentSchema string
Parent string
// Ordinal is the position of the parent among the parents of the child.
Ordinal int64
// Partition reports that the child is a partition of the parent. Releases
// below 10 have no partitions, and that is a real false.
Partition bool
// Visible and ParentVisible report that the child and the parent are on
// the search path of the session, so that psql prints their names with no
// schema. See D201.
Visible sql.Null[bool]
ParentVisible sql.Null[bool]
}
Inherit is one parent of a table by inheritance. psql prints the parents in Inherits and the children in Child tables of \d+ name.
A partition is in PostgreSQL's catalog as a child too. Partition says so, so that a caller can leave it out the way psql does.
type Language ¶
type Language struct {
Name string
Owner string
Trusted bool
Internal bool
Handler string
Validator string
Inline string
Access sql.Null[string]
Comment sql.Null[string]
}
Language is a procedural language. psql lists them with \dL.
type LargeObject ¶
LargeObject is a large object. psql lists them with \dl.
type MaterializedView ¶ added in v0.42.0
type MaterializedView struct {
Schema string
Name string
// Definition is the query of the view.
Definition sql.Null[string]
// Options are the clauses that follow the name in CREATE MATERIALIZED VIEW, such
// as BUILD IMMEDIATE REFRESH COMPLETE ON DEMAND. It is absent where the product
// has none.
Options sql.Null[string]
Comment sql.Null[string]
}
MaterializedView is a materialized view of a product that lists them apart from the tables. Oracle keeps the rows of one in a table of the same name, which the list of tables also holds.
type MaterializedViewLog ¶ added in v0.45.0
type MaterializedViewLog struct {
Schema string
// Master is the table that the log records.
Master string
// LogTable is the table that holds the log, which the log makes and drops.
LogTable string
// PrimaryKey, RowID, Sequence and ObjectID say what each entry holds besides
// the changed values.
PrimaryKey bool
RowID bool
Sequence bool
ObjectID bool
// IncludeNew says that an entry holds the new values of a changed row.
IncludeNew bool
// FilterColumns says that the log holds columns that a person named.
FilterColumns bool
// Columns are the columns that a person named, each quoted and joined by commas. It is
// absent when the log names none. See D299.
Columns sql.Null[string]
}
MaterializedViewLog is the log of the changes to a table, which a fast refresh of a materialized view reads. The product keeps it in a table of its own.
type Meta ¶
type Meta struct {
// contains filtered or unexported fields
}
Meta is what a caller holds. It names the dialect and the server version, and it decides which fragment of a query applies.
The caller builds it. dbmeta never detects a dialect and never detects a version. See D36.
func New ¶
func New(d Dialect, versions VersionSet) (*Meta, error)
New returns the Meta for a dialect at a version.
Pass the version the caller read with Dialect.VersionQuery, or any version the caller wants to force. Overriding matters for a proxy that hides the server, for a compatible product that reports a version it does not behave like, for a generator with no server at all, and for finding out whether a fault is a version gate.
An unknown version selects the newest fragment of every piece, which is what D21 requires above the ceiling.
func Open ¶
Open reads the version of the server behind db and returns the metadata for it, which is Version followed by New. If the version cannot be read, Open returns the error and no Meta. A caller that wants to go on without a version calls New with an empty VersionSet, which takes the newest fragments, and decides that for itself, because on an old server those statements can be wrong.
func (*Meta) String ¶
String satisfies the fmt.Stringer interface. It returns the line to show a person, such as "PostgreSQL 16.2", which is what usql prints for \conninfo and in its prompt.
func (*Meta) Version ¶
func (m *Meta) Version() VersionSet
Version returns the version set m was built with. Call VersionSet.Main for the one number most callers want.
The two accessors mirror the arguments of New, so there is nothing to remember about their names.
type NotNull ¶ added in v0.9.0
type NotNull struct {
Schema string
Table string
Name string
Column string
// NoInherit reports NO INHERIT.
NoInherit bool
// Local reports that the constraint was written on this table, and not
// only inherited.
Local bool
// Inherited reports that a parent table also holds it.
Inherited bool
// Validated is false for a constraint that was added NOT VALID.
Validated bool
}
NotNull is a NOT NULL constraint that has a name, which PostgreSQL 18 records in pg_constraint. psql 18 prints them in Not-null constraints of \d+ name. Constraints does not hold them, and Column.Nullable still answers on every release. See D49 and D199.
type Operator ¶
type Operator struct {
Schema string
Name string
LeftType string
RightType string
ResultType string
Function sql.Null[string]
Comment sql.Null[string]
// Leakproof reports that the function behind the operator is leakproof.
// It is false for an operator with no function. See D201.
Leakproof bool
}
Operator is an operator. psql lists them with \do.
type OperatorClass ¶
type OperatorClass struct {
AccessMethod string
Schema string
Name string
InputType string
Default bool
Family string
Owner string
// StorageType is the type the index stores, where it differs from the
// input type, as psql's \dAc+ prints it. See D147.
StorageType sql.Null[string]
// Visible and FamilyVisible report that the class and its family are on
// the search path of the session, so that psql prints their names with no
// schema. FamilySchema is the schema of Family. See D201.
Visible sql.Null[bool]
FamilyVisible sql.Null[bool]
FamilySchema string
}
OperatorClass tells an access method how to index a type. psql lists them with \dAc.
type OperatorFamily ¶
type OperatorFamily struct {
AccessMethod string
Schema string
Name string
Owner string
// AppliesTo is the input types of the family's operator classes, joined
// by commas, as psql's \dAf prints them. See D147.
AppliesTo sql.Null[string]
// Visible reports that the family is on the search path of the session,
// so that psql prints its name with no schema. See D201.
Visible sql.Null[bool]
}
OperatorFamily groups operator classes. psql lists them with \dAf.
type OperatorFamilyFunction ¶
type OperatorFamilyFunction struct {
AccessMethod string
Family string
LeftType string
RightType string
Number int64
Function string
// FunctionName is the function with no argument types, as psql's \dAp
// prints it. Function is the form with them, which \dAp+ prints. See
// D201.
FunctionName string
// Visible reports that the family is on the search path of the session.
// FamilySchema is the schema of Family. See D201.
Visible sql.Null[bool]
FamilySchema string
}
OperatorFamilyFunction is one support function of a family. psql lists them with \dAp.
type OperatorFamilyOperator ¶
type OperatorFamilyOperator struct {
AccessMethod string
Family string
Operator string
Strategy int64
Purpose string
// LeftType and RightType are the registered types, which with Strategy
// name one operator of the family, and by which psql orders the rows.
LeftType string
RightType string
// SortFamily is the operator family an ordering operator sorts by, and
// absent for a search operator. Leakproof reports that the function of the
// operator is leakproof. psql's \dAo+ prints both. See D201.
SortFamily sql.Null[string]
Leakproof bool
// Visible reports that the family is on the search path of the session,
// so that psql prints its name with no schema. FamilySchema is the schema
// of Family. See D201.
Visible sql.Null[bool]
FamilySchema string
}
OperatorFamilyOperator is one operator of a family. psql lists them with \dAo.
type Param ¶
type Param struct {
Name string
Desc string
// Default is used when the caller supplies no value. A parameter with a
// nil Default is required, and leaving it out is an error.
//
// Most metadata parameters narrow a result and mean "every one" when they
// are empty, so most declare a default. That is not the same as ignoring
// an unknown name, which is always an error: a caller that misspells a
// parameter is told, rather than silently getting an unfiltered result.
Default any
}
Param is a query parameter that a query declares. The name is what appears in the SQL after an at sign, so a parameter named schema is written @schema.
func TypesParam ¶
func TypesParam() Param
TypesParam is the parameter that narrows Tables to the kinds of relation named, by Table.Type. Every model's Tables takes it. See D138.
type Partition ¶ added in v0.9.0
type Partition struct {
// Schema and Table name the parent. PartitionSchema and Partition name the
// partition.
Schema string
Table string
PartitionSchema string
Partition string
// Type is the relation type of the partition, as Table.Type spells it. A
// partitioned table and a foreign table are partitions too.
Type string
// Bound is what follows FOR VALUES, or DEFAULT, as pg_get_expr writes it.
Bound sql.Null[string]
// Constraint is the implicit constraint the partition bound makes, as
// pg_get_partition_constraintdef writes it.
Constraint sql.Null[string]
// Partitioned reports that the partition has partitions of its own.
Partitioned bool
// DetachPending reports a DETACH CONCURRENTLY that has not finished.
// Releases below 14 have none, and that is a real false.
DetachPending bool
// TableVisible and PartitionVisible report that the parent and the
// partition are on the search path of the session, so that psql prints
// their names with no schema. See D201.
TableVisible sql.Null[bool]
PartitionVisible sql.Null[bool]
// Generated says that the server made the partition for an interval, and a person
// did not, so a script does not write it. It is absent where the product makes none.
// See D297.
Generated sql.Null[bool]
}
Partition is one partition of a partitioned table. psql prints it in the Partitions list of \d+ name, and in Partition of for the partition itself.
It is one row for each partition, so a partitioned table of many partitions is many rows. A caller that wants the partitions of one table passes the table as Parent. A partition that is itself partitioned is a row of its own where it is the parent. See D199.
type PartitionFunction ¶ added in v0.45.0
type PartitionFunction struct {
Name string
// DataType is the type of the column that the function takes, as declared.
DataType string
// Range is left or right, which side of a boundary value holds the value.
Range string
// Boundaries are the boundary values as literals, joined by a comma and a space,
// in order, and empty for a function that has one partition.
Boundaries string
}
PartitionFunction says how the values of a column map to partitions. SQL Server keeps it in the database, apart from the tables that use it.
type PartitionScheme ¶ added in v0.45.0
type PartitionScheme struct {
Name string
// Function is the name of the partition function of the scheme.
Function string
// Filegroups are the filegroups of the partitions, in order, joined by a comma
// and a space.
Filegroups string
}
PartitionScheme puts the partitions of a function on storage. SQL Server keeps it in the database, apart from the tables that use it.
type PartitionedTable ¶
type PartitionedTable struct {
Schema string
Name string
Owner string
Type string
Parent string
Strategy string
Expression string
Comment sql.Null[string]
// Table is the table a partitioned index is on, and absent for a table.
// AccessMethod is the access method of the index, and absent for a table
// on a release below 12. See D199.
Table sql.Null[string]
AccessMethod sql.Null[string]
// DirectSize is the bytes that the partitions one level below take, and
// TotalSize the bytes that every partition below takes, both as
// pg_table_size counts them. They are absent below release 12, which has
// no pg_partition_tree. See D199.
DirectSize sql.Null[int64]
TotalSize sql.Null[int64]
// ParentVisible and TableVisible report that the parent, and the table of
// a partitioned index, are on the search path of the session, so that
// psql prints their names with no schema. See D201.
ParentVisible sql.Null[bool]
TableVisible sql.Null[bool]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
// KeyColumns are the columns that the partition scheme of a table is given, for
// a product that partitions by a scheme, and absent otherwise. See D296.
KeyColumns sql.Null[string]
// Interval is the expression of an interval partitioned table, which makes a
// partition when a row needs one, and absent for any other. Reference is the name
// of the foreign key that a table of reference partitioning takes its partitions
// from. SubStrategy and SubKeyColumns say how each partition is split again, and
// SubpartitionTemplates lists the subpartitions of the template. All four are absent
// for a table that has none. See D297.
Interval sql.Null[string]
Reference sql.Null[string]
SubStrategy sql.Null[string]
SubKeyColumns sql.Null[string]
}
PartitionedTable is a table split into partitions. psql lists them with \dP.
type PasswordChange ¶
type PasswordChange struct {
// User is the role, user or login whose password changes.
User string
// Password is the new password.
Password string
// Old is the current password. SQL Server and Oracle can require it and
// every other product ignores it.
Old string
}
PasswordChange is a request to set a password.
type Policy ¶ added in v0.9.0
type Policy struct {
Schema string
Table string
Name string
// Command is all, select, insert, update or delete.
Command string
// Permissive is false for a restrictive policy. A release below 10 has
// only permissive policies, and that is a real true.
Permissive bool
// Roles are the roles the policy applies to, joined by a comma, and absent
// for public.
Roles sql.Null[string]
// Using and WithCheck are the expressions, as pg_get_expr writes them, and
// absent when the policy has none.
Using sql.Null[string]
WithCheck sql.Null[string]
Comment sql.Null[string]
// Enabled reports that the policy is switched on. SQL Server, Oracle and
// Vertica can switch one policy off and keep it, and a policy that is off
// restricts nothing. Absent where the product has no switch for one
// policy. PostgreSQL switches row security for a whole table, which is
// Table.RowSecurity, so a PostgreSQL policy is always active and this is
// absent. See D211.
Enabled sql.Null[bool]
// PolicySchema is the schema that holds the policy, where it is not the schema
// of the table, as in SQL Server. It is absent where the policy belongs to its
// table. See D296.
PolicySchema sql.Null[string]
}
Policy is a row level security policy. psql prints them in Policies of \d+ name.
type Privilege ¶
type Privilege struct {
Schema sql.Null[string]
Name string
Type string
Access sql.Null[string]
ColumnAccess sql.Null[string]
Policies sql.Null[string]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
}
Privilege is the grants on one object. psql lists them with \z and \dp.
type Publication ¶
type Publication struct {
Name string
Owner string
AllTables bool
Insert bool
Update bool
Delete bool
Truncate bool
ViaRoot bool
Comment sql.Null[string]
// GeneratedColumns is none or stored, which says whether the publication
// sends generated columns. It is none below release 18, which cannot send them.
// See D201.
GeneratedColumns sql.Null[string]
}
Publication is a set of changes offered for replication. psql lists them with \dRp.
type PublicationTable ¶
type PublicationTable struct {
Publication string
Schema string
Name string
Columns string
Where sql.Null[string]
// Via says how the table is in the publication: table when the
// publication names it, schema when it names the schema of the table, and
// all tables when it names every table. Only table is read unless the
// caller asks for the others. See D199.
Via sql.Null[string]
}
PublicationTable is one table a publication offers. psql shows them with \dRp+.
type Query ¶
type Query[T any] struct { // contains filtered or unexported fields }
Query is one kind of metadata object, such as a table or a column.
There is one exported Query value per object kind, and a model registers what its dialect provides for it. A caller names the object by its value, so the result type is inferred and an unknown type cannot be asked for.
func NewQuery ¶
NewQuery returns a query for one kind of object. The root package declares one value per kind. A model does not call this.
func (*Query[T]) All ¶
func (q *Query[T]) All(ctx context.Context, m *Meta, db Queryer, args map[string]any) iter.Seq2[T, error]
All runs the query against db and yields one value per row.
The iterator holds a database connection until it ends. Stopping early, with break or by returning false from the yield, releases it, and so does canceling ctx. Do not open a second iterator inside the body of the first: that needs a second connection and deadlocks on a pool of one. Ask for every row you want in one call and filter in the loop.
func (*Query[T]) Build ¶
Build returns the statement for m with its placeholders written the way the dialect wants them, and the argument values in matching order.
The caller can run it itself. An argument named in the statement and missing from args is an error, and an argument in args that the statement does not name is an error. Neither is ignored.
func (*Query[T]) Each ¶
Each runs the query with args, as All does, and passes only the arguments the query takes. All refuses an argument the query does not take, which catches a misspelled name in a map. A caller that asks every kind of object with one set of arguments, such as a describe command, a completer or a code generator, sets the fields once in an Args and calls Each.
A query that the model does not answer yields ErrNotSupported, and one that no model was built for yields ErrModelNotBuilt, as All does.
func (*Query[T]) Fields ¶
Fields returns the result columns for m, in order.
Read Field.Present to tell a field the server is too old to have from a value that is genuinely null. Both arrive as NULL under the padding rule.
func (*Query[T]) Register ¶
Register records what a dialect provides for this query. A model package calls it from its init. Registering twice for one dialect panics, because it is a build mistake.
func (*Query[T]) Share ¶
Share registers for the dialect to the binding that the dialect from registered, and reports whether from had one. A model for a product that speaks another product's protocol, and whose catalog imitates that product's, answers with the other product's statement where the statement answers. It registers a binding of its own, with Query.Register, where the statement does not answer. CockroachDB shares most of PostgreSQL's statements this way. See D123.
It panics when to already has a binding, as Register does. A model shares from its init, after the model it shares from has registered, which its import of that model guarantees.
type Queryer ¶
type Queryer interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
Queryer runs a query. It is the whole of what dbmeta asks a database to do.
The name follows Go's own: database/sql/driver names the same method on database/sql/driver.QueryerContext. It was Querier until D121.
database/sql.DB, database/sql.Tx and database/sql.Conn all satisfy it. database/sql.Stmt does not, because its QueryContext takes no statement.
Pass a database/sql.Tx to read more than one catalog in one snapshot. Two calls against a database/sql.DB are two statements, and the database can change between them.
One method, on purpose ¶
This is the interface rather than database/sql.DB so that the type system states what the library does. dbmeta reads. It never writes, never prepares a statement, and never runs anything without a context, and a reader establishes that from this declaration rather than by searching the implementation.
It had four methods until D49. Two were never called, and one of those was ExecContext, so the interface of a read only library advertised the one operation hard rule 8 forbids it from performing.
It is not a seam for a mock ¶
A fake cannot satisfy this. database/sql.Rows is a struct with unexported fields that only database/sql builds, from a registered driver, so nothing outside that package can return one.
Test against a fake driver instead, registered with database/sql.Register. That is what dbmeta does: see examplefake_test.go, which replays recorded rows and needs no database. The driver interface is the seam Go provides, and it is a smaller thing to implement than it looks.
type Quoting ¶
type Quoting struct {
// BackslashEscapes reports whether a backslash escapes the next character
// inside a string literal.
//
// It is sql_mode not containing NO_BACKSLASH_ESCAPES on MySQL and MariaDB,
// and standard_conforming_strings being off on Vertica. SQL Server has
// no such setting and leaves this absent.
BackslashEscapes sql.Null[bool]
}
Quoting is the session state that decides how a string literal is escaped.
A field is absent when the caller has not read it. A product that needs a field and does not get it returns ErrQuotingUnknown, because the safe default is different per product and guessing is how the demonstration above happens.
type ResultDescription ¶ added in v0.36.0
type ResultDescription struct {
// Stmt is the statement to run. It does not run the query it describes.
Stmt string
// Name is the column of the rows that holds the name of a result column.
// The value is NULL for a column that has no name.
Name string
// Type is the column of the rows that holds the SQL name of its type, such
// as varchar(10).
Type string
}
ResultDescription is a statement that describes the columns of a query, and the names of the columns of the rows it returns.
type Returning ¶ added in v0.31.0
type Returning int
Returning is how the INSERT, UPDATE, DELETE and MERGE statements of a product give back the rows that they changed. See D264.
const ( // ReturningNone is a product with no such clause, or one whose clause // puts the rows in variables, as Oracle's RETURNING INTO does. The // statement returns no rows. ReturningNone Returning = iota // ReturningRows is a RETURNING clause that sends the rows to the client. // PostgreSQL, CockroachDB, SQLite, DuckDB, MariaDB and Firebird have it. ReturningRows // ReturningOutput is the OUTPUT clause of SQL Server. It sends the rows to // the client unless it has an INTO. ReturningOutput // ReturningThenReturn is the THEN RETURN clause of Spanner. ReturningThenReturn )
Returning values.
type Role ¶
type Role struct {
Name string
Superuser bool
CreateRole bool
CreateDB bool
CanLogin bool
Replication bool
BypassRLS bool
Inherit bool
ConnLimit int64
ValidUntil sql.Null[string]
MemberOf string
Comment sql.Null[string]
}
Role is a database role. psql lists them with \du and \dg.
type RoleGrant ¶
type RoleGrant struct {
Role string
MemberOf string
Grantor sql.Null[string]
Admin bool
Inherit bool
Set bool
}
RoleGrant is one role's membership of another. psql lists them with \drg.
type RoleSetting ¶
type RoleSetting struct {
Role sql.Null[string]
Database sql.Null[string]
Settings sql.Null[string]
}
RoleSetting is a configuration value set for a role, optionally in one database. psql lists them with \drds.
type RoutineParameter ¶
type RoutineParameter struct {
Catalog string
Schema string
Routine string
RoutineID sql.Null[string]
Name sql.Null[string]
Ordinal int64
// Mode is in, out, inout, variadic or table for a column of a returned
// table. A return value reports mode return and ordinal zero where the
// database records one.
Mode string
DataType string
Default sql.Null[string]
}
RoutineParameter is one parameter of a function or a procedure, in declaration order.
It is durable. Function.ArgTypes still holds the signature psql prints, and this is the same fact in parts.
Group by Routine and, where the database overloads a name, by RoutineID. PostgreSQL allows two functions with one name and different parameters, so the name alone does not identify one.
type Rule ¶ added in v0.9.0
type Rule struct {
Schema string
Table string
Name string
// Event is select, update, insert or delete.
Event string
// Enabled is enabled, disabled, replica or always.
Enabled string
// Instead reports INSTEAD and not ALSO.
Instead bool
// Definition is the CREATE RULE statement, as pg_get_ruledef writes it,
// without the final semicolon.
Definition string
Comment sql.Null[string]
}
Rule is a rewrite rule of a table. psql prints them in Rules of \d+ name.
The rule that makes a view is not here. It is named _RETURN and View holds its definition.
type Schema ¶
type Schema struct {
Catalog string
Name string
Owner string
Comment sql.Null[string]
// Access is the access privileges of the schema, one per line, as psql's
// \dn+ prints them. It is absent when the privileges are the default.
// See D201.
Access sql.Null[string]
// Options are the options set on the schema, as name=value pairs that a
// comma and a space separate, such as the default expiration of a table
// in a BigQuery dataset. The description is the comment and is not here.
// It is absent where the product has none.
Options sql.Null[string]
}
Schema is a namespace within a catalog.
type Sequence ¶
type Sequence struct {
Schema string
Name string
DataType sql.Null[string]
Start sql.Null[string]
Minimum sql.Null[string]
Maximum sql.Null[string]
Increment sql.Null[string]
Cycles sql.Null[bool]
OwnedBy string
Comment sql.Null[string]
// CacheSize is the number of values a session takes at once. It is absent
// below release 10, as the bounds are. See D201.
CacheSize sql.Null[int64]
// Identity says that the sequence belongs to an identity column and not to
// a column that has a serial default. psql prints a different footer for
// each. It is absent when no column owns the sequence. See D262.
Identity sql.Null[bool]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
// LastValue is the last value that the sequence gave, as text, and absent when
// it gave none or the product does not say. A dump sets the next value from it.
// See D296.
LastValue sql.Null[string]
}
Sequence generates numbers. psql lists them with \ds and shows the detail inside \d name.
Start, Minimum, Maximum and Increment are decimal text, because an Oracle sequence is bounded by 28 digits and an int64 holds 19. The default maximum of an Oracle sequence is 9999999999999999999999999999.
type Setting ¶
type Setting struct {
Name string
Value sql.Null[string]
Type sql.Null[string]
Context sql.Null[string]
Access sql.Null[string]
// Display is the value as the server shows it, with its unit, such as
// 128MB where Value holds 16384. psql's \dconfig prints it. See D147.
Display sql.Null[string]
// Source says where the value came from, such as default, configuration
// file, environment variable or override, as pg_settings.source says it.
// See D262.
Source sql.Null[string]
// Boot is the value the server starts with when nothing sets it, as
// pg_settings.boot_val says it, and it is written the way Value is. psql's
// \dconfig with no pattern lists the settings whose source is not default
// and whose Value is not their Boot. See D262.
Boot sql.Null[string]
}
Setting is a configuration parameter. psql lists them with \dconfig.
type SourceLine ¶ added in v0.42.0
type SourceLine struct {
Schema string
// Name is the name of the object.
Name string
// Type is the kind of the object in lower case, such as function, procedure,
// package, package body, type, type body or trigger.
Type string
// Line is the number of the line, from 1.
Line int64
// Text is the line, with its line break.
Text string
}
SourceLine is one line of the source text of a stored object. The lines of one object, in order of Line, join to the text that follows CREATE OR REPLACE.
It is durable. It is a separate kind rather than a field on Function, because an object has many lines and a child of an object is its own kind with flat rows (D47). Oracle keeps its source this way, and has no other form of it that every user can read.
type Statements ¶ added in v0.31.0
type Statements struct {
// Returning says how a statement gives back the rows that it changed.
Returning Returning
// SetListsSettings says that SET with nothing after it, or with ALL or -v,
// lists the settings. True for Impala and Hive.
SetListsSettings bool
// ExecuteReturnsRows says that EXECUTE runs a procedure and returns its
// rows, as EXEC does. True for SQL Server. In every other product EXECUTE
// runs a prepared statement and returns no rows.
ExecuteReturnsRows bool
// CopyFromStdin says that COPY table FROM STDIN reads its rows from the
// client, which sends them after the statement. True for PostgreSQL and
// CockroachDB. See [Dialect.CopyFromStdin] and D307.
CopyFromStdin bool
}
Statements is what a product's statements return, which a client needs to choose between a query and an exec. See Dialect.Classify and D264.
type Stmt ¶
type Stmt []Choice
Stmt is the pieces of one statement, in order. Each piece resolves on its own, so a statement is assembled rather than chosen.
type Subpartition ¶ added in v0.46.0
type Subpartition struct {
Schema string
Table string
Partition string
Name string
// Position is the order of the subpartitions in the partition, from one.
Position int64
// Bound is the upper bound of a range subpartition, the values of a list one, and
// absent for a hash one.
Bound sql.Null[string]
}
Subpartition is one part of a partition that is split again.
type SubpartitionTemplate ¶ added in v0.46.0
type SubpartitionTemplate struct {
Schema string
Table string
Name string
// Position is the order of the subpartitions in the template, from one.
Position int64
// Bound is the upper bound of a range subpartition, the values of a list one, and
// absent for a hash one.
Bound sql.Null[string]
}
SubpartitionTemplate is a subpartition that a partitioned table gives each of its partitions.
type Subscription ¶
type Subscription struct {
Name string
Owner string
Enabled bool
Publications string
Synchronous sql.Null[string]
Slot sql.Null[string]
Comment sql.Null[string]
// The columns below are the ones psql's \dRs+ adds. Each is absent on a
// release that has no such property, because a subscription of that
// release did not choose. Binary arrives in release 14, DisableOnError,
// TwoPhase and SkipLSN in 15, Origin, PasswordRequired and RunAsOwner in
// 16, and Failover in 17. Streaming arrives in 14 as on or off and in 16
// as on, off or parallel. TwoPhase is disabled, pending or enabled. See
// D201.
Binary sql.Null[bool]
Streaming sql.Null[string]
TwoPhase sql.Null[string]
DisableOnError sql.Null[bool]
Origin sql.Null[string]
PasswordRequired sql.Null[bool]
RunAsOwner sql.Null[bool]
Failover sql.Null[bool]
SkipLSN sql.Null[string]
}
Subscription receives changes from a publication. psql lists them with \dRs.
type SubscriptionConnection ¶ added in v0.9.0
SubscriptionConnection is the connection string of a subscription, which psql's \dRs+ prints in Conninfo. It is a kind of its own because only a superuser can read the column, and a statement that names it is refused for every other role. Subscription is refused with it. See D201.
type Support ¶
type Support int
Support says whether this query can be asked of m.
const ( // NotBuilt means no model for the dialect is in this binary. It says // nothing about the database. NotBuilt Support = iota // NotSupported means the model is present and the database has no such // object. NotSupported // Supported means the query can be asked. Supported // TooOld means the model is present and the product has the object, and // this release of it does not. [Query.Build] returns [ErrVersionTooOld]. // // It is last rather than in order of how supported each one is, so that // the three values that existed before it keep their numbers. A caller // compares these by equality and never by rank. See D54. TooOld )
Support values.
func (Support) String ¶
String satisfies the fmt.Stringer interface.
type Synonym ¶ added in v0.42.0
type Synonym struct {
Schema string
Name string
// TargetSchema and Target name the object. TargetDatabase and TargetServer are
// absent for an object of the same database and server. For Oracle a database
// link is the server.
TargetSchema sql.Null[string]
Target string
TargetDatabase sql.Null[string]
TargetServer sql.Null[string]
}
Synonym is another name for an object. The name is in a schema, and it points at an object that need not exist, in the same database or in another one.
type Syntax ¶
type Syntax struct {
// DollarQuotes is a string between $$ and $$, or between $tag$ and $tag$.
DollarQuotes bool
// BlockComments is a comment between /* and */.
BlockComments bool
// SlashComments is a comment from // to the end of the line.
SlashComments bool
// HashComments is a comment from # to the end of the line.
HashComments bool
// Backticks is a name between backticks.
Backticks bool
// Brackets is a name between square brackets, as SQL Server and SQLite
// write one. See D264.
Brackets bool
// BackslashEscapes says that a backslash in a string between single or
// double quotes escapes the next character, so `'it\'s'` is one string.
// The MySQL family reads one. PostgreSQL and the others read a backslash
// as an ordinary character, and a client that reads it as an escape
// joins two strings or cuts one. See D266.
BackslashEscapes bool
// DashComments is a comment from two dashes to the end of the line. Every
// SQL product reads one. Cypher does not: `(a)--(b)` is a relationship and
// `5--3` is 8, so a client that reads two dashes as a comment cuts the
// statement there. See D261.
DashComments bool
// BeginEndBlocks says that the body of a stored program can sit between
// BEGIN and END with no quotes around it, and hold semicolons that do
// not end the statement. A CREATE of a PROCEDURE, FUNCTION, TRIGGER or
// EVENT is the case, and a client that splits at each semicolon cuts the
// body into pieces that the server refuses. A transaction is not such a body.
// A client keeps splitting `BEGIN; ...; END;`.
// False for a product that quotes the body, as PostgreSQL does with
// dollar quotes, and for one with no stored programs. See D249.
BeginEndBlocks bool
// AnonymousBlocks says that a statement which starts with BEGIN or
// DECLARE is a block of code that the server runs, and a client must keep
// it whole to its last END. Oracle is the case. The block ends at the
// semicolon after its last END.
// False where a bare BEGIN starts a transaction, and where DECLARE is a
// statement of its own, as in SQL Server. See D252.
AnonymousBlocks bool
}
Syntax is the lexical forms a product's SQL has. A client that splits text into statements reads it to know which characters open a string, a comment or a quoted name, so that a semicolon inside one does not end the statement. usql's lexer took these per driver, and they are the product's grammar, the same for every driver of it. See D143.
type Table ¶
type Table struct {
Catalog string
Schema string
Name string
Type string
Comment sql.Null[string]
// Owner is the role that owns the relation. It is absent where the
// product has no owner of a relation. See D198.
Owner sql.Null[string]
// Persistence is permanent, unlogged or temporary, as psql's \dt+ says
// it. It is absent where the product has no such choice. See D198.
Persistence sql.Null[string]
// AccessMethod is the table access method, such as heap, and absent for
// a relation that has none, such as a view, or on a server that records
// none. PostgreSQL has it from release 12. See D198.
AccessMethod sql.Null[string]
// Size is the bytes the relation takes on disk, as pg_table_size counts
// them: the main data, the free space map, the visibility map and the
// TOAST table, and not the indexes. It is a number and not the text psql
// prints, because a caller can format a number and cannot add up text.
// A view and a foreign table have no file here, so PostgreSQL answers 0
// for them. It is absent where the relation was dropped while the
// statement ran, and where the product keeps no size. See D198.
Size sql.Null[int64]
// Rows is the planner's estimate of the rows, which is the number
// ANALYZE and VACUUM last stored. It is not a count. PostgreSQL before
// release 14 stores 0 for a relation that was never analyzed, and from
// 14 stores -1, so that 0 means an empty relation. See D198.
Rows sql.Null[int64]
// Options are the storage parameters set on the relation, such as
// fillfactor=70 or security_barrier=true, joined by a comma and a space.
// PostgreSQL adds the parameters of the TOAST table with a prefix of
// toast, as psql does. It is absent when none is set. See D199.
Options sql.Null[string]
// RowSecurity reports whether row level security is on for the table.
// It is absent where the product has none. See D199.
RowSecurity sql.Null[bool]
// RowSecurityForced reports whether row level security also applies to
// the owner of the table. See D199.
RowSecurityForced sql.Null[bool]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
// Extension is the extension that owns the object, and absent for an object
// that no extension owns. A dump leaves such an object out and writes CREATE
// EXTENSION instead, because the extension makes it again. It is absent where
// the product has no extensions.
Extension sql.Null[string]
// HistorySchema and HistoryTable name the history table of a system versioned
// table, which is where the server keeps the rows that an update or a delete
// replaced. Both are absent for any other table, and for a product that has
// none. The history table is a table of its own in the same listing. A dump
// writes it first and turns versioning on after the rows are loaded.
HistorySchema sql.Null[string]
HistoryTable sql.Null[string]
// Definition is the statement that makes the table, as the product keeps it,
// and absent where the product keeps none. SQLite keeps the text of CREATE
// TABLE, with the clauses that no catalog lists, such as STRICT and WITHOUT
// ROWID. See D293.
Definition sql.Null[string]
// OfType is the object type that the table is made of, for an object table
// of Oracle, as schema.type. It is absent for any other table. See D294.
OfType sql.Null[string]
// Collation is the default collation of the columns of the table, for a product
// that sets one for each table. It is absent where it has none. See D296.
Collation sql.Null[string]
}
Table is a table, a view, a materialized view or a sequence.
type Tablespace ¶
type Tablespace struct {
Name string
Owner sql.Null[string]
Location sql.Null[string]
Options sql.Null[string]
Size sql.Null[string]
Access sql.Null[string]
Comment sql.Null[string]
}
Tablespace is a location the server stores data in. psql lists them with \db.
type Terminator ¶
type Terminator int
Terminator is what a product does with a semicolon that ends a statement.
const ( // TerminatorKept is a product that takes the semicolon, which is most. TerminatorKept Terminator = iota // TerminatorStripped is a product that refuses a semicolon at the end of // a statement, such as Trino and Presto, so a client removes it. TerminatorStripped // TerminatorStrippedUnlessEnd is Oracle, which refuses the semicolon at // the end of a statement and needs it at the end of a PL/SQL block, so a // client removes it unless the statement ends with `END;` or with `END` and // the name of the unit, as `END payroll;` does. TerminatorStrippedUnlessEnd // TerminatorRequired is a product that refuses a statement that does not // end with a semicolon, such as MaxCompute, so a client adds one when the // statement has none. A statement of dbmeta already ends with one. See D237. TerminatorRequired )
Terminator values.
type TextSearchConfig ¶
type TextSearchConfig struct {
Schema string
Name string
Parser string
Comment sql.Null[string]
// ParserSchema is the schema of Parser. psql's \dF+ prints the two
// joined, such as pg_catalog.default. See D147.
ParserSchema sql.Null[string]
}
TextSearchConfig ties a parser to dictionaries. psql lists them with \dF.
type TextSearchConfigMap ¶
type TextSearchConfigMap struct {
Schema string
Config string
Token string
Position int64
DictionarySchema string
Dictionary string
}
TextSearchConfigMap is one dictionary that a configuration consults for one kind of token. A configuration consults the dictionaries for a token in the order of Position, and psql's \dF+ joins them into one line. See D147.
type TextSearchDictionary ¶
type TextSearchDictionary struct {
Schema string
Name string
Template string
Options sql.Null[string]
Comment sql.Null[string]
// TemplateSchema is the schema of Template. psql's \dFd+ prints the two
// joined, such as pg_catalog.simple. See D201.
TemplateSchema sql.Null[string]
}
TextSearchDictionary normalizes tokens. psql lists them with \dFd.
type TextSearchParser ¶
TextSearchParser splits text into tokens. psql lists them with \dFp.
type TextSearchParserFunction ¶ added in v0.9.0
type TextSearchParserFunction struct {
Schema string
Parser string
Method string
Ordinal int64
Function string
Comment sql.Null[string]
}
TextSearchParserFunction is one of the five functions of a text search parser, which psql's \dFp+ prints as Method and Function. Method is start, token, end, headline or lextype, in the order psql prints them. Function is the name as regproc writes it, and Comment the comment on the function. See D201.
type TextSearchParserTokenType ¶ added in v0.29.0
type TextSearchParserTokenType struct {
Schema string
Parser string
ID int64
Alias string
Description string
}
TextSearchParserTokenType is a kind of token that a text search parser returns, such as asciiword or email. psql prints them under a parser with \dFp+. See D262.
type TextSearchTemplate ¶
type TextSearchTemplate struct {
Schema string
Name string
Init sql.Null[string]
Lexize string
Comment sql.Null[string]
}
TextSearchTemplate is the code behind a dictionary. psql lists them with \dFt.
type TimeKind ¶ added in v0.52.0
type TimeKind uint8
TimeKind says what a column holds when it holds a date or a time. A client prints each kind in one form for every dialect, as psql prints it, and the driver reports the same value as a time.Time for all of them.
const ( // TimeDate is a date with no time, such as 2026-11-29. TimeDate TimeKind = iota + 1 // TimeOfDay is a time with no date and no zone, such as 14:48:35. TimeOfDay // TimeOfDayZone is a time with no date and a zone offset. TimeOfDayZone // TimeStamp is a date and a time with no zone, such as 2026-11-29 14:48:35. TimeStamp // TimeStampZone is a date and a time that name one instant, which a client // shows in the zone of its session with the offset. TimeStampZone )
The kinds. The zero value is none, which Dialect.TimeKind returns for a column that is not one of the five, and for a dialect that records nothing.
func (TimeKind) String ¶ added in v0.52.0
String satisfies fmt.Stringer.
type Trigger ¶
type Trigger struct {
Schema string
Table string
Name string
Enabled string
Definition string
Comment sql.Null[string]
// ActionOrder is the position of the trigger among those of the same table,
// event and timing, from one, for a product that orders them. See D296.
ActionOrder sql.Null[int64]
// SQLMode is the sql_mode that the trigger was made under, which MySQL and
// MariaDB keep with it.
SQLMode sql.Null[string]
// Placement says which events the trigger is first or last for, as text such as
// first INSERT, last UPDATE, for a product that lets a person place a trigger
// among those of the same event. It is absent when none is placed. See D296.
Placement sql.Null[string]
// Definer is the account that the trigger runs as, as user@host, for a product
// that keeps one. It is absent otherwise. See D297.
Definer sql.Null[string]
}
Trigger fires on a change to a table. psql shows them inside \d name.
type Type ¶
type Type struct {
Catalog string
Schema string
Name string
Internal string
Kind string
Elements string
Owner sql.Null[string]
Access sql.Null[string]
Comment sql.Null[string]
// Size is the internal length of a value in bytes, var for a type whose
// values vary in length, and tuple for a composite type, as psql's \dT+
// prints it. See D147.
Size sql.Null[string]
// Visible says whether the object is on the search path of the session,
// which is what psql tests with pg_table_is_visible and its relatives.
// psql lists only visible objects when a pattern has no schema, and lists
// every object when it has one. It is absent where the product has no
// search path. See D262.
Visible sql.Null[bool]
// Extension is the extension that owns the object, and absent for an object
// that no extension owns. A dump leaves such an object out and writes CREATE
// EXTENSION instead, because the extension makes it again. It is absent where
// the product has no extensions.
Extension sql.Null[string]
// RangeSubtype is the type of the bounds of a range type, and absent for any
// other type. The five fields after it are absent for a range type that
// takes the default. A dump writes them back with CREATE TYPE AS RANGE. See
// D292.
RangeSubtype sql.Null[string]
// RangeOpClass is the operator class of the subtype, when it is not the
// default one.
RangeOpClass sql.Null[string]
// RangeCollation is the collation of the bounds, when it is not the one of the subtype.
RangeCollation sql.Null[string]
// RangeCanonical is the function that puts a range in its canonical form.
RangeCanonical sql.Null[string]
// RangeSubtypeDiff is the function that gives the difference of two bounds.
RangeSubtypeDiff sql.Null[string]
// RangeMultirange is the name of the multirange type of a range type, which
// release 14 made. It is absent on an older release.
RangeMultirange sql.Null[string]
}
Type is a data type. psql lists them with \dT.
type TypeAttribute ¶ added in v0.42.0
type TypeAttribute struct {
Schema string
// Type is the name of the type that has the attribute.
Type string
Name string
// Ordinal is the position of the attribute, from 1.
Ordinal int64
DataType string
Nullable bool
}
TypeAttribute is one attribute of an object type. It is the same fact as the column of a composite type, and it has a kind of its own where the catalog keeps the attributes of a type apart from the columns of a table, as Oracle does.
type TypeRef ¶ added in v0.36.0
type TypeRef struct {
// OID is the number of the type.
OID uint32
// Modifier is the modifier of the type, such as the length of a
// varchar(10) plus four. It is -1 when the type has none.
Modifier int32
}
TypeRef is the type of one result column as a driver reports it.
type User ¶
type User struct {
// Name is the effective user, which is what a client shows.
Name string
// Session is who the connection authenticated as, and is absent on a
// product that does not separate the two.
Session sql.Null[string]
}
User is who a connection is authenticated as.
Most products answer two names rather than one. The effective user is who the session acts as now, and the session user is who it authenticated as. They differ after SET ROLE on PostgreSQL, and on SQL Server they are always two different things: a connection authenticates as a server login and acts as a database user, so sa acts as dbo.
Both come from one statement on every product that has them, so both are reported. See D47.
type UserMapping ¶
UserMapping maps a local role onto a foreign server. psql lists them with \deu.
type Variant ¶ added in v0.15.0
type Variant struct {
// Param is the name of a boolean parameter that the binding declares.
Param string
// Stmt replaces Binding.Stmt when the parameter is true. It returns the
// same columns as Binding.Stmt, in the same order.
Stmt Stmt
}
Variant is a statement that replaces the statement of a binding when a boolean parameter is true. It is for a read that needs a right that a caller does not always hold, so the plain statement never names the source and the caller opts in. The text of a statement cannot depend on an argument in any other way. See D232.
type Version ¶
type Version struct {
// Raw is the text the server reported.
Raw string
// Parts are the numeric components, most significant first.
Parts []uint32
// Suffix is any text after the numbers.
Suffix string
// Unknown reports that the server gave no usable version. A serverless
// database is the usual case. An unknown version sorts above every known
// one, because a continuously released database is newest.
Unknown bool
}
Version is one version a server reports.
The number of components differs per database. Trino reports one, PostgreSQL two, SQLite3 three, SQL Server four, and Oracle five. Comparison pads the shorter list with zeros, so 16.2 and 16.2.0 are the same version.
Suffix holds any text after the numbers, such as the "MariaDB" in "11.4.2-MariaDB". It is recorded and never compared. A flavor is a separate axis and belongs to the dialect.
func ParseVersion ¶
ParseVersion reads a version from the text a server reported. It takes the leading numeric components and records the rest as the suffix.
It accepts a leading "v", which DuckDB reports. It returns a version marked Unknown, and no error, for text with no leading number, which is how YDB reports "<unknown>".
func ParseVersionNum ¶
ParseVersionNum reads the integer a PostgreSQL server reports for server_version_num.
The encoding changed at release 10. Below 100000 the integer packs three numbers, so 90624 is 9.6.24. At 100000 and above it packs two, so 180006 is 18.6. The second number lands in the same position either way, so this agrees with ParseVersion about the same server.
func V ¶
V builds a Version from its numeric components. Use it for the minimum version of a fragment, where only the numbers matter.
func (Version) Compare ¶
Compare compares v and ver, padding the shorter component list with zeros. It returns a negative number when v is older, a positive number when v is newer, and zero when they are the same. An unknown version is newer than every known one.
func (Version) String ¶
String satisfies the fmt.Stringer interface.
type VersionSet ¶
type VersionSet struct {
// Versions holds each reported version by name. The empty name is the
// main one.
Versions map[string]Version
// Display is the line to show a person, built by the dialect that parsed
// it, such as "Microsoft SQL Server 16.0.4115.5, RTM-CU12, Developer
// Edition".
Display string
}
VersionSet is every version one server reports.
Most databases report one, under the empty key. Cassandra reports three that move independently: the release under the empty key, and the keys "cql" and "protocol", so a fragment says which one it gates on.
func (VersionSet) Get ¶
func (s VersionSet) Get(key string) Version
Get returns the version recorded under key. A key that was never set returns an unknown version, so a fragment gating on a version the server does not report is treated as newest rather than failing.
A caller deciding whether a fragment applies calls [Has] first. An unknown version is newer than every known one, so Get alone makes an absent key look like the newest possible server.
func (VersionSet) Has ¶
func (s VersionSet) Has(key string) bool
Has reports whether key was recorded.
A named key is a fact about the server, so its absence is a fact too. A server that reports no "mariadb" version is not a MariaDB server, and a fragment naming that key must not apply to it. Read this rather than [Get], which cannot tell an absent key from an unreadable version. See D44.
func (VersionSet) Keys ¶
func (s VersionSet) Keys() []string
Keys returns every key recorded, sorted, so that a caller can show what the server reported.
func (VersionSet) Main ¶
func (s VersionSet) Main() Version
Main returns the version under the empty key.
func (*VersionSet) Set ¶
func (s *VersionSet) Set(key string, ver Version)
Set records ver under key. The empty key is the main version.
func (VersionSet) String ¶
func (s VersionSet) String() string
String satisfies the fmt.Stringer interface. It returns Display when the dialect set one.
type View ¶
type View struct {
Catalog string
Schema string
Name string
Definition sql.Null[string]
// CheckOption is none, local or cascaded.
CheckOption sql.Null[string]
Updatable sql.Null[bool]
Insertable sql.Null[bool]
Comment sql.Null[string]
}
View is a view and the statement that defines it.
It is durable. The definition is what the catalog stores rather than a rendering of it, so it is text and that is the structured answer.
It is a separate kind rather than a field on Table on purpose. Reaching the definition costs a join or a function call per row, and a caller listing tables does not want to pay it.
type ViewDependency ¶ added in v0.37.0
type ViewDependency struct {
Schema string
// View is the name of the view.
View string
// ReferencedSchema and Referenced name the relation that the view reads.
ReferencedSchema string
Referenced string
// ReferencedType is table, view or materialized view, in lower case.
ReferencedType string
}
ViewDependency says that a view reads a relation. A view that reads three tables has three rows.
It is durable. It is a separate kind rather than a field on View, because a view has many and a child of an object is its own kind with flat rows (D47).
type XMLSchemaCollection ¶ added in v0.45.0
type XMLSchemaCollection struct {
Schema string
Name string
// Definition is the text of the schemas, which CREATE XML SCHEMA COLLECTION
// takes. It is absent where the caller cannot read it.
Definition sql.Null[string]
Comment sql.Null[string]
}
XMLSchemaCollection is a set of XML schemas that a column of the type xml can be checked against. SQL Server keeps them in the database.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package all registers the metadata models.
|
Package all registers the metadata models. |
|
Package container names the database servers that dbrun starts: the ones dbmeta is tested against, and the Staged ones that no model reads yet.
|
Package container names the database servers that dbrun starts: the ones dbmeta is tested against, and the Staged ones that no model reads yet. |
|
Package dump builds the statements of a dump and of a copy, and runs nothing.
|
Package dump builds the statements of a dump and of a copy, and runs nothing. |
|
Package hosted names the hosted database services that dbrun can reach, as Go data.
|
Package hosted names the hosted database services that dbrun can reach, as Go data. |
|
models
|
|
|
arangodb
Package arangodb holds the metadata queries for ArangoDB, in AQL.
|
Package arangodb holds the metadata queries for ArangoDB, in AQL. |
|
arangodb/fixture
Package fixture builds the collections the ArangoDB queries read.
|
Package fixture builds the collections the ArangoDB queries read. |
|
athena
Package athena holds the metadata queries for Amazon Athena, in the Trino based SQL of Athena engine version 3.
|
Package athena holds the metadata queries for Amazon Athena, in the Trino based SQL of Athena engine version 3. |
|
athena/fixture
Package fixture holds a known good Amazon Athena schema, in the Trino based SQL dialect of Athena engine version 3.
|
Package fixture holds a known good Amazon Athena schema, in the Trino based SQL dialect of Athena engine version 3. |
|
avatica
Package avatica holds the metadata queries for the standalone Apache Avatica server, which stands in front of HSQLDB.
|
Package avatica holds the metadata queries for the standalone Apache Avatica server, which stands in front of HSQLDB. |
|
avatica/fixture
Package fixture builds the schema the Avatica queries read.
|
Package fixture builds the schema the Avatica queries read. |
|
bigquery
Package bigquery holds the metadata queries for Google BigQuery, in the GoogleSQL dialect.
|
Package bigquery holds the metadata queries for Google BigQuery, in the GoogleSQL dialect. |
|
bigquery/fixture
Package fixture holds a known good BigQuery schema, in the GoogleSQL dialect.
|
Package fixture holds a known good BigQuery schema, in the GoogleSQL dialect. |
|
cassandra
Package cassandra holds the metadata queries for Apache Cassandra.
|
Package cassandra holds the metadata queries for Apache Cassandra. |
|
cassandra/fixture
Package fixture builds the keyspace the Cassandra queries read.
|
Package fixture builds the keyspace the Cassandra queries read. |
|
clickhouse
Package clickhouse holds the metadata queries for ClickHouse.
|
Package clickhouse holds the metadata queries for ClickHouse. |
|
clickhouse/fixture
Package fixture builds the database the ClickHouse queries read.
|
Package fixture builds the database the ClickHouse queries read. |
|
cockroachdb
Package cockroachdb holds the metadata queries for CockroachDB.
|
Package cockroachdb holds the metadata queries for CockroachDB. |
|
cockroachdb/fixture
Package fixture holds known good CockroachDB schemas.
|
Package fixture holds known good CockroachDB schemas. |
|
cosmos
Package cosmos holds the metadata queries for Azure Cosmos DB, with the API for NoSQL.
|
Package cosmos holds the metadata queries for Azure Cosmos DB, with the API for NoSQL. |
|
cosmos/fixture
Package fixture holds a known good Azure Cosmos DB database, for the API for NoSQL.
|
Package fixture holds a known good Azure Cosmos DB database, for the API for NoSQL. |
|
couchbase
Package couchbase holds the metadata queries for Couchbase Server, in SQL++.
|
Package couchbase holds the metadata queries for Couchbase Server, in SQL++. |
|
couchbase/fixture
Package fixture builds the scope the Couchbase queries read.
|
Package fixture builds the scope the Couchbase queries read. |
|
cratedb
Package cratedb holds the metadata queries for CrateDB.
|
Package cratedb holds the metadata queries for CrateDB. |
|
cratedb/fixture
Package fixture builds the schema the CrateDB queries read.
|
Package fixture builds the schema the CrateDB queries read. |
|
databend
Package databend holds the metadata queries for Databend.
|
Package databend holds the metadata queries for Databend. |
|
databend/fixture
Package fixture builds the objects the Databend queries read.
|
Package fixture builds the objects the Databend queries read. |
|
databricks
Package databricks holds the metadata queries for Databricks SQL on Unity Catalog.
|
Package databricks holds the metadata queries for Databricks SQL on Unity Catalog. |
|
databricks/fixture
Package fixture holds a known good Databricks schema, in the SQL of Databricks SQL on Unity Catalog.
|
Package fixture holds a known good Databricks schema, in the SQL of Databricks SQL on Unity Catalog. |
|
drill
Package drill holds the metadata queries for Apache Drill.
|
Package drill holds the metadata queries for Apache Drill. |
|
drill/fixture
Package fixture holds a known good Apache Drill server.
|
Package fixture holds a known good Apache Drill server. |
|
druid
Package druid holds the metadata queries for Apache Druid, in Druid SQL.
|
Package druid holds the metadata queries for Apache Druid, in Druid SQL. |
|
druid/fixture
Package fixture holds a known good Apache Druid cluster.
|
Package fixture holds a known good Apache Druid cluster. |
|
duckdb
Package duckdb holds the metadata queries for DuckDB.
|
Package duckdb holds the metadata queries for DuckDB. |
|
duckdb/fixture
Package fixture holds a known good DuckDB schema.
|
Package fixture holds a known good DuckDB schema. |
|
elasticsearch
Package elasticsearch holds the metadata queries for Elasticsearch, in its SQL.
|
Package elasticsearch holds the metadata queries for Elasticsearch, in its SQL. |
|
elasticsearch/fixture
Package fixture builds the indices the Elasticsearch queries read.
|
Package fixture builds the indices the Elasticsearch queries read. |
|
exasol
Package exasol holds the metadata queries for Exasol.
|
Package exasol holds the metadata queries for Exasol. |
|
exasol/fixture
Package fixture builds the schema the Exasol queries read.
|
Package fixture builds the schema the Exasol queries read. |
|
firebird
Package firebird holds the metadata queries for Firebird.
|
Package firebird holds the metadata queries for Firebird. |
|
firebird/fixture
Package fixture builds the schema the Firebird queries read.
|
Package fixture builds the schema the Firebird queries read. |
|
hana
Package hana holds the metadata queries for SAP HANA.
|
Package hana holds the metadata queries for SAP HANA. |
|
hana/fixture
Package fixture builds the schema the SAP HANA queries read.
|
Package fixture builds the schema the SAP HANA queries read. |
|
hive
Package hive holds the metadata queries for Apache Hive.
|
Package hive holds the metadata queries for Apache Hive. |
|
hive/fixture
Package fixture builds the schema the Apache Hive queries read.
|
Package fixture builds the schema the Apache Hive queries read. |
|
impala
Package impala holds the metadata queries for Apache Impala.
|
Package impala holds the metadata queries for Apache Impala. |
|
impala/fixture
Package fixture builds the objects the Impala queries read.
|
Package fixture builds the objects the Impala queries read. |
|
influxdb
Package influxdb holds the metadata queries for InfluxDB 3.
|
Package influxdb holds the metadata queries for InfluxDB 3. |
|
influxdb/fixture
Package fixture holds a known good InfluxDB 3 database.
|
Package fixture holds a known good InfluxDB 3 database. |
|
influxql
Package influxql holds the metadata queries for InfluxQL, the query language of InfluxDB 1 and of InfluxDB 2 through its v1 API.
|
Package influxql holds the metadata queries for InfluxQL, the query language of InfluxDB 1 and of InfluxDB 2 through its v1 API. |
|
influxql/fixture
Package fixture holds a known good InfluxQL database.
|
Package fixture holds a known good InfluxQL database. |
|
informationschema
Package informationschema builds metadata queries from the SQL standard's information_schema views.
|
Package informationschema builds metadata queries from the SQL standard's information_schema views. |
|
informationschema/fixture
Package fixture holds a known good schema for a database read through information_schema.
|
Package fixture holds a known good schema for a database read through information_schema. |
|
internal/typeparse
Package typeparse reads the type names of the products that a basic dump only reads from.
|
Package typeparse reads the type names of the products that a basic dump only reads from. |
|
libsql
Package libsql holds the metadata queries for libSQL.
|
Package libsql holds the metadata queries for libSQL. |
|
libsql/fixture
Package fixture holds a known good libSQL schema.
|
Package fixture holds a known good libSQL schema. |
|
maxcompute
Package maxcompute holds the metadata queries for Alibaba Cloud MaxCompute, in the SQL of MaxCompute.
|
Package maxcompute holds the metadata queries for Alibaba Cloud MaxCompute, in the SQL of MaxCompute. |
|
maxcompute/fixture
Package fixture holds a known good Alibaba Cloud MaxCompute project, in the SQL of MaxCompute.
|
Package fixture holds a known good Alibaba Cloud MaxCompute project, in the SQL of MaxCompute. |
|
mysql
Package mysql holds the metadata queries for MariaDB and MySQL.
|
Package mysql holds the metadata queries for MariaDB and MySQL. |
|
mysql/fixture
Package fixture holds known good MariaDB and MySQL schemas.
|
Package fixture holds known good MariaDB and MySQL schemas. |
|
neo4j
Package neo4j holds the metadata queries for Neo4j, the graph database, in Cypher.
|
Package neo4j holds the metadata queries for Neo4j, the graph database, in Cypher. |
|
neo4j/fixture
Package fixture builds the objects the Neo4j queries read.
|
Package fixture builds the objects the Neo4j queries read. |
|
opensearch
Package opensearch holds the metadata queries for OpenSearch, in its SQL.
|
Package opensearch holds the metadata queries for OpenSearch, in its SQL. |
|
opensearch/fixture
Package fixture builds the indices the OpenSearch queries read.
|
Package fixture builds the indices the OpenSearch queries read. |
|
oracle
Package oracle holds the metadata queries for Oracle Database.
|
Package oracle holds the metadata queries for Oracle Database. |
|
oracle/fixture
Package fixture builds the schema the Oracle queries read.
|
Package fixture builds the schema the Oracle queries read. |
|
postgres
Package postgres holds the metadata queries for PostgreSQL.
|
Package postgres holds the metadata queries for PostgreSQL. |
|
postgres/fixture
Package fixture holds known good PostgreSQL schemas.
|
Package fixture holds known good PostgreSQL schemas. |
|
presto
Package presto holds the metadata queries for Presto.
|
Package presto holds the metadata queries for Presto. |
|
presto/fixture
Package fixture builds the schema the Presto queries read.
|
Package fixture builds the schema the Presto queries read. |
|
questdb
Package questdb holds the metadata queries for QuestDB.
|
Package questdb holds the metadata queries for QuestDB. |
|
questdb/fixture
Package fixture builds the tables the QuestDB queries read.
|
Package fixture builds the tables the QuestDB queries read. |
|
redshift
Package redshift holds the metadata queries for Amazon Redshift.
|
Package redshift holds the metadata queries for Amazon Redshift. |
|
redshift/fixture
Package fixture builds the objects the Redshift queries read.
|
Package fixture builds the objects the Redshift queries read. |
|
rqlite
Package rqlite holds the metadata queries for rqlite.
|
Package rqlite holds the metadata queries for rqlite. |
|
rqlite/fixture
Package fixture holds a known good rqlite schema.
|
Package fixture holds a known good rqlite schema. |
|
singlestore
Package singlestore holds the metadata queries for SingleStore.
|
Package singlestore holds the metadata queries for SingleStore. |
|
singlestore/fixture
Package fixture builds the objects the SingleStore queries read.
|
Package fixture builds the objects the SingleStore queries read. |
|
snowflake
Package snowflake holds the metadata queries for Snowflake.
|
Package snowflake holds the metadata queries for Snowflake. |
|
snowflake/fixture
Package fixture builds the objects the Snowflake queries read.
|
Package fixture builds the objects the Snowflake queries read. |
|
solr
Package solr holds the metadata queries for Apache Solr, in the SQL of its Parallel SQL handler.
|
Package solr holds the metadata queries for Apache Solr, in the SQL of its Parallel SQL handler. |
|
solr/fixture
Package fixture builds the collections the Apache Solr queries read.
|
Package fixture builds the collections the Apache Solr queries read. |
|
spanner
Package spanner holds the metadata queries for Google Cloud Spanner, in the GoogleSQL dialect.
|
Package spanner holds the metadata queries for Google Cloud Spanner, in the GoogleSQL dialect. |
|
spanner/fixture
Package fixture holds a known good Spanner schema, in the GoogleSQL dialect.
|
Package fixture holds a known good Spanner schema, in the GoogleSQL dialect. |
|
sqlite3
Package sqlite3 holds the metadata queries for SQLite.
|
Package sqlite3 holds the metadata queries for SQLite. |
|
sqlite3/fixture
Package fixture holds a known good SQLite schema.
|
Package fixture holds a known good SQLite schema. |
|
sqlserver
Package sqlserver holds the metadata queries for Microsoft SQL Server.
|
Package sqlserver holds the metadata queries for Microsoft SQL Server. |
|
sqlserver/fixture
Package fixture holds a known good Microsoft SQL Server schema.
|
Package fixture holds a known good Microsoft SQL Server schema. |
|
surrealdb
Package surrealdb holds the metadata queries for SurrealDB, in SurrealQL.
|
Package surrealdb holds the metadata queries for SurrealDB, in SurrealQL. |
|
surrealdb/fixture
Package fixture builds the objects the SurrealDB queries read.
|
Package fixture builds the objects the SurrealDB queries read. |
|
tablestore
Package tablestore holds the metadata queries for Alibaba Cloud Tablestore, through its SQL feature.
|
Package tablestore holds the metadata queries for Alibaba Cloud Tablestore, through its SQL feature. |
|
tablestore/fixture
Package fixture holds a known good set of Tablestore tables, for the SQL feature of the service.
|
Package fixture holds a known good set of Tablestore tables, for the SQL feature of the service. |
|
tidb
Package tidb holds the metadata queries for TiDB.
|
Package tidb holds the metadata queries for TiDB. |
|
tidb/fixture
Package fixture holds known good TiDB schemas.
|
Package fixture holds known good TiDB schemas. |
|
trino
Package trino holds the metadata queries for Trino.
|
Package trino holds the metadata queries for Trino. |
|
trino/fixture
Package fixture builds the schema the Trino queries read.
|
Package fixture builds the schema the Trino queries read. |
|
vertica
Package vertica holds the metadata queries for Vertica.
|
Package vertica holds the metadata queries for Vertica. |
|
vertica/fixture
Package fixture builds the schema the Vertica queries read.
|
Package fixture builds the schema the Vertica queries read. |
|
vitess
Package vitess holds the metadata queries for Vitess.
|
Package vitess holds the metadata queries for Vitess. |
|
vitess/fixture
Package fixture holds known good Vitess schemas.
|
Package fixture holds known good Vitess schemas. |
|
ydb
Package ydb holds the metadata queries for YDB.
|
Package ydb holds the metadata queries for YDB. |
|
ydb/fixture
Package fixture builds the directory the YDB queries read.
|
Package fixture builds the directory the YDB queries read. |