- HTTP request
- Path parameters
- Request body
- Response body
- Authorization scopes
- ExecuteSqlPayload
- PartialResultMode
- Message
- Metadata
- QueryResult
- Column
- Row
- Value
- Examples
- Try it!
Execute SQL statements.
HTTP request
POST https://sqladmin.googleapis.com/v1/projects/{project}/instances/{instance}/executeSql
The URL uses gRPC Transcoding syntax.
Path parameters
| Parameters | |
|---|---|
project |
Required. Project ID of the project that contains the instance. |
instance |
Required. Database instance ID. This does not include the project ID. |
Request body
The request body contains an instance of ExecuteSqlPayload.
Response body
Execute SQL statements response.
If successful, the response body contains data with the following structure:
| JSON representation |
|---|
{ "messages": [ { object ( |
| Fields | |
|---|---|
messages[] |
A list of notices and warnings generated during query execution. For PostgreSQL, this includes all notices and warnings. For MySQL, this includes warnings generated by the last executed statement. To retrieve all warnings for a multi-statement query, |
metadata |
The additional metadata information regarding the execution of the SQL statements. |
results[] |
The list of results after executing all the SQL statements. |
status |
Contains the error from the database if the SQL execution failed. |
Authorization scopes
Requires one of the following OAuth scopes:
https://www.googleapis.com/auth/cloud-platformhttps://www.googleapis.com/auth/sqlservice.admin
For more information, see the Authentication Overview.
ExecuteSqlPayload
The request payload used to execute SQL statements.
| JSON representation |
|---|
{ "user": string, "sqlStatement": string, "database": string, "rowLimit": string, "partialResultMode": enum ( |
| Fields | |
|---|---|
user |
Optional. The name of an existing database user to connect to the database. When |
sqlStatement |
Required. SQL statements to run on the database. It can be a single statement or a sequence of statements separated by semicolons. |
database |
Optional. Name of the database on which the statement will be executed. |
rowLimit |
Optional. The maximum number of rows returned per SQL statement. |
partialResultMode |
Optional. Controls how the API should respond when the SQL execution result is incomplete due to the size limit or another error. The default mode is to throw an error. |
application |
Optional. Specifies the name of the application that is making the request. This field is used for telemetry. Only alphanumeric characters, dashes, and underscores are allowed. The maximum length is 32 characters. |
Union field user_password. Credentials for the database connection. user_password can be only one of the following: |
|
autoIamAuthn |
Optional. When set to true, the API caller identity associated with the request is used for database authentication. The API caller must be an IAM user in the database. |
PartialResultMode
Controls how the API should respond when the SQL execution result exceeds 10 MB.
| Enums | |
|---|---|
PARTIAL_RESULT_MODE_UNSPECIFIED |
Unspecified mode, effectively the same as FAIL_PARTIAL_RESULT. |
FAIL_PARTIAL_RESULT |
Throw an error if the result exceeds 10 MB or if only a partial result can be retrieved. Don't return the result. |
ALLOW_PARTIAL_RESULT |
Return a truncated result and set partialResult to true if the result exceeds 10 MB or if only a partial result can be retrieved due to error. Don't throw an error. |
Message
Represents a notice or warning message from the database.
| JSON representation |
|---|
{ "message": string, "severity": string } |
| Fields | |
|---|---|
message |
The full message string. For PostgreSQL, this is a formatted string that may include severity, code, and the notice/warning message. For MySQL, this contains the warning message. |
severity |
The severity of the message (e.g., "NOTICE" for PostgreSQL, "WARNING" for MySQL). |
Metadata
The additional metadata information regarding the execution of the SQL statements.
| JSON representation |
|---|
{ "sqlStatementExecutionTime": string } |
| Fields | |
|---|---|
sqlStatementExecutionTime |
The time taken to execute the SQL statements. A duration in seconds with up to nine fractional digits, ending with ' |
QueryResult
QueryResult contains the result of executing a single SQL statement.
| JSON representation |
|---|
{ "columns": [ { object ( |
| Fields | |
|---|---|
columns[] |
instances.list of columns included in the result. This also includes the data type of the column. |
rows[] |
Rows returned by the SQL statement. |
message |
Message related to the SQL execution result. |
partialResult |
Set to true if the SQL execution's result is truncated due to size limits or an error retrieving results. |
status |
If results were truncated due to an error, details of that error. |
Column
Contains the name and datatype of a column.
| JSON representation |
|---|
{ "name": string, "type": string } |
| Fields | |
|---|---|
name |
Name of the column. |
type |
Datatype of the column. |
Row
Contains the values for a row.
| JSON representation |
|---|
{
"values": [
{
object ( |
| Fields | |
|---|---|
values[] |
The values for the row. |
Value
The cell value of the table.
| JSON representation |
|---|
{ "value": string, "nullValue": boolean } |
| Fields | |
|---|---|
value |
The cell value in string format. |
nullValue |
If cell value is null, then this flag will be set to true. |