Class SqlInsertStatement
Represents a parsed INSERT statement.
public sealed class SqlInsertStatement : SqlStatement
- Inheritance
-
SqlInsertStatement
- Inherited Members
- Extension Methods
Constructors
SqlInsertStatement(SqlSegment, SqlSegment?, SqlStatement?, SqlSegment?, SqlSegment?, WithClause?)
Initializes a new instance of the SqlInsertStatement class.
public SqlInsertStatement(SqlSegment target, SqlSegment? values, SqlStatement? sourceQuery, SqlSegment? output, SqlSegment? returning, WithClause? withClause)
Parameters
targetSqlSegmentThe target segment identifying the destination of the insert.
valuesSqlSegmentThe VALUES segment when the insert uses literal values.
sourceQuerySqlStatementThe statement used as data source when the insert uses a query.
outputSqlSegmentThe OUTPUT segment if present.
returningSqlSegmentThe RETURNING segment if present.
withClauseWithClauseOptional CTE definitions.
Properties
InsertPart
Gets the INSERT clause represented as a typed part.
public InsertPart InsertPart { get; }
Property Value
IntoPart
Gets the INTO clause represented as a typed part.
public IntoPart IntoPart { get; }
Property Value
Output
Gets the OUTPUT segment when present.
public SqlSegment? Output { get; }
Property Value
Returning
Gets the RETURNING segment when present.
public SqlSegment? Returning { get; }
Property Value
SourceQuery
Gets the source statement when the insert pulls data from a query.
public SqlStatement? SourceQuery { get; }
Property Value
Target
Gets the target segment describing the destination table or expression.
public SqlSegment Target { get; }
Property Value
Values
Gets the VALUES segment when the statement inserts literal values.
public SqlSegment? Values { get; }
Property Value
ValuesPart
Gets the VALUES clause represented as a typed part when present.
public ValuesPart? ValuesPart { get; }
Property Value
Methods
BuildSql()
Builds the canonical inline SQL representation of the statement.
protected override string BuildSql()
Returns
- string
The inline SQL string representing the statement.
EnsureOutputSegment()
Ensures an OUTPUT segment exists and returns it.
public SqlSegment EnsureOutputSegment()
Returns
- SqlSegment
The existing or newly created OUTPUT segment.
EnsureReturningSegment()
Ensures a RETURNING segment exists and returns it.
public SqlSegment EnsureReturningSegment()
Returns
- SqlSegment
The existing or newly created RETURNING segment.
EnsureValuesSegment()
Ensures a VALUES segment exists and returns it.
public SqlSegment EnsureValuesSegment()
Returns
- SqlSegment
The existing or newly created VALUES segment.
Exceptions
- InvalidOperationException
Thrown when the insert statement already uses a source query.
GetChildStatements()
Retrieves the child statements referenced by this statement.
protected override IEnumerable<SqlStatement> GetChildStatements()
Returns
- IEnumerable<SqlStatement>
An enumerable of nested statements.