execute_sql
async
¶
execute_sql(
agent_context_id: AgentContextIdentifier,
connection_id: ConnectionIdentifier,
query: SqlDataQuery,
*,
config_overrides: Optional[AsyncContextClientConfig] = None,
) -> ExecuteSqlResponse
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 a LIMIT clause or select fewer columns.
Parameters:
-
agent_context_id(AgentContextIdentifier) –The agent context that owns the connection, by ID or full ARN.
-
connection_id(ConnectionIdentifier) –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(SqlDataQuery) –The query to run: a SQL statement and the AWS Glue tables that it reads. For the SQL rules and limits, see
SqlQuery.
Raises:
-
AccessDeniedException–You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.
-
InternalServerException–The request failed because of an internal error. Retry the request.
-
ThrottlingException–The request was denied because it exceeded a request rate quota. Wait, then retry the request.
-
ValidationException–The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.
-
ConflictException–The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.
-
ResourceNotFoundException–The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
Run a SQL query The following example totals order value by sales region from an AWS Glue table that a connection in the agent context links, and returns the top three sales regions.
>>> await client.execute_sql(agent_context_id='ac-0123456789abcdef0123456789abcdef', connection_id='conn-0123456789abcdef0123456789abcdef', query={'sql': {'statement': 'SELECT "sales_region", SUM("order_total") AS "total_sales" FROM "arn:aws:glue:us-east-1:111122223333:table/sales_analytics/orders" GROUP BY "sales_region" ORDER BY "total_sales" DESC LIMIT 3', 'tables': [{'glueTableArn': 'arn:aws:glue:us-east-1:111122223333:table/sales_analytics/orders'}]}})
Run a SQL query on a connection that isn't linked, which fails with ResourceNotFoundException
The following example fails with ResourceNotFoundException because the connection isn't linked to the agent context.
>>> await client.execute_sql(agent_context_id='ac-0123456789abcdef0123456789abcdef', connection_id='conn-fedcba9876543210fedcba9876543210', query={'sql': {'statement': 'SELECT "order_id" FROM "arn:aws:glue:us-east-1:111122223333:table/sales_analytics/orders" LIMIT 10', 'tables': [{'glueTableArn': 'arn:aws:glue:us-east-1:111122223333:table/sales_analytics/orders'}]}})
Source code in docs_src/capo_context/_services/async_context.py
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 | |