Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

PG_LAST_QUERY_ID - Amazon Redshift

PG_LAST_QUERY_ID

Returns the query ID of the most recently completed query in the current session. If no queries have been run in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that run exclusively on the leader node. For more information, see Leader node–only functions.

Syntax

pg_last_query_id()

Return type

Returns an integer.

Example

The following query returns the ID of the latest query completed in the current session.

select pg_last_query_id();

Results are the following.

pg_last_query_id ---------------- 5437 (1 row)

The following query returns the query ID and text of the most recently completed query in the current session.

select query, trim(querytxt) as sqlquery from stl_query where query = pg_last_query_id();

Results are the following.

query | sqlquery ------+-------------------------------------------------- 5437 | select name, loadtime from stl_file_scan where loadtime > 1000000; (1 rows)
PrivacySite termsCookie preferences
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.