Context / Client / execute_sql
execute_sql¶
- Context.Client.execute_sql(**kwargs)¶
Runs one read-only SQL query over the tables of a connection in an agent context, and returns the result as typed columns and rows. Use this to read structured data directly when you can write the query yourself. If the result’s rows are larger than 5 MiB, the call fails with
ValidationException. Add aLIMITclause or select fewer columns.See also: AWS API Documentation
Request Syntax
response = client.execute_sql( agentContextId='string', connectionId='string', query={ 'sql': { 'statement': 'string', 'tables': [ { 'glueTableArn': 'string' }, ] } } )
- Parameters:
agentContextId (string) –
[REQUIRED]
The agent context that owns the connection, by ID or full ARN.
connectionId (string) –
[REQUIRED]
The connection to run against. Must be a GLUE_DATA_CATALOG connection linked to the agent context. Its access configuration (
accessConfig) determines how AWS Context reads the tables.query (dict) –
[REQUIRED]
The query to run: a SQL statement and the AWS Glue tables that it reads. For the SQL rules and limits, see
SqlQuery.Note
This is a Tagged Union structure. Only one of the following top level keys can be set:
sql.sql (dict) –
A SQL statement and the tables it reads.
statement (string) – [REQUIRED]
One read-only SELECT or WITH statement, without a trailing
;, in PostgreSQL-compatible SQL as the query engine parses it. Double-quote every identifier: unquoted identifiers are upper-cased and matching is case-sensitive. Reference each table by its quoted, fully qualified AWS Glue table ARN, for exampleSELECT "order_id" FROM "arn:aws:glue:us-east-1:111122223333:table/db/orders" LIMIT 10. At most 50,000 rows are returned whatever the statement’s own LIMIT.tables (list) – [REQUIRED]
Every table the statement reads. The service does not parse the SQL to find tables, and the engine resolves only the tables listed here.
(dict) –
One table the statement reads. Exactly one member is set. Every table must belong to the requested connection in this agent context.
Note
This is a Tagged Union structure. Only one of the following top level keys can be set:
glueTableArn.glueTableArn (string) –
An AWS Glue table, by its fully qualified AWS Glue table ARN, in your account and the current Region.
- Return type:
dict
- Returns:
Response Syntax
{ 'columnMetadata': [ { 'name': 'string', 'type': 'BOOLEAN'|'TINYINT'|'SMALLINT'|'INTEGER'|'BIGINT'|'REAL'|'DOUBLE'|'DECIMAL'|'VARCHAR'|'VARBINARY'|'DATE'|'TIME'|'TIMESTAMP'|'INTERVAL'|'ARRAY'|'STRUCT'|'MAP'|'UNKNOWN', 'typeName': 'string', 'nullable': True|False, 'precision': 123, 'scale': 123, 'timeZone': 'string' }, ], 'rows': [ { 'values': [ { 'nullValue': True|False, 'booleanValue': True|False, 'longValue': 123, 'doubleValue': 123.0, 'stringValue': 'string', 'blobValue': b'bytes', 'jsonValue': 'string' }, ] }, ] }
Response Structure
(dict) –
columnMetadata (list) –
One entry per result column, in result order.
rows[i].values[j]is the value ofcolumnMetadata[j].(dict) –
A result column.
name (string) –
The column name or alias as the engine reports it. Not unique:
SELECT a.id, b.idreturns twoidcolumns.type (string) –
The column’s portable SQL type. It fixes which
SqlValuemember the column’s values use.typeName (string) –
The engine’s own type, for example
Timestamp(MICROSECOND, UTC)orDecimal(12, 2, 128).nullable (boolean) –
Specifies whether the column can hold NULL.
precision (integer) –
DECIMAL: total digits. TIME and TIMESTAMP: fractional-second digits.
scale (integer) –
DECIMAL: digits after the decimal point.
timeZone (string) –
TIMESTAMP only: set when the engine stores an instant, for example
UTC.
rows (list) –
The result rows, in result order. Each row holds a positional list of typed values, one per column.
(dict) –
One result row.
values (list) –
The row’s values, one per column, in column order.
(dict) –
One value. Exactly one member is set, and the column’s
typedetermines which member.Note
This is a Tagged Union structure. Only one of the following top level keys will be set:
nullValue,booleanValue,longValue,doubleValue,stringValue,blobValue,jsonValue. If a client receives an unknown member it will setSDK_UNKNOWN_MEMBERas the top level key, which maps to the name or tag of the unknown member. The structure ofSDK_UNKNOWN_MEMBERis as follows:'SDK_UNKNOWN_MEMBER': {'name': 'UnknownMemberName'}
nullValue (boolean) –
Specifies whether the value is a SQL NULL. Always
truewhen present.booleanValue (boolean) –
A BOOLEAN column value.
longValue (integer) –
A TINYINT, SMALLINT, INTEGER, or BIGINT column value.
doubleValue (float) –
REAL and DOUBLE, except NaN and infinities, which are
stringValue(NaN,Infinity,-Infinity).stringValue (string) –
VARCHAR, and the types whose exact form is text: DECIMAL and unsigned 64-bit integers in plain notation, DATE (
yyyy-MM-dd), TIME and TIMESTAMP (ISO-8601 at the column’s precision;ZwhentimeZoneis set), and INTERVAL (ISO-8601 duration). An UNKNOWN column’s values are NULL. A non-null value of a type the service cannot return fails the request with ValidationException (cast the column to VARCHAR).blobValue (bytes) –
A VARBINARY column value, as binary data.
jsonValue (string) –
An ARRAY, STRUCT, or MAP column value, as JSON text: an array, an object, and an array of
{"key": ..., "value": ...}entries. Nested values follow the same rules, with NULL asnull.
Exceptions
Context.Client.exceptions.ThrottlingExceptionContext.Client.exceptions.ConflictExceptionContext.Client.exceptions.ValidationExceptionContext.Client.exceptions.InternalServerExceptionContext.Client.exceptions.ResourceNotFoundExceptionContext.Client.exceptions.AccessDeniedException