Expand description
Name resolution, type resolution, the query tree, the rewriter for views and rules.
This crate first ships in milestone M2. See spec/22-crate-layout.md section 22.4 and spec/23-milestones.md.
analyze takes a raw statement of rupg-sql and gives a Query whose expressions have their types, as parse_analyze of PostgreSQL does. The rules of type resolution come from parse_coerce.c, parse_func.c and parse_oper.c of PostgreSQL 19, so a query gets the same functions, the same casts and the same errors.
Modules§
- node
- The stored form of an expression, which the catalog keeps for a column default, a check constraint and an index expression.
- tsdict
- The text search dictionaries of the templates
simpleandsnowball: the init functionsdsimple_initanddsnowball_init, which read the options of a dictionary, and the lexize functionsdsimple_lexizeanddsnowball_lexize.CREATE TEXT SEARCH DICTIONARYruns the init function to check the options, asverify_dictoptionsdoes, andts_lexizeruns both. It also has the configurations oflookup_ts_config_cache, with the dictionaries of their maps. - types
- The facts of a type that the rules of
parse_coerce.cread: the category, the preferred flag, the element type and the array type.
Structs§
- Aggref
- A call of an aggregate function, as
Aggref. - Case
- A
CASEexpression. - Column
- A column of a relation.
- Copy
Relation - The relation of a
COPY ... TOand the query that reads its rows. - Copy
Target - The table of a
COPY ... FROM, asDoCopyandBeginCopyFromopen it. - Cte
- A query of
WITHafter the analysis, as aCommonTableExprof the listcteListof a query. - CteRef
- The query of
WITHthat a relation ofFROMreads, as aRangeTblEntryof the kindRTE_CTE. - Current
Of CurrentOfExpr: the condition ofWHERE CURRENT OFon the target table of anUPDATEor aDELETE, which is true for the row that the cursor is on, asexecCurrentOffinds it.- Cycle
Clause CTECycleClause:CYCLE, with the columns that find a cycle, the column of the mark with its two values, and the column of the path.- Deferrable
- A
DEFERRABLEunique constraint. A write does not fail on a duplicate key of its index:unique_key_recheckchecks the key again after the statement, or at the commit when the constraint is deferred. - Defined
- The result of
define. - Derived
- The key of a unique index with an expression or a predicate, which
FormIndexDatumcomputes for each row. A row that does not pass the predicate is not in the index, asExecInsertIndexTupleschecks it withExecQual.Unique::columnshas the places of the key columns in the values of the expressions. - Expr
- An expression with its type and its typmod. A typmod of -1 means that the expression has no typmod.
- Field
Store - The parts of an assignment to fields of a row value, as
FieldStore. - Fill
- The default of a new column of
ALTER TABLE ... ADD COLUMN, asATExecAddColumnkeeps it intab->newvals, or the new expression of a generated column ofSET EXPRESSION. The rows of the table get this default, also when a later subcommand of the statement sets or drops the default of the column. - Foreign
- A foreign key that a write checks after the statement for each row that it wrote, as a trigger of
ri_triggers.cchecks it. The target table is the referencing table forRI_FKey_check_insandRI_FKey_check_upd, and the referenced table for the triggers of the actions, such asRI_FKey_noaction_delandRI_FKey_cascade_upd. - Frame
- The frame of a window, as the fields
frameOptions,startOffset,endOffset,startInRangeFunc,endInRangeFunc,inRangeAscandinRangeNullsFirstofWindowClause. - From
Function - A function in
FROM, as thefunctionsandfuncordinalityof aRangeTblEntryof the kindRTE_FUNCTION. - Func
- A call of a function.
- Grouping
Func - A call of
GROUPING, asGroupingFunc. The result has a bit for each argument, with the bit of the last argument as the lowest bit. A bit is 1 when the grouping set of the group does not have the argument. - IsJson
JsonIsPredicate:IS JSON.- Join
- A join of two parts of
FROM. - JoinRow
- The whole row of a join, or of the alias of
USING. - Json
Behavior JsonBehavior: anON ERRORor anON EMPTYclause.- Json
Ctor JsonConstructorExpr: a SQL/JSON constructor.- Json
Expr JsonExpr:JSON_EXISTS,JSON_QUERYorJSON_VALUE.- Json
Format JsonFormat: aFORMATclause.- Json
Returning JsonReturning: the type of the result of a SQL/JSON function and its format.- Json
Table TableFuncof the kindTFT_JSON_TABLE: the call ofJSON_TABLE.- Json
Table Column - A column of
JSON_TABLE. - Json
Table Scan JsonTablePathScan: a row pattern path and the columns that read its rows.- Json
Value JsonValueExpr: an input of a SQL/JSON function. The executor readsformatted, and the deparser showsrawand the format.- Merge
- The clauses of a
MERGEand the foreign keys that its actions check. - Merge
Clause MergeAction: aWHENclause of aMERGE.- MinMax
MinMaxAggInfo: the form of a query whose aggregate calls are eachminormax, with a subquery for each aggregate call that reads the first value in the order of its sort operator.- Named
Arg - An argument by its name, as
NamedArgExpr. - OnConflict
OnConflictExpr: what anINSERTdoes for a new row with the key of a row that the table has.- OutArg
- An argument of
CALLfor anINOUTorOUTargument of the procedure. ACALLin PL/pgSQL writes the value of the argument back to it, so it must be a variable. - Params
- The parameters of a statement.
- Partition
Check - A partition whose rows must satisfy its partition constraint, one entry of
tab->partition_constraint. - Perm
Info RTEPermissionInfo: the privileges that the statement needs on a relation.- Place
Holder - A
PlaceHolderVar: the value ofexprat the scan or the join of the relations of the subquery, which is null in a row where an outer join above them gives nulls for them, as a column of those relations is. - Product
- A statement of the rewrite of a write by the rules of its table, in the order that
RewriteQuerygives. - Query
- The query tree of a
SELECT. - Reindex
Options - The options of
REINDEX, asExecReindexreads them from the option list. - Relation
- A relation of
FROM, as aRangeTblEntryof the kindRTE_RELATIONorRTE_SUBQUERY. - RowCompare
- The comparison of two rows with an ordering operator, as
RowCompareExpr. - RowMark
- A relation that
FOR UPDATEorFOR SHARElocks, as aRowMarkClause. - Rule
Tree - The query trees of a rule, as
transformRuleStmtmakes them. Each query has the relation of the rule as its first two relations,oldandnew. - Schema
Elements - The elements of
CREATE SCHEMA, which the caller runs after the statement made the schema. - Script
- The statements of the body of a function in SQL that
Body::Statementsruns, whichfmgr_sqlanalyzes and runs one after the other, asprepare_next_queryandinit_execution_statedo. A statement can see the changes of the statements before it. - Search
Clause CTESearchClause:SEARCH DEPTH FIRSTorSEARCH BREADTH FIRST.- SetOp
- An operation of the tree, as
SetOperationStmt. - Shown
- The list of
RETURNINGasEXPLAINshows it in theOutputof aModifyTable. A column ofoldornewreadsRETURNING_OLDorRETURNING_NEWwith the number of the column in the table, andmerge_action()readsMERGE_ACTION. The other columns are as in the targets of the query. - Sort
Group - An item of
ORDER BY,GROUP BY,DISTINCTorDISTINCT ON, asSortGroupClause. - SubLink
- A subquery in an expression, as
SubLink. - Subscript
- The parts of a fetch from an array or of an assignment to a part of an array, as
SubscriptingRef. - Table
Sample TableSampleClause: the sample method ofTABLESAMPLEand its arguments.- Target
- A column of the result.
- TopLevel
- A statement that cannot run inside a transaction block or in a function, as
PreventInTransactionBlockchecks it. - Transform
- The expression of
USINGofALTER COLUMN ... TYPEfor one column, asATPrepAlterColumnTypekeeps it intab->newvals. - Unique
- A unique index of the target table, which
_bt_check_uniquechecks for each new version of a row. - Var
- A column of a relation of
FROM. - Variable
- A variable of a function that a query reads as a parameter.
- View
Check - The
WithCheckOptionitems of the kindWCO_VIEW_CHECKof a write, whichExecWithCheckOptionschecks after the write of each row, beforeRETURNING. - Window
Clause - A window of a query, as
WindowClause. - Window
Func - A call of a window function, as
WindowFunc. - Write
- The table that an
INSERT, anUPDATEor aDELETEwrites. - XmlExpr
XmlExpr: a SQL/XML function with its own syntax. The type isbooleanforIS DOCUMENT,textforXMLSERIALIZEandxmlfor the others.
Enums§
- Action
- What a trigger of a foreign key on the referenced table does for an old key,
confdeltypeandconfupdtype. - Body
- The body of a function in SQL, as the analyzer reads it for the types of the arguments of a call.
- BoolOp
- The operators of
BoolExpr. - Bool
Test - The tests of
BooleanTest. - Cast
Form CoercionFormof a cast node: the way a cast was written, which a deparse function shows.- Context
CoercionContext: where a cast happens. A cast is allowed in its own context and in each later one.- Expr
Kind - The kinds of expression.
- Frame
Bound - The start or the end of a frame.
- Frame
Exclusion - The rows that the clause
EXCLUDEremoves from a frame. - Frame
Mode - The mode of a frame.
- From
Item - A part of
FROM: a relation or a join. - Func
Form - The way a call was written, which a deparse function shows.
- Grouping
Set - A grouping set of
GROUP BY, asGroupingSetaftertransformGroupClause. A simple set names its items by the index of their targets incrate::Query::targets. - Join
Kind - The kinds of join. Only the planner makes a semi join or an anti join, as
pull_up_sublinksmakes them fromEXISTSandIN. - Json
Behavior Kind JsonBehaviorType: what a SQL/JSON function gives on an error or when the path finds no item.- Json
Ctor Kind JsonConstructorType: the function of aJsonCtor.- Json
Encoding JsonEncoding: theENCODINGof aFORMAT JSONclause.- Json
Expr Op JsonExprOp: the function of aJsonExpr.- Json
Format Kind JsonFormatType: the format of aFORMATclause.- Json
Item Type JsonValueType: the kind of JSON value thatIS JSONaccepts.- Json
Table Plan JsonTablePlan: the plan that gives the rows ofJSON_TABLE.- Json
Wrapper JsonWrapper: theWRAPPERclause ofJSON_QUERY.- Match
Kind MergeMatchKind: the rows that aWHENclause takes.- Merge
Command - The action of a
WHENclause. - Message
- A message of a statement that defines an object. The client gets the messages before the result.
- Null
Treatment - The null treatment of a call of a window function, as
ignore_nulls. - Path
CoercionPathType: how a cast happens.- RowCompare
Kind - The comparison of a
RowCompare, asrctype. - SetKind
- The kinds of set operation.
- SetTree
- A part of the tree of a set operation.
- SqlBody
- The body in SQL of a function, as
prosqlbodykeeps it. - SqlValue
- The functions of the SQL standard that take no parentheses.
- SubLink
Kind - The kinds of
SubLinkthat the analyzer takes. - Write
Kind - The kind of a statement that writes the rows of a table,
CmdType. - XmlOp
XmlExprOp: the function of anXmlExpr.
Constants§
- FRAMEOPTION_
END_ OFFSET FRAMEOPTION_END_OFFSET: the end of the frame has an offset.- FRAMEOPTION_
END_ OFFSET_ FOLLOWING FRAMEOPTION_END_OFFSET_FOLLOWING, which the grammar does not name.- FRAMEOPTION_
END_ UNBOUNDED_ FOLLOWING FRAMEOPTION_END_UNBOUNDED_FOLLOWING. The grammar makes the bits of the end of a frame with a shift of the bits of the start, so it does not name this bit.- FRAMEOPTION_
START_ OFFSET FRAMEOPTION_START_OFFSET: the start of the frame has an offset.- MERGE_
ACTION - The relation of
merge_action()inShown::targets, as aMergeSupportFunc. - PG_
CATALOG_ NAMESPACE - The OID of the schema
pg_catalog. - REGRESS_
SYMBOLS - The functions of
regress.cthat havePG_FUNCTION_INFO_V1. A function in C can link to them in the library of the regression tests, andrupg-funcruns some of them. - RETURNING_
NEW - The relation of a column of the new row in
Shown::targets, as aVarwithvarreturningtypeVAR_RETURNING_NEW. - RETURNING_
OLD - The relation of a column of the old row in
Shown::targets, as aVarwithvarreturningtypeVAR_RETURNING_OLD. - TABLE_
OID_ ATTNUM - The attribute number of the system column
tableoid.
Traits§
- Env
- The facts of the session that the analyzer reads.
- Variables
- The variables of a PL/pgSQL function that the queries of the function can name.
Functions§
- acl_
dependents - The objects with an ACL that names the role other than as their owner, as
updateAclDependenciesrecords them inpg_shdepend. The ACL of a column gives an object with the number of the column. - acl_
roles aclmembers: the grantees and the grantors of the texts of an ACL, withoutPUBLIC, in order and without duplicates.- analyze
parse_analyze: the query tree of a raw statement, which is thestmtof aRawStmt. For a statement of the extended protocol, theQueryhas the type of each parameter.- analyze_
assign transformPLAssignStmt:analyze_withof the value of an assignment to the variablenameof the typetywith the typmodtypmod. The value takes the type of the variable with the casts of PL/pgSQL, so that the error of a cast points into the assignment.- analyze_
assign_ part transformPLAssignStmtof an assignment to a part of a variable, asx[i] := 5andr.f[1:2] := a:analyze_withof thePLAssignStmtthatrupg_sql::parse_plpgsql_assigngives. The value of the query is the new value of the variable, which is the array with the new value of the element or of the slice.- analyze_
product crate::analyzefor a statement ofquery_rewrite.- analyze_
with crate::analyzeof a query of a PL/pgSQL function, whose names can be variables of the function. A name that is a column and a variable is an error, asplpgsql.variable_conflictwith the valueerrorgives it.- arg_
defaults stringToNodefor theproargdefaultsof a function: an expression for each default, in the order of the arguments. A function with no defaults gives no expressions.- attnums
CopyGetAttnums: the indexes of the columns that a list of names gives, or of all the columns when the list is empty.relis the name of the relation for the error of a column that does not exist.- can_
coerce can_coerce_type: true if each input type has a cast to its target type in the context.- check_
outer_ joins - The check of
make_outerjoininfo: a relation with a row mark cannot be on the nullable side of an outer join, at each level of the query. - column_
type plpgsql_parse_cwordtype: the type and the typmod of the columncolumnof the relation with the qualified namenames, orNonewhen the relation or the column does not exist.- copy_
filter - The query of the condition
WHEREof aCOPY ... FROM. The parameter$nis the value of the columnnof the row, and the query gives the value of the condition, asExecQualgives it for the row ofCopyFrom. - copy_
insert - The
INSERTthat writes the rows of aCOPY ... FROM, asCopyFromfills a row: the parameter$nis the value of the selected columnn, and the other columns get their defaults.defaultsis true for a selected column whose field is the marker ofDEFAULT. Such a column also gets its default, and the parameters skip it.OVERRIDING SYSTEM VALUElets the data give a value to an identity columnGENERATED ALWAYS, asCOPYdoes. - copy_
relation - The checks of
DoCopyandBeginCopyTofor the relation ofCOPY ... TO:table_openrv,CopyGetAttnumsand the kind of the relation. - copy_
rules_ error - The checks of
BeginCopyToon the rewrite of the query ofCOPYby the rules of its table: the error for a rewrite that is not one statement. - copy_
target - The checks of
table_openrvandCopyGetAttnumsfor the relation ofCOPY. - default_
opclass GetDefaultOpClass: the default operator class of the type for the access method. An exact match comes first. Else the one class that the type has a binary cast to, or the one for a preferred type of its category when there are more.- define
- Runs a statement that defines an object, for the role
user, and adds the object to the catalog. The statement is thestmtof aRawStmt, andtextis its text, which the catalog keeps for a view and for a function. - equality_
for_ ordering get_equality_op_for_ordering_op: the=operator of the btree family of an ordering operator, and true when the operator sorts in descending order.Nonewhen the operator is not the<or the>of a btree family.- execute_
params EvaluateParams: the query that gives the values of the parameters ofEXECUTE. It has noFROMand one column for each expression, which is coerced to the type of its parameter in the assignment context. The caller checks the number of the expressions first.- expand_
arguments expand_function_arguments: the arguments of a call in the order of the function, with the defaults of the arguments that the call does not give. A call with no named argument that gives all the arguments keeps its list.- expand_
grouping_ sets expand_grouping_sets: the grouping sets ofGROUP BYas lists of items, with the shortest lists first. Each set is the product of the expansions of the items ofGROUP BY. Withdistinctthe same set comes once. The result isNonewhen there are more thanlimitsets.- expand_
virtual expand_virtual_generated_columns: the query with the generation expression of each virtual generated column in the place of each column of the table that the query reads, also in its subqueries and in the queries of its write. The rows of a write keep the null of each virtual generated column of the table.- expand_
virtual_ body expand_virtualfor the body of a function in SQL.- explicit_
cast coerce_to_target_typewithCOERCION_EXPLICITandCOERCE_EXPLICIT_CASTfor an expression whose type is known, to a type that is not a domain, as the cast$1::textin the body of a SQL function thatinline_functionputs in a query.Nonewhen the type has no such cast.- figure_
colname - The name of the column for the expression, or
?column?. - find_
library expand_dynamic_library_nameand thestatofinternal_load_library: the full name of the libraryname. The only library that rupg has is the library of the regression tests, by a path that ends inregressorregress.so. A name without a directory is in$libdir, which does not have that library.- find_
path find_coercion_pathway.- first_
row_ mark - The strength of the first row mark on a table in the query, in its subqueries in
FROMand in its views, as the firstPlanRowMarkof the plan. - foreign_
keys - The foreign keys that a write of the kind
kindof the tabletablechecks, in the order of the names of their triggers. A leaf partition checks them for its rows of anUPDATEor aDELETEof its partitioned table. - func_
cost procostof the functionfunc, asget_func_costreads it, or 1 for a function that is not known.- function_
body - The body of a function in SQL as the analyzer reads it from the text that the catalog keeps, for a call with arguments of the types
inputs, with$1as the first argument.Nonewhen the catalog has no function in SQL with the OID. - function_
script - The statements of the body of the function in SQL with the OID, for
Body::Statements.Nonewhen the catalog has no function in SQL with the OID, or when the body isRETURN. - function_
sqlbody - The body in SQL of the function with the OID, as
interpret_AS_clauseanalyzes it forprosqlbody: the arguments have their declared types, and the value ofRETURNand the columns of the queries do not take a cast to the result type.Nonewhen the catalog has no function in SQL with the OID, or when the function has its body in a string. - is_
binary_ coercible IsBinaryCoercible: true if a value ofsourceis a value oftargetwith no change.- is_
definition - True for a statement that
defineruns. - lock_
table LockTableCommandfor the roleuser. The caller doesRequireTransactionBlockfirst. The statement locks each relation after its checks, then the relations that the query of a view reads, or the children of a table withoutONLY.- locked_
tables - The tables with a row mark in the query, in its subqueries in
FROMand in its views. - option_
on - True when the boolean option
nameofreloptionsis on, asRelationHasSecurityInvokerandRelationIsSecurityViewreadsecurity_invokerandsecurity_barrier. - out_
columns build_function_result_tupdesc_tandresolve_polymorphic_tupdesc: the columns of the rows of a call of a function with two or moreOUT,INOUTorTABLEparameters, or of a procedure with one or more. A parameter without a name gives the namecolumnN, and a polymorphic type takes the actual type that the arguments of the call give.Nonefor a function with fewer such parameters.- owned_
objects - The objects of a catalog that have a dependency of
pg_shdependon their ownerrole, asrecordDependencyOnOwnermakes them. An index, a TOAST table, a composite type as a relation, the row type of a table, an array type and a multirange type have none. - param_
types PrepareQuery: the type OIDs of the parameters thatPREPAREdeclares, astypenameTypeIdfinds them.- parse_
type parseTypeString: the OID and the typmod of the type that a string names, as the input ofregtypeandto_regtypemodread it.- plpgsql_
cast get_cast_hashentry: the querySELECT $1that casts a value of the typesourceto the typetargetwith the typmodtypmod, in the context of PL/pgSQL, where the output and the input functions cast a value when no other cast exists.- query_
rewrite QueryRewritefor a write: the statements of the rewrite by the rules of the target table, in order, orNonewhen no rule fires.- record_
fields get_expr_result_tupdescandexpandRecordVariable: the fields of an expression of typerecord. A call of a function gives itsOUTparameters. The whole row of a join gives the columns of the join. A column of a subquery inFROMgives the fields of its expression in the subquery, also through more subqueries.levelshas the relations of the query of the expression, then the relations of each query outside it.Nonewhen the fields are not known before the query runs.- reindex_
options - The option list of
ExecReindex. - relation_
by_ names - The OID of the relation with the qualified name
names, asRangeVarGetRelidfinds it with the search path, orNone. - relation_
row_ type plpgsql_parse_wordrowtype: the row type of the relation with the qualified namenames, orNone.- resolve_
polymorphic enforce_generic_type_consistency: replaces the polymorphic types indeclaredwith the actual types, and gives the actual result type forresult.- rewrite_
insert - The
INSERTthat writes a row of a table again afterALTER COLUMN ... TYPE, asATRewriteTableevaluatestab->newvals: the parameter$nis the old value of the selected columnn, andtransformsgives the expression ofUSINGof a selected column, orNonefor a column that keeps its old value. The expressions refer to the columns by their names, throughFROM (VALUES ($1, ...)) AS relname(columns). The other columns get their defaults. - row_
type_ fields - The name, the type and the typmod of each field of a row type, as
build_row_from_rowtypereads them, orNonefor a type that is not the row type of a relation. A dropped column has no name and the type 0. - rule_
tree - The query trees of the rule of the catalog with the OID, from the text of the rule and the
search_paththat the rule keeps, orNonewhen the catalog has no rule with the OID.pg_get_ruledefshows these queries. - set_
constraints - The constraints of a
SET CONSTRAINTS:NoneforALL, or the OIDs of the deferrable constraints of the names, in the order of the names. A name with no schema finds the constraints with the name in the first schema ofsearch_paththat has one. - sort_
operators - The
<and the>operators of the type, aslookup_type_cachegiveslt_oprandgt_opr, or 0 for an operator that the type does not have.get_rule_orderbyuses them to show the direction of a sort. - strength_
name LCS_asString.- tablespace_
options transformRelOptionsandtablespace_reloptionsforCREATE TABLESPACE: the options of the statement, each asname=value, in the order of the statement. An option cannot have a namespace.- temp_
namespace myTempNamespace: the OID of the temporary schema of the session in the catalog, or 0 when the session has none yet.- trigger_
when - The condition of
WHENof the trigger of the catalog with the OID, with the query that hasoldandnewas its relations, orNonewhen the catalog has no such trigger or the trigger has no condition.pg_get_triggerdefshows the condition. - vacuum_
relations vacuumfor the relationsrelsof aVacuumStmt, afterExecVacuumhas read the options.vacuumis true forVACUUM, andanalyzeis true forANALYZEor forVACUUMwith the optionANALYZE. The warnings for the relations that the statement skips go towarnings, also when a later relation gives an error.- view_
query - The query of a view or of a materialized view of the catalog, from the text of the view and the
search_paththat the view keeps, orNonewhen the catalog has no view with the OID.pg_get_viewdefshows this query.
Type Aliases§
- Allowed
- The privilege check of
LOCK TABLE.allowed(relid, role)isLockTableAclCheckfor the mode of the statement: true when the role can lock the relation. - Take
- The lock of
LOCK TABLEon one relation.take(relid)isLockRelationOidin the mode of the statement, orConditionalLockRelationOidwithNOWAIT. It gives false when the lock is not free and the statement hasNOWAIT.