Class yii\db\pgsql\QueryBuilder

Inheritanceyii\db\pgsql\QueryBuilder » yii\db\QueryBuilder » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/pgsql/QueryBuilder.php

QueryBuilder is the query builder for PostgreSQL databases.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$db yii\db\Connection The database connection. yii\db\QueryBuilder
$separator string The separator between different fragments of a SQL statement. yii\db\QueryBuilder
$typeMap array Mapping from abstract column types (keys) to physical column types (values). yii\db\pgsql\QueryBuilder

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$conditionBuilders array Map of query condition to builder methods. yii\db\QueryBuilder
$conditionClasses array Map of condition aliases to condition classes. yii\db\QueryBuilder
$expressionBuilders string[]|yii\db\ExpressionBuilderInterface[] Maps expression class to expression builder class. yii\db\QueryBuilder

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\db\QueryBuilder
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
addCheck() Creates a SQL command for adding a check constraint to an existing table. yii\db\QueryBuilder
addColumn() Builds a SQL statement for adding a new DB column. yii\db\QueryBuilder
addCommentOnColumn() Builds a SQL command for adding comment to column. yii\db\QueryBuilder
addCommentOnTable() Builds a SQL command for adding comment to table. yii\db\QueryBuilder
addDefaultValue() Creates a SQL command for adding a default value constraint to an existing table. yii\db\QueryBuilder
addForeignKey() Builds a SQL statement for adding a foreign key constraint to an existing table. yii\db\QueryBuilder
addPrimaryKey() Builds a SQL statement for adding a primary key constraint to an existing table. yii\db\QueryBuilder
addUnique() Creates a SQL command for adding an unique constraint to an existing table. yii\db\QueryBuilder
alterColumn() Builds a SQL statement for changing the definition of a column. yii\db\pgsql\QueryBuilder
batchInsert() {@inheritdoc} yii\db\pgsql\QueryBuilder
bindParam() Helper method to add $value to $params array using PARAM_PREFIX. yii\db\QueryBuilder
build() Generates a SELECT SQL statement from a yii\db\Query object. yii\db\QueryBuilder
buildAndCondition() Connects two or more SQL expressions with the AND or OR operator. yii\db\QueryBuilder
buildBetweenCondition() Creates an SQL expressions with the BETWEEN operator. yii\db\QueryBuilder
buildColumns() Processes columns and properly quotes them if necessary. yii\db\QueryBuilder
buildCondition() Parses the condition specification and generates the corresponding SQL expression. yii\db\QueryBuilder
buildExistsCondition() Creates an SQL expressions with the EXISTS operator. yii\db\QueryBuilder
buildExpression() Builds given $expression yii\db\QueryBuilder
buildFrom() yii\db\QueryBuilder
buildGroupBy() yii\db\QueryBuilder
buildHashCondition() Creates a condition based on column-value pairs. yii\db\QueryBuilder
buildHaving() yii\db\QueryBuilder
buildInCondition() Creates an SQL expressions with the IN operator. yii\db\QueryBuilder
buildJoin() yii\db\QueryBuilder
buildLikeCondition() Creates an SQL expressions with the LIKE operator. yii\db\QueryBuilder
buildLimit() yii\db\QueryBuilder
buildNotCondition() Inverts an SQL expressions with NOT operator. yii\db\QueryBuilder
buildOrderBy() yii\db\QueryBuilder
buildOrderByAndLimit() Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. yii\db\QueryBuilder
buildSelect() yii\db\QueryBuilder
buildSimpleCondition() Creates an SQL expressions like "column" operator value. yii\db\QueryBuilder
buildUnion() yii\db\QueryBuilder
buildWhere() yii\db\QueryBuilder
buildWithQueries() yii\db\QueryBuilder
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
checkIntegrity() Builds a SQL statement for enabling or disabling integrity check. yii\db\pgsql\QueryBuilder
className() Returns the fully qualified name of this class. yii\base\BaseObject
createConditionFromArray() Transforms $condition defined in array format (as described in yii\db\Query::where() to instance of \yii\db\yii\db\condition\ConditionInterface according to $conditionClasses map. yii\db\QueryBuilder
createIndex() Builds a SQL statement for creating a new index. yii\db\pgsql\QueryBuilder
createTable() Builds a SQL statement for creating a new DB table. yii\db\QueryBuilder
createView() Creates a SQL View. yii\db\QueryBuilder
delete() Creates a DELETE SQL statement. yii\db\QueryBuilder
dropCheck() Creates a SQL command for dropping a check constraint. yii\db\QueryBuilder
dropColumn() Builds a SQL statement for dropping a DB column. yii\db\QueryBuilder
dropCommentFromColumn() Builds a SQL command for adding comment to column. yii\db\QueryBuilder
dropCommentFromTable() Builds a SQL command for adding comment to table. yii\db\QueryBuilder
dropDefaultValue() Creates a SQL command for dropping a default value constraint. yii\db\QueryBuilder
dropForeignKey() Builds a SQL statement for dropping a foreign key constraint. yii\db\QueryBuilder
dropIndex() Builds a SQL statement for dropping an index. yii\db\pgsql\QueryBuilder
dropPrimaryKey() Builds a SQL statement for removing a primary key constraint to an existing table. yii\db\QueryBuilder
dropTable() Builds a SQL statement for dropping a DB table. yii\db\QueryBuilder
dropUnique() Creates a SQL command for dropping an unique constraint. yii\db\QueryBuilder
dropView() Drops a SQL View. yii\db\QueryBuilder
executeResetSequence() Execute a SQL statement for resetting the sequence value of a table's primary key. yii\db\QueryBuilder
getColumnType() Converts an abstract column type into a physical column type. yii\db\QueryBuilder
getExpressionBuilder() Gets object of yii\db\ExpressionBuilderInterface that is suitable for $expression. yii\db\QueryBuilder
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() {@inheritdoc} yii\db\QueryBuilder
insert() {@inheritdoc} yii\db\pgsql\QueryBuilder
renameColumn() Builds a SQL statement for renaming a column. yii\db\QueryBuilder
renameTable() Builds a SQL statement for renaming a DB table. yii\db\pgsql\QueryBuilder
resetSequence() Creates a SQL statement for resetting the sequence value of a table's primary key. yii\db\pgsql\QueryBuilder
selectExists() Creates a SELECT EXISTS() SQL statement. yii\db\QueryBuilder
setConditionClasses() Setter for $conditionClasses property. yii\db\QueryBuilder
setExpressionBuilders() Setter for $expressionBuilders property. yii\db\QueryBuilder
truncateTable() Builds a SQL statement for truncating a DB table. yii\db\pgsql\QueryBuilder
update() {@inheritdoc} yii\db\pgsql\QueryBuilder
upsert() {@inheritdoc} yii\db\pgsql\QueryBuilder

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
defaultConditionClasses() {@inheritdoc} yii\db\pgsql\QueryBuilder
defaultExpressionBuilders() {@inheritdoc} yii\db\pgsql\QueryBuilder
extractAlias() Extracts table alias if there is one or returns false yii\db\QueryBuilder
hasLimit() Checks to see if the given limit is effective. yii\db\QueryBuilder
hasOffset() Checks to see if the given offset is effective. yii\db\QueryBuilder
prepareInsertSelectSubQuery() Prepare select-subquery and field names for INSERT INTO . yii\db\QueryBuilder
prepareInsertValues() Prepares a VALUES part for an INSERT SQL statement. yii\db\QueryBuilder
prepareUpdateSets() Prepares a SET parts for an UPDATE SQL statement. yii\db\QueryBuilder
prepareUpsertColumns() yii\db\QueryBuilder

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
INDEX_B_TREE 'btree' Defines a B-tree index for createIndex(). yii\db\pgsql\QueryBuilder
INDEX_GIN 'gin' Defines a GIN index for createIndex(). yii\db\pgsql\QueryBuilder
INDEX_GIST 'gist' Defines a GiST index for createIndex(). yii\db\pgsql\QueryBuilder
INDEX_HASH 'hash' Defines a hash index for createIndex(). yii\db\pgsql\QueryBuilder
INDEX_UNIQUE 'unique' Defines a UNIQUE index for createIndex(). yii\db\pgsql\QueryBuilder
PARAM_PREFIX ':qp' The prefix for automatically generated query binding parameters. yii\db\QueryBuilder

Property Details

$typeMap public property

Mapping from abstract column types (keys) to physical column types (values).

public array $typeMap = [\yii\db\pgsql\Schema::TYPE_PK => 'serial NOT NULL PRIMARY KEY', \yii\db\pgsql\Schema::TYPE_UPK => 'serial NOT NULL PRIMARY KEY', \yii\db\pgsql\Schema::TYPE_BIGPK => 'bigserial NOT NULL PRIMARY KEY', \yii\db\pgsql\Schema::TYPE_UBIGPK => 'bigserial NOT NULL PRIMARY KEY', \yii\db\pgsql\Schema::TYPE_CHAR => 'char(1)', \yii\db\pgsql\Schema::TYPE_STRING => 'varchar(255)', \yii\db\pgsql\Schema::TYPE_TEXT => 'text', \yii\db\pgsql\Schema::TYPE_TINYINT => 'smallint', \yii\db\pgsql\Schema::TYPE_SMALLINT => 'smallint', \yii\db\pgsql\Schema::TYPE_INTEGER => 'integer', \yii\db\pgsql\Schema::TYPE_BIGINT => 'bigint', \yii\db\pgsql\Schema::TYPE_FLOAT => 'double precision', \yii\db\pgsql\Schema::TYPE_DOUBLE => 'double precision', \yii\db\pgsql\Schema::TYPE_DECIMAL => 'numeric(10,0)', \yii\db\pgsql\Schema::TYPE_DATETIME => 'timestamp(0)', \yii\db\pgsql\Schema::TYPE_TIMESTAMP => 'timestamp(0)', \yii\db\pgsql\Schema::TYPE_TIME => 'time(0)', \yii\db\pgsql\Schema::TYPE_DATE => 'date', \yii\db\pgsql\Schema::TYPE_BINARY => 'bytea', \yii\db\pgsql\Schema::TYPE_BOOLEAN => 'boolean', \yii\db\pgsql\Schema::TYPE_MONEY => 'numeric(19,4)', \yii\db\pgsql\Schema::TYPE_JSON => 'jsonb']

Method Details

alterColumn() public method

Builds a SQL statement for changing the definition of a column.

public string alterColumn ( $table, $column, $type )
$table string

The table whose column is to be changed. The table name will be properly quoted by the method.

$column string

The name of the column to be changed. The name will be properly quoted by the method.

$type string

The new column type. The getColumnType() method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. You can also use PostgreSQL-specific syntax such as SET NOT NULL.

return string

The SQL statement for changing the definition of a column.

batchInsert() public method

{@inheritdoc}

public void batchInsert ( $table, $columns, $rows, &$params = [] )
$table
$columns
$rows
$params
checkIntegrity() public method

Builds a SQL statement for enabling or disabling integrity check.

public string checkIntegrity ( $check true, $schema '', $table '' )
$check boolean

Whether to turn on or off the integrity check.

$schema string

The schema of the tables.

$table string

The table name.

return string

The SQL statement for checking integrity

createIndex() public method

Builds a SQL statement for creating a new index.

See also http://www.postgresql.org/docs/8.2/static/sql-createindex.html.

public string createIndex ( $name, $table, $columns, $unique false )
$name string

The name of the index. The name will be properly quoted by the method.

$table string

The table that the new index will be created for. The table name will be properly quoted by the method.

$columns string|array

The column(s) that should be included in the index. If there are multiple columns, separate them with commas or use an array to represent them. Each column name will be properly quoted by the method, unless a parenthesis is found in the name.

$unique boolean|string

Whether to make this a UNIQUE index constraint. You can pass true or INDEX_UNIQUE to create a unique index, false to make a non-unique index using the default index type, or one of the following constants to specify the index method to use: INDEX_B_TREE, INDEX_HASH, INDEX_GIST, INDEX_GIN.

return string

The SQL statement for creating a new index.

defaultConditionClasses() protected method

{@inheritdoc}

protected void defaultConditionClasses ( )
defaultExpressionBuilders() protected method

{@inheritdoc}

protected void defaultExpressionBuilders ( )
dropIndex() public method

Builds a SQL statement for dropping an index.

public string dropIndex ( $name, $table )
$name string

The name of the index to be dropped. The name will be properly quoted by the method.

$table string

The table whose index is to be dropped. The name will be properly quoted by the method.

return string

The SQL statement for dropping an index.

insert() public method

{@inheritdoc}

public void insert ( $table, $columns, &$params )
$table
$columns
$params
renameTable() public method

Builds a SQL statement for renaming a DB table.

public string renameTable ( $oldName, $newName )
$oldName string

The table to be renamed. The name will be properly quoted by the method.

$newName string

The new table name. The name will be properly quoted by the method.

return string

The SQL statement for renaming a DB table.

resetSequence() public method

Creates a SQL statement for resetting the sequence value of a table's primary key.

The sequence will be reset such that the primary key of the next new row inserted will have the specified value or 1.

public string resetSequence ( $tableName, $value null )
$tableName string

The name of the table whose primary key sequence will be reset

$value mixed

The value for the primary key of the next new row inserted. If this is not set, the next new row's primary key will have a value 1.

return string

The SQL statement for resetting sequence

throws yii\base\InvalidArgumentException

if the table does not exist or there is no sequence associated with the table.

truncateTable() public method

Builds a SQL statement for truncating a DB table.

Explicitly restarts identity for PGSQL to be consistent with other databases which all do this by default.

public string truncateTable ( $table )
$table string

The table to be truncated. The name will be properly quoted by the method.

return string

The SQL statement for truncating a DB table.

update() public method

{@inheritdoc}

public void update ( $table, $columns, $condition, &$params )
$table
$columns
$condition
$params
upsert() public method
public void upsert ( $table, $insertColumns, $updateColumns, &$params )
$table
$insertColumns
$updateColumns
$params