pg

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// SystemSchemaWhereClause is an optimization for getting less schema objects.
	SystemSchemaWhereClause = func() string {
		var schemas []string
		for schema := range systemSchemas {
			schemas = append(schemas, fmt.Sprintf("'%s'", schema))
		}
		return strings.Join(schemas, ",")
	}()
)

Functions

func Completion

func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error)

Completion is the entry point of PostgreSQL code completion.

func Diagnose

func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]base.Diagnostic, error)

func ExtractAccessTables

func ExtractAccessTables(statement string, option ExtractAccessTablesOption) ([]base.ColumnResource, error)

ExtractAccessTables extracts all table/view references from a SQL statement. This is a lightweight version that doesn't perform full query span analysis.

func GenerateRestoreSQL

func GenerateRestoreSQL(ctx context.Context, rCtx base.RestoreContext, statement string, backupItem *storepb.PriorBackupDetail_Item) (string, error)

func GetQuerySpan

func GetQuerySpan(ctx context.Context, gCtx base.GetQuerySpanContext, statement, database, schema string, _ bool) (*base.QuerySpan, error)

GetQuerySpan returns the query span for the given statement.

func GetStatementRanges

func GetStatementRanges(_ context.Context, _ base.StatementRangeContext, statement string) ([]base.Range, error)

func IsPlSQLBlock

func IsPlSQLBlock(stmt string) bool

IsPlSQLBlock checks if the given statement is a PL/pgSQL anonymous code block (DO statement). Returns true if the statement is a DO block only, false otherwise.

func IsSystemDatabase

func IsSystemDatabase(database string) bool

func IsSystemFunction

func IsSystemFunction(function string, definition string) bool

func IsSystemSchema

func IsSystemSchema(schema string) bool

func IsSystemTable

func IsSystemTable(table string) bool

func IsSystemUser

func IsSystemUser(user string) bool

func IsSystemView

func IsSystemView(view string) bool

func NormalizePostgreSQLAnyName

func NormalizePostgreSQLAnyName(ctx parser.IAny_nameContext) []string

NormalizePostgreSQLAnyName normalizes the given any name.

func NormalizePostgreSQLColid

func NormalizePostgreSQLColid(ctx parser.IColidContext) string

NormalizePostgreSQLColid normalizes the given colid.

func NormalizePostgreSQLFuncName

func NormalizePostgreSQLFuncName(ctx parser.IFunc_nameContext) []string

NormalizePostgreSQLFuncName normalizes the given function name.

func NormalizePostgreSQLName

func NormalizePostgreSQLName(ctx parser.INameContext) string

NormalizePostgreSQLName normalizes the given name. nolint:revive

func NormalizePostgreSQLQualifiedName

func NormalizePostgreSQLQualifiedName(ctx parser.IQualified_nameContext) []string

ParsePostgreSQLStatement parses the given SQL and returns the AST tree.

func ParsePostgreSQL

func ParsePostgreSQL(sql string) ([]*base.ParseResult, error)

ParsePostgreSQL parses the given SQL and returns a list of ParseResult (one per statement). Use the PostgreSQL parser based on antlr4.

func ParsePostgreSQLPLBlock

func ParsePostgreSQLPLBlock(plBlock string) (*base.ParseResult, error)

ParsePostgreSQLPLBlock parses the given PL/pgSQL block (BEGIN...END) and returns the ParseResult. Use the PostgreSQL parser based on antlr4, starting from pl_block rule.

func SplitSQL

func SplitSQL(statement string) ([]base.SingleSQL, error)

SplitSQL splits the given SQL statement into multiple SQL statements.

func TransformDMLToSelect

func TransformDMLToSelect(ctx context.Context, tCtx base.TransformContext, statement string, _ string, targetSchema string, tablePrefix string) ([]base.BackupStatement, error)

Types

type CTETableListener

type CTETableListener struct {
	*pg.BasePostgreSQLParserListener
	// contains filtered or unexported fields
}

func (*CTETableListener) EnterCommon_table_expr

func (l *CTETableListener) EnterCommon_table_expr(ctx *pg.Common_table_exprContext)

type Completer

type Completer struct {
	// contains filtered or unexported fields
}

func NewStandardCompleter

func NewStandardCompleter(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) *Completer

func NewTrickyCompleter

func NewTrickyCompleter(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) *Completer

type CompletionMap

type CompletionMap map[string]base.Candidate

func (CompletionMap) Insert

func (m CompletionMap) Insert(entry base.Candidate)

type ExtractAccessTablesOption

type ExtractAccessTablesOption struct {
	// DefaultDatabase is the default database name to use when table reference doesn't specify one.
	DefaultDatabase string
	// DefaultSchema is the default schema name to use when table reference doesn't specify one.
	DefaultSchema string
	// SkipMetadataValidation skips metadata lookup and validation.
	// When true, returns all table references found in SQL without checking if they exist.
	SkipMetadataValidation bool
	// GetDatabaseMetadata is the function to get database metadata (optional, only used when SkipMetadataValidation is false).
	GetDatabaseMetadata base.GetDatabaseMetadataFunc
	// Ctx is the context for metadata lookup (optional, only used when SkipMetadataValidation is false).
	Ctx context.Context
	// InstanceID is the instance ID for metadata lookup (optional, only used when SkipMetadataValidation is false).
	InstanceID string
}

ExtractAccessTablesOption configures access table extraction behavior.

type ObjectFlags

type ObjectFlags int
const (
	ObjectFlagsShowSchemas ObjectFlags = 1 << iota
	ObjectFlagsShowTables
	ObjectFlagsShowColumns
	ObjectFlagsShowFirst
	ObjectFlagsShowSecond
)

type SetOperator

type SetOperator struct {
	Type       string // "UNION", "EXCEPT", "INTERSECT"
	IsDistinct bool   // false means ALL, true means DISTINCT (or implicit distinct)
}

SetOperator represents a set operation between SELECT statements

type StatementType

type StatementType int
const (
	StatementTypeUnknown StatementType = iota
	StatementTypeUpdate
	StatementTypeInsert
	StatementTypeDelete
)

type StatementTypeWithPosition

type StatementTypeWithPosition struct {
	Type string
	// Line is the one-based line number where the statement ends.
	Line int
	Text string
}

StatementTypeWithPosition contains statement type and its position information.

func GetStatementTypes

func GetStatementTypes(asts []base.AST) ([]StatementTypeWithPosition, error)

GetStatementTypes returns statement types with position information. The line numbers are one-based.

type TableRefListener

type TableRefListener struct {
	*pg.BasePostgreSQLParserListener
	// contains filtered or unexported fields
}

func (*TableRefListener) EnterSelect_with_parens

func (l *TableRefListener) EnterSelect_with_parens(_ *pg.Select_with_parensContext)

func (*TableRefListener) EnterTable_ref

func (l *TableRefListener) EnterTable_ref(ctx *pg.Table_refContext)

func (*TableRefListener) ExitSelect_with_parens

func (l *TableRefListener) ExitSelect_with_parens(_ *pg.Select_with_parensContext)

func (*TableRefListener) ExitTable_ref

func (l *TableRefListener) ExitTable_ref(ctx *pg.Table_refContext)

type TableReference

type TableReference struct {
	Database      string
	Schema        string
	Table         string
	Alias         string
	StatementType StatementType
}

func (*TableReference) String

func (t *TableReference) String() string

type TargetAliasListener

type TargetAliasListener struct {
	*pg.BasePostgreSQLParserListener
	// contains filtered or unexported fields
}

func (*TargetAliasListener) EnterTarget_alias

func (l *TargetAliasListener) EnterTarget_alias(ctx *pg.Target_aliasContext)

Jump to

Keyboard shortcuts

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