MediaWiki master
Wikimedia\Rdbms\Platform\PostgresPlatform Class Reference

Inherits Wikimedia\Rdbms\Platform\SQLPlatform.

Collaboration diagram for Wikimedia\Rdbms\Platform\PostgresPlatform:

Public Member Functions

 buildConcat ( $stringList)
 Build a concatenation list to feed into a SQL query.
Parameters
string[]$stringListRaw SQL expression list; caller is responsible for escaping
Returns
string

 
 buildGroupConcat ( $field, $delim)
 Build a GROUP_CONCAT expression.
Parameters
string$fieldField name
string$delimDelimiter
Returns
string

 
 buildStringCast ( $field)
 
Parameters
string$fieldField or column to cast
Returns
string
Since
1.28 in IDatabase, moved to ISQLPlatform in 1.39

 
 getCoreSchema ()
 
 getDatabaseAndTableIdentifier (string $table)
 Get the database identifer and prefixed table name identifier for a table.The table name is assumed to be relative to the current DB domainThis method is useful for TEMPORARY table tracking. In MySQL, temp tables with identical names can co-exist on different databases, which can be done via CREATE and USE. Note that SQLite/PostgreSQL do not allow changing the database within a session. This method omits the schema identifier for several reasons:

  • MySQL/MariaDB do not support schemas at all.
  • SQLite/PostgreSQL put all TEMPORARY tables in the same schema (TEMP and pgtemp, respectively). When these engines resolve a table reference, they first check for a matching table in the temp schema, before checking the current DB domain schema. Note that this breaks table segregation based on the schema component of the DB domain, e.g. a temp table with unqualified name "x" resolves to the same underlying table whether the current DB domain is "my_db-schema1-mw_" or "my_db-schema2-mw_". By ignoring the schema, we can at least account for this.
  • Exposing the the TEMP/pg_temp schema here would be too leaky of an abstraction, running the risk of unexpected results, such as identifiers that don't match. It is easier to just avoid creating identically-named TEMPORARY tables on different schemas.
Access: internal
only to be used inside rdbms library
Parameters
string$tableTable name
Returns
array{0:string|null,1:string} (unquoted database name, unquoted prefixed table name)

 
 implicitOrderby ()
 Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1.
Returns
bool

 
 isTransactableQuery (Query $sql)
 Determine whether a SQL statement is sensitive to isolation level.A SQL statement is considered transactable if its result could vary depending on the transaction isolation level. Operational commands such as 'SET' and 'SHOW' are not considered to be transactable.Main purpose: Used by query() to decide whether to begin a transaction before the current query (in DBO_TRX mode, on by default).
Returns
bool

 
 limitResult ( $sql, $limit, $offset=false)
 Construct a LIMIT query with optional offset.The SQL should be adjusted so that only the first $limit rows are returned. If $offset is provided as well, then the first $offset rows should be discarded, and the next $limit rows should be returned. If the result of the query is not ordered, then the rows to be returned are theoretically arbitrary.$sql is expected to be a SELECT, if that makes a difference.
Parameters
string$sqlSQL query we will append the limit too
int$limitThe SQL limit
int | false$offsetThe SQL offset (default false)
Returns
string
Since
1.34 in IDatabase, moved to ISQLPlatform in 1.39

 
 lockIsFreeSQLText ( $lockName)
 
Parameters
string$lockName
Returns
string

 
 lockSQLText ( $lockName, $timeout)
 
Parameters
string$lockName
float$timeout
Returns
string

 
 makeInsertLists (array $rows, $aliasPrefix='', array $typeByColumn=[])
 Make SQL lists of columns, row tuples, and column aliases for INSERT/VALUES expressions.The tuple column order is that of the columns of the first provided row. The provided rows must have exactly the same keys and ordering thereof.
Parameters
array[]$rowsNon-empty list of (column => value) maps
string$aliasPrefixOptional prefix to prepend to the magic alias names
string[]$typeByColumnOptional map of (column => data type)
Returns
array (comma-separated columns, comma-separated tuples, comma-separated aliases)
Since
1.35

 
 selectSQLText ( $tables, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Take the same arguments as IDatabase::select() and return the SQL it would use.This can be useful for making UNION queries, where the SQL text of each query is needed. In general, however, callers outside of Database classes should just use select().
See also
IDatabase::select()
Parameters
string | array$tablesTable reference(s), using the unqualified name of tables or of the form "information_schema.<identifier>".
string | array$varsField names
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression>$conds Conditions
string$fnameCaller function name
string | array$optionsQuery options
string | array$join_condsJoin conditions
Returns
string SQL query string

 
 setCoreSchema (string $coreSchema)
 
 timestamp ( $ts=0)
 Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS.The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.
Parameters
string | int$ts
Returns
string

 
 unlockSQLText ( $lockName)
 
Parameters
string$lockName
Returns
string

 
- Public Member Functions inherited from Wikimedia\Rdbms\Platform\SQLPlatform
 __construct (DbQuoter $quoter, ?LoggerInterface $logger=null, ?DatabaseDomain $currentDomain=null, $errorLogger=null)
 
 addIdentifierQuotes ( $s)
 Escape a SQL identifier (e.g.table, column, database) for use in a SQL queryDepending on the database this will either be backticks or "double quotes"
Parameters
string$s
Returns
string
Since
1.33

 
 anyChar ()
 Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.
Returns
LikeMatch

 
 anyString ()
 Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
Returns
LikeMatch

 
 assertValidUpsertSetArray (array $set, array $uniqueKey, array $rows)
 
 bitAnd ( $fieldLeft, $fieldRight)
 
Parameters
string | int$fieldLeft
string | int$fieldRight
Returns
string

 
 bitNot ( $field)
 
Parameters
string | int$field
Returns
string

 
 bitOr ( $fieldLeft, $fieldRight)
 
Parameters
string | int$fieldLeft
string | int$fieldRight
Returns
string

 
 buildComparison (string $op, array $conds)
 Build a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g.
 
 buildExcludedValue ( $column)
 
 buildGreatest ( $fields, $values)
 Build a GREATEST function statement comparing columns/values.Integer and float values in $values will not be quotedIf $fields is an array, then each value with a string key is treated as an expression (which must be manually quoted); such string keys do not appear in the SQL and are only descriptive aliases.
Parameters
string | string[]$fieldsName(s) of column(s) with values to compare
string | int | float | string[] | int[] | float[]$valuesValues to compare
Returns
mixed
Since
1.35 in IDatabase, moved to ISQLPlatform in 1.39

 
 buildGroupConcatField ( $delim, $tables, $field, $conds='', $join_conds=[])
 Build a GROUP_CONCAT or equivalent statement for a query.This is useful for combining a field for several rows into a single string. NULL values will not appear in the output, duplicated values will appear, and the resulting delimiter-separated values have no defined sort order. Code using the results may need to use the PHP unique() or sort() methods.
Parameters
string$delimGlue to bind the results together
string | array$tablesTable reference(s), using the unqualified name of tables or of the form "information_schema.<identifier>". {
See also
select} for details.
Parameters
string$fieldField name
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression>$conds Conditions
string | array$join_condsJoin conditions
Returns
string SQL text
Since
1.23

 
 buildIntegerCast ( $field)
 
Parameters
string$fieldField or column to cast
Returns
string
Since
1.31 in IDatabase, moved to ISQLPlatform in 1.39

 
 buildLeast ( $fields, $values)
 Build a LEAST function statement comparing columns/values.Integer and float values in $values will not be quotedIf $fields is an array, then each value with a string key is treated as an expression (which must be manually quoted); such string keys do not appear in the SQL and are only descriptive aliases.
Parameters
string | string[]$fieldsName(s) of column(s) with values to compare
string | int | float | string[] | int[] | float[]$valuesValues to compare
Returns
mixed
Since
1.35 in IDatabase, moved to ISQLPlatform in 1.39

 
 buildLike ( $param,... $params)
 LIKE statement wrapper.This takes a variable-length argument list with parts of pattern to match containing either string literals that will be escaped or tokens returned by anyChar() or anyString(). Alternatively, the function could be provided with an array of the aforementioned parameters.Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns a LIKE clause that searches for subpages of 'My page title'. Alternatively: $pattern = [ 'My_page_title/', $dbr->anyString() ]; $query .= $dbr->buildLike( $pattern );
Since
1.16 in IDatabase, moved to ISQLPlatform in 1.39
Parameters
string|LikeMatch|non-empty-array<string|LikeMatch>$param
string|LikeMatch...$params
Returns
string Fully built LIKE statement

 
 buildSelectSubquery ( $tables, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery.
See also
IDatabase::selectSQLText()
Parameters
string | array$tablesTable reference(s), using the unqualified name of tables or of the form "information_schema.<identifier>". {
See also
select} for details.
Parameters
string | array$varsField names
string | array$condsConditions
string$fnameCaller function name
string | array$optionsQuery options
string | array$join_condsJoin conditions
Returns
Subquery
Since
1.31

 
 buildSubstring ( $input, $startPosition, $length=null)
 
 conditional ( $cond, $caseTrueExpression, $caseFalseExpression)
 Returns an SQL expression for a simple conditional.This doesn't need to be overridden unless CASE isn't supported in the RDBMS.
Parameters
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>>|array<int,string|IExpression>$cond SQL condition expression (yields a boolean)
string | int$caseTrueExpressionSQL expression to return when the condition is true
string | int$caseFalseExpressionSQL expression to return when the condition is false
Returns
string SQL fragment

 
 decodeExpiry ( $expiry, $format=TS::MW)
 Decode an expiry time into a DBMS independent format.
Parameters
string$expiryDB timestamp field value for expiry
int | TS$formatTS::* constant, defaults to TS::MW
Returns
string

 
 deleteJoinSqlText ( $delTable, $joinTable, $delVar, $joinVar, $conds)
 
 deleteSqlText ( $table, $conds)
 
 dispatchingInsertSqlText ( $table, $rows, $options)
 
 dropTableSqlText ( $table)
 
 encodeExpiry ( $expiry)
 Encode an expiry time into the DBMS dependent format.
Parameters
string$expiryTimestamp for expiry, or the 'infinity' string
Returns
string

 
 escapeLikeInternal ( $s, $escapeChar='`')
 
 extractSingleFieldFromList ( $var)
 
 extractTableNameComponents (string $name)
 Extract the dot-separated components of a table name, preserving identifier quotation.
 
 factorConds ( $condsArray)
 Given an array of condition arrays representing an OR list of AND lists, for example:(A=1 AND B=2) OR (A=1 AND B=3)produce an SQL expression in which the conditions are factored:(A=1 AND (B=2 OR B=3))We also use IN() to simplify further:(A=1 AND (B IN (2,3))More compactly, in boolean algebra notation, a sum of products, e.g. AB + AC is factored to produce A(B+C). Factoring proceeds recursively to reduce expressions with any number of variables, for example AEP + AEQ + AFP + AFQ = A(E(P+Q) + F(P+Q))The algorithm is simple and will not necessarily find the shortest possible expression. For the best results, fields should be given in a consistent order, and the fields with values likely to be shared should be leftmost in the associative arrays.
Parameters
array$condsArrayAn array of associative arrays. The associative array keys represent field names, and the values represent the field values to compare against.
Returns
string SQL expression fragment

 
 fieldNameWithAlias ( $name, $alias=false)
 Get an aliased field name e.g.
 
 getCurrentDomain ()
 
 getInfinity ()
 Find out when 'infinity' is.Most DBMSes support this. This is a special keyword for timestamps in PostgreSQL, and works with CHAR(14) as well because "i" sorts after all numbers.
Returns
string

 
 getQueryVerb ( $sql)
 
 getTableAliases ()
 
 ignoreIndexClause ( $index)
 IGNORE INDEX clause.
 
 insertNonConflictingSqlText ( $table, array $rows)
 
 insertSelectNativeSqlText ( $destTable, $srcTable, array $varMap, $conds, $fname, array $insertOptions, array $selectOptions, $selectJoinConds)
 
 insertSqlText ( $table, array $rows)
 
 isFlagInOptions ( $option, array $options)
 
 isQuotedIdentifier ( $name)
 Returns if the given identifier looks quoted or not according to the database convention for quoting identifiers.
 
 makeKeyCollisionCondition (array $rows, array $uniqueKey)
 Build an SQL condition to find rows with matching key values to those in $rows.
 
 makeList (array $a, $mode=self::LIST_COMMA)
 Makes an encoded list of strings from an array.These can be used to make conjunctions or disjunctions on SQL condition strings derived from an array ({

See also
IDatabase::select} $conds documentation).

Example usage:

$sql = $db->makeList( [
'rev_page' => $id,
$db->makeList( [ 'rev_minor' => 1, 'rev_len < 500' ], $db::LIST_OR )
], $db::LIST_AND );

This would set $sql to "rev_page = '$id' AND (rev_minor = 1 OR rev_len < 500)"

Parameters
array$aContaining the data
int$modeIDatabase class constant:
Exceptions
DBErrorIf an error occurs, {
See also
IDatabase::query}
Returns
string

 
 makeWhereFrom2d ( $data, $baseKey, $subKey)
 Build a "OR" condition with pairs from a two-dimensional array.The associative array should have integer keys relating to the $baseKey field. The nested array should have string keys for the $subKey field. The inner values are ignored, and are typically boolean true.Example usage:

$data = [
2 => [
'Foo' => true,
'Bar' => true,
],
3 => [
'Quux' => true,
],
];
// (page_namespace = 2 AND page_title IN ('Foo','Bar'))
// OR (page_namespace = 3 AND page_title = 'Quux')
Todo
This is effectively specific to MediaWiki's LinkBatch. Consider deprecating or generalising slightly.
Parameters
array$dataNested array, must be non-empty
string$baseKeyField name to match the base-level keys to (eg 'pl_namespace')
string$subKeyField name to match the sub-level keys to (eg 'pl_title')
Returns
string SQL fragment

 
 normalizeConditions ( $conds, $fname)
 
 normalizeOptions ( $options)
 
 normalizeUpsertParams ( $uniqueKeys, &$rows)
 Validate and normalize parameters to upsert() or replace()
 
 qualifiedTableComponents ( $name)
 Get the table components needed for a query given the currently selected database/schema.
 
 releaseSavepointSqlText ( $identifier)
 
 replaceVars ( $ins)
 Database-independent variable replacement.
 
 rollbackSqlText ()
 
 rollbackToSavepointSqlText ( $identifier)
 
 savepointSqlText ( $identifier)
 
 setCurrentDomain (DatabaseDomain $currentDomain)
 
 setPrefix (string $prefix)
 
 setSchemaVars ( $vars)
 Set schema variables to be used when streaming commands from SQL files or stdin.Variables appear as SQL comments and are substituted by their corresponding values
Parameters
array | null$varsMap of (variable => value) or null to use the defaults

 
 setTableAliases (array $aliases)
 Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name.
 
 strreplace ( $orig, $old, $new)
 Returns a SQL expression for simple string replacement (e.g.REPLACE() in mysql)
Parameters
string$origColumn to modify
string$oldColumn to seek
string$newColumn to replace with
Returns
string

 
 tableName (string $name, $format='quoted')
 Format a table name ready for use in constructing an SQL query.This does two important things: it quotes the table names to clean them up, and it adds a table prefix if only given a table name with no quotes.All functions of this object which require a table name call this function themselves. Pass the canonical name to such functions. This is only needed when calling query() directly.The provided name should not qualify the database nor the schema, unless the name is of the form "information_schema.<identifier>". Unlike information_schema tables, regular tables can receive writes and are subject to configuration regarding table aliases, virtual domains, and LBFactory sharding. Callers needing to access remote databases should use appropriate connection factory methods.
Note
This function does not sanitize user input. It is not safe to use this function to escape user input.
Parameters
string$nameThe unqualified name of a table (no quotes, db, schema, nor table prefix), or a table name of the form "information_schema.<unquoted identifier>".
string$formatOne of: quoted - Automatically pass the table name through addIdentifierQuotes() so that it can be used in a query. raw - Do not add identifier quotes to the table name.
Returns
string Qualified table name (includes any applicable prefix or foreign db/schema)

 
 tableNamesN (... $tables)
 Fetch a number of table names into a zero-indexed numerical array.Much like tableName(), this is only needed when calling query() directly. You should prefer calling other methods, or using SelectQueryBuilder.Theoretical example (which really does not require raw SQL):

[ $user, $watchlist ] = $dbr->tableNamesN( 'user', 'watchlist' );
$sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user
WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
Parameters
string...$tables
Returns
array
Deprecated
Since 1.43; if you must format table names, write several calls to tableName.

 
 timestampOrNull ( $ts=null)
 Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS.If NULL is input, it is passed through, allowing NULL values to be inserted into timestamp fields.The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.
Parameters
string | int | null$ts
Returns
string|null

 
 unionQueries ( $sqls, $all, $options=[])
 Construct a UNION query.This is used for providing overload point for other DB abstractions not compatible with the MySQL syntax.
Access: internal
callers outside of rdbms library should use UnionQueryBuilder instead.
Parameters
array$sqlsSQL statements to combine
bool$allEither IDatabase::UNION_ALL or IDatabase::UNION_DISTINCT
array$optionsQuery options
Returns
string SQL fragment

 
 unionSupportsOrderAndLimit ()
 Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.
Returns
bool

 
 updateSqlText ( $table, $set, $conds, $options)
 
 useIndexClause ( $index)
 USE INDEX clause.
 
- Public Member Functions inherited from Wikimedia\Rdbms\Platform\ISQLPlatform
 buildSubString ( $input, $startPosition, $length=null)
 Build a SUBSTRING function.
 

Protected Member Functions

 makeInsertNonConflictingVerbAndOptions ()
 
Returns
string[] ("INSERT"-style SQL verb, "ON CONFLICT"-style clause or "")
Since
1.35

 
 makeSelectOptions (array $options)
 Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.
See also
Database::select()
Parameters
array$optionsAssociative array of options to be turned into an SQL query, valid keys are listed in the function.
Returns
string[] (START OPTIONS, PRE-LIMIT TAIL, POST-LIMIT TAIL)

 
 makeUpdateOptionsArray ( $options)
 Make UPDATE options array for Database::makeUpdateOptions.
Parameters
array$options
Returns
array

 
 relationSchemaQualifier ()
 
Returns
string|null Schema to use to qualify relations in queries

 
- Protected Member Functions inherited from Wikimedia\Rdbms\Platform\SQLPlatform
 assertBuildSubstringParams ( $startPosition, $length)
 Check type and bounds for parameters to self::buildSubstring()
 
 assertValidUpsertRowArray (array $rows, array $uniqueKey)
 
 buildSuperlative ( $sqlfunc, $fields, $values)
 Build a superlative function statement comparing columns/values.
 
 fieldNamesWithAlias ( $fields)
 Gets an array of aliased field names.
 
 getDefaultSchemaVars ()
 Get schema variables to use if none have been set via setSchemaVars().
 
 getIdentifierQuoteChar ()
 Get the character used for identifier quoting.
 
 getSchemaVars ()
 Get schema variables.
 
 makeGroupByWithHaving ( $options)
 Returns an optional GROUP BY with an optional HAVING.
 
 makeOrderBy ( $options)
 Returns an optional ORDER BY.
 
 makeUpdateOptions ( $options)
 Make UPDATE options for the Database::update function.
 
 normalizeJoinType (string $joinType)
 Validate and normalize a join type.
 
 normalizeRowArray (array $rowOrRows)
 
 tableNamesWithIndexClauseOrJOIN ( $tables, $use_index=[], $ignore_index=[], $join_conds=[])
 Get the aliased table name clause for a FROM clause which might have a JOIN and/or USE INDEX or IGNORE INDEX clause.
 
 tableNameWithAlias ( $table, $alias=false)
 Get an aliased table name.
 

Additional Inherited Members

- Public Attributes inherited from Wikimedia\Rdbms\Platform\ISQLPlatform
const ALL_ROWS = '*'
 Unconditional update/delete of whole table.
 
const CALLER_SUBQUERY = 'subquery'
 Special value for ->caller() / $fname parameter used when providing a caller is not expected, because we're formatting a subquery that won't be executed directly.
 
const CALLER_UNKNOWN = 'unknown'
 Special value for ->caller() / $fname parameter used when a caller is not provided.
 
const LIST_AND = 1
 Combine list with AND clauses.
 
const LIST_COMMA = 0
 Combine list with comma delimiters.
 
const LIST_NAMES = 3
 Treat as field name and do not apply value escaping.
 
const LIST_OR = 4
 Combine list with OR clauses.
 
const LIST_SET = 2
 Convert map into a SET clause.
 
const QUERY_CHANGE_LOCKS = 512
 Query is a command for advisory locks.
 
const QUERY_CHANGE_NONE = 32
 Query is a read-only Data Query Language query.
 
const QUERY_CHANGE_ROWS = 128
 Query is a Data Manipulation Language command (INSERT, DELETE, LOCK, ...)
 
const QUERY_CHANGE_SCHEMA = 256
 Query is a Data Definition Language command.
 
const QUERY_CHANGE_TRX = 64
 Query is a Transaction Control Language command (BEGIN, USE, SET, ...)
 
const QUERY_IGNORE_DBO_TRX = 8
 Ignore the current presence of any DBO_TRX flag.
 
const QUERY_NO_RETRY = 16
 Do not try to retry the query if the connection was lost.
 
const QUERY_NORMAL = 0
 Idiom for "no special flags".
 
const QUERY_PSEUDO_PERMANENT = 2
 Track a TEMPORARY table CREATE as if it was for a permanent table (for testing)
 
const QUERY_REPLICA_ROLE = 4
 Enforce that a query does not make effective writes.
 
const QUERY_SILENCE_ERRORS = 1
 Ignore query errors and return false when they happen.
 
- Protected Attributes inherited from Wikimedia\Rdbms\Platform\SQLPlatform
DatabaseDomain $currentDomain
 
callable $errorLogger
 Error logging callback.
 
LoggerInterface $logger
 
DbQuoter $quoter
 
array null $schemaVars
 Current variables use for schema element placeholders.
 
array[] $tableAliases = []
 Current map of (table => (dbname, schema, prefix) map)
 

Detailed Description

Since
1.39
See also
ISQLPlatform

Definition at line 17 of file PostgresPlatform.php.

Member Function Documentation

◆ buildConcat()

Wikimedia\Rdbms\Platform\PostgresPlatform::buildConcat ( $stringList)

Build a concatenation list to feed into a SQL query.

Parameters
string[]$stringListRaw SQL expression list; caller is responsible for escaping
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 27 of file PostgresPlatform.php.

◆ buildGroupConcat()

Wikimedia\Rdbms\Platform\PostgresPlatform::buildGroupConcat ( $field,
$delim )

Build a GROUP_CONCAT expression.

Parameters
string$fieldField name
string$delimDelimiter
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 32 of file PostgresPlatform.php.

◆ buildStringCast()

Wikimedia\Rdbms\Platform\PostgresPlatform::buildStringCast ( $field)

Parameters
string$fieldField or column to cast
Returns
string
Since
1.28 in IDatabase, moved to ISQLPlatform in 1.39

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 44 of file PostgresPlatform.php.

◆ getCoreSchema()

Wikimedia\Rdbms\Platform\PostgresPlatform::getCoreSchema ( )

Definition at line 53 of file PostgresPlatform.php.

◆ getDatabaseAndTableIdentifier()

Wikimedia\Rdbms\Platform\PostgresPlatform::getDatabaseAndTableIdentifier ( string $table)

Get the database identifer and prefixed table name identifier for a table.The table name is assumed to be relative to the current DB domainThis method is useful for TEMPORARY table tracking. In MySQL, temp tables with identical names can co-exist on different databases, which can be done via CREATE and USE. Note that SQLite/PostgreSQL do not allow changing the database within a session. This method omits the schema identifier for several reasons:

  • MySQL/MariaDB do not support schemas at all.
  • SQLite/PostgreSQL put all TEMPORARY tables in the same schema (TEMP and pgtemp, respectively). When these engines resolve a table reference, they first check for a matching table in the temp schema, before checking the current DB domain schema. Note that this breaks table segregation based on the schema component of the DB domain, e.g. a temp table with unqualified name "x" resolves to the same underlying table whether the current DB domain is "my_db-schema1-mw_" or "my_db-schema2-mw_". By ignoring the schema, we can at least account for this.
  • Exposing the the TEMP/pg_temp schema here would be too leaky of an abstraction, running the risk of unexpected results, such as identifiers that don't match. It is easier to just avoid creating identically-named TEMPORARY tables on different schemas.
Access: internal
only to be used inside rdbms library
Parameters
string$tableTable name
Returns
array{0:string|null,1:string} (unquoted database name, unquoted prefixed table name)

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 152 of file PostgresPlatform.php.

◆ implicitOrderby()

Wikimedia\Rdbms\Platform\PostgresPlatform::implicitOrderby ( )

Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1.

Returns
bool

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 49 of file PostgresPlatform.php.

◆ isTransactableQuery()

Wikimedia\Rdbms\Platform\PostgresPlatform::isTransactableQuery ( Query $sql)

Determine whether a SQL statement is sensitive to isolation level.A SQL statement is considered transactable if its result could vary depending on the transaction isolation level. Operational commands such as 'SET' and 'SHOW' are not considered to be transactable.Main purpose: Used by query() to decide whether to begin a transaction before the current query (in DBO_TRX mode, on by default).

Returns
bool

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 238 of file PostgresPlatform.php.

References Wikimedia\Rdbms\Query\getSQL().

◆ limitResult()

Wikimedia\Rdbms\Platform\PostgresPlatform::limitResult ( $sql,
$limit,
$offset = false )

Construct a LIMIT query with optional offset.The SQL should be adjusted so that only the first $limit rows are returned. If $offset is provided as well, then the first $offset rows should be discarded, and the next $limit rows should be returned. If the result of the query is not ordered, then the rows to be returned are theoretically arbitrary.$sql is expected to be a SELECT, if that makes a difference.

Parameters
string$sqlSQL query we will append the limit too
int$limitThe SQL limit
int | false$offsetThe SQL offset (default false)
Returns
string
Since
1.34 in IDatabase, moved to ISQLPlatform in 1.39

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 22 of file PostgresPlatform.php.

◆ lockIsFreeSQLText()

Wikimedia\Rdbms\Platform\PostgresPlatform::lockIsFreeSQLText ( $lockName)

Parameters
string$lockName
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 254 of file PostgresPlatform.php.

◆ lockSQLText()

Wikimedia\Rdbms\Platform\PostgresPlatform::lockSQLText ( $lockName,
$timeout )

Parameters
string$lockName
float$timeout
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 244 of file PostgresPlatform.php.

◆ makeInsertLists()

Wikimedia\Rdbms\Platform\PostgresPlatform::makeInsertLists ( array $rows,
$aliasPrefix = '',
array $typeByColumn = [] )

Make SQL lists of columns, row tuples, and column aliases for INSERT/VALUES expressions.The tuple column order is that of the columns of the first provided row. The provided rows must have exactly the same keys and ordering thereof.

Parameters
array[]$rowsNon-empty list of (column => value) maps
string$aliasPrefixOptional prefix to prepend to the magic alias names
string[]$typeByColumnOptional map of (column => data type)
Returns
array (comma-separated columns, comma-separated tuples, comma-separated aliases)
Since
1.35

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 177 of file PostgresPlatform.php.

◆ makeInsertNonConflictingVerbAndOptions()

Wikimedia\Rdbms\Platform\PostgresPlatform::makeInsertNonConflictingVerbAndOptions ( )
protected

Returns
string[] ("INSERT"-style SQL verb, "ON CONFLICT"-style clause or "")
Since
1.35

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 224 of file PostgresPlatform.php.

◆ makeSelectOptions()

Wikimedia\Rdbms\Platform\PostgresPlatform::makeSelectOptions ( array $options)
protected

Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.

See also
Database::select()
Parameters
array$optionsAssociative array of options to be turned into an SQL query, valid keys are listed in the function.
Returns
string[] (START OPTIONS, PRE-LIMIT TAIL, POST-LIMIT TAIL)

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 120 of file PostgresPlatform.php.

◆ makeUpdateOptionsArray()

Wikimedia\Rdbms\Platform\PostgresPlatform::makeUpdateOptionsArray ( $options)
protected

Make UPDATE options array for Database::makeUpdateOptions.

Parameters
array$options
Returns
array

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 229 of file PostgresPlatform.php.

◆ relationSchemaQualifier()

Wikimedia\Rdbms\Platform\PostgresPlatform::relationSchemaQualifier ( )
protected

Returns
string|null Schema to use to qualify relations in queries

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 167 of file PostgresPlatform.php.

◆ selectSQLText()

Wikimedia\Rdbms\Platform\PostgresPlatform::selectSQLText ( $tables,
$vars,
$conds = '',
$fname = __METHOD__,
$options = [],
$join_conds = [] )

Take the same arguments as IDatabase::select() and return the SQL it would use.This can be useful for making UNION queries, where the SQL text of each query is needed. In general, however, callers outside of Database classes should just use select().

See also
IDatabase::select()
Parameters
string | array$tablesTable reference(s), using the unqualified name of tables or of the form "information_schema.<identifier>".
string | array$varsField names
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression>$conds Conditions
string$fnameCaller function name
string | array$optionsQuery options
string | array$join_condsJoin conditions
Returns
string SQL query string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 62 of file PostgresPlatform.php.

◆ setCoreSchema()

Wikimedia\Rdbms\Platform\PostgresPlatform::setCoreSchema ( string $coreSchema)

Definition at line 57 of file PostgresPlatform.php.

◆ timestamp()

Wikimedia\Rdbms\Platform\PostgresPlatform::timestamp ( $ts = 0)

Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS.The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.

Parameters
string | int$ts
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 37 of file PostgresPlatform.php.

◆ unlockSQLText()

Wikimedia\Rdbms\Platform\PostgresPlatform::unlockSQLText ( $lockName)

Parameters
string$lockName
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 262 of file PostgresPlatform.php.


The documentation for this class was generated from the following file: