View a markdown version of this page

Running queries - Amazon Redshift

Amazon Redshift will no longer support the use of Python UDFs after June 30, 2026. We will start enforcing it in phases. For more information on the details of Python end of life and migration options, see the blog post that was published on June 30, 2025.

Running queries

You can run queries on Amazon Redshift Serverless with express configuration from Amazon Redshift query editor v2, the Amazon Redshift Data API, Amazon SageMaker Unified Studio, AWS Quick, or the Amazon Redshift JDBC, ODBC, and Python drivers. You can also attach to the express configuration with the Redshift extension for DuckDB. Before you run queries, register Amazon S3 and Amazon S3 Tables data in the AWS Glue Data Catalog and RMS data through Amazon Redshift federated permissions, and set the IAM permissions for it, as described in Data access and permissions.

In the Amazon Redshift console, the express configuration appears as Amazon Redshift Serverless with express configuration. In the query editor v2 and Amazon SageMaker Unified Studio, the express configuration appears as Redshift Serverless (SQL).

Connecting from the Amazon Redshift console

To query the express configuration from the console
  1. Open the Amazon Redshift Serverless console.

  2. On the Serverless with express configuration view, choose Query your data now. You can also start from the Amazon Redshift console landing page and choose Query Redshift Serverless with express configuration.

    Note

    If you receive a ValidationException because the express configuration isn't activated, activate it first. For more information, see Activating the express configuration.

  3. The query editor v2 opens with the express configuration selected. Under Redshift Serverless (SQL) in the tree, choose the Redshift Catalog, S3 Tables Catalog, or AWS Glue Catalog to expand it and browse the data that you registered. Then run your query.

Connecting from the query editor v2

Use the query editor v2 to run SQL against the express configuration directly in the console, without a separate SQL client.

To query the express configuration from the query editor v2
  1. Open the query editor v2.

  2. In the connection selector, choose Redshift Serverless (SQL).

  3. Select the dev database, and then run your query. Reference your data with three-part names, as shown in the following example:

    SELECT * FROM "awsdatacatalog"."mydatabase"."mytable";

For more information about the query editor v2, see Querying a database using the query editor v2.

Connecting with the Data API

Call the Data API against the regional endpoint to run SQL without managing a persistent connection. With the express configuration, you can authenticate only with IAM, so don't pass a secret ARN or a database user. If you pass neither --workgroup-name nor --cluster-identifier, the Data API uses Amazon Redshift Serverless with express configuration. If the express configuration isn't activated in this AWS Region, activate it first. For more information, see Activating the express configuration. The following AWS CLI command passes the endpoint name express-default explicitly:

aws redshift-data execute-statement \ --workgroup-name express-default \ --database dev \ --sql "SELECT * FROM awsdatacatalog.my_database.my_iceberg_table LIMIT 10"

The --database parameter is optional and defaults to dev.

Retrieve the results with describe-statement and get-statement-result after the statement status is FINISHED. To cancel a running statement, call cancel-statement with the statement ID. For more information about the Data API, see Using the Amazon Redshift Data API. You can discover your data with the Data API metadata operations. ListDatabases returns awsdatacatalog for the AWS Glue Data Catalog, RMS databases as database@catalog, and Amazon S3 table buckets as table-bucket@s3tablescatalog. To list the tables in one of them, pass its name as --database. The following AWS CLI commands list the databases and then the tables in an Amazon S3 table bucket:

aws redshift-data list-databases aws redshift-data list-tables --database table-bucket@s3tablescatalog

For three-part names and SQL discovery commands, see Referencing and discovering your data.

Connecting with JDBC, ODBC, and other SQL clients

With the express configuration, you can connect using JDBC, ODBC, psql, and other PostgreSQL clients on the service-managed regional endpoint on port 5439, over the public endpoint or through AWS PrivateLink. Connect to the dev database on the regional endpoint host, which has the form express-default.express.region.redshift-serverless.amazonaws.com.

The following example shows a JDBC connection URL that uses the jdbc:redshift:iam:// scheme. Replace region with your AWS Region, and profile-name with a named profile from your AWS CLI credentials file.

jdbc:redshift:iam://express-default.express.region.redshift-serverless.amazonaws.com:5439/dev?sslmode=verify-full&Profile=profile-name

The following example shows an ODBC connection string. Replace region with your AWS Region, and profile-name with a named profile from your AWS CLI credentials file.

Driver={Amazon Redshift ODBC Driver (x64)}; Server=express-default.express.region.redshift-serverless.amazonaws.com; Port=5439; Database=dev; IAM=1; Profile=profile-name; SSLMode=verify-full

These examples use the IAM connection forms that the express configuration requires. The JDBC URL uses the jdbc:redshift:iam:// scheme, the ODBC string sets IAM=1, and both name a profile for the AWS credentials. Both set verify-full for TLS host-name verification, which matches the private connectivity example. Don't set a database user name or password in these connection strings. Your IAM identity needs redshift-serverless:GetCredentials and redshift-serverless:DbConnect on the express-default workgroup ARN. For more information about the full permissions, see Data access and permissions.

psql and other PostgreSQL clients don't request credentials themselves. Request a short-lived database user name and password with the AWS CLI get-credentials command, keep them in shell variables, and connect with full TLS verification. The following commands use jq to read the credential. Replace region with your AWS Region:

CREDENTIAL=$(aws redshift-serverless get-credentials --workgroup-name express-default --region region) DB_USER=$(printf '%s' "$CREDENTIAL" | jq -r '.dbUser') export PGPASSWORD=$(printf '%s' "$CREDENTIAL" | jq -r '.dbPassword') psql "host=express-default.express.region.redshift-serverless.amazonaws.com port=5439 dbname=dev user=$DB_USER sslmode=verify-full sslrootcert=/etc/pki/tls/certs/ca-bundle.crt" -c "SELECT current_user, current_database();" unset PGPASSWORD CREDENTIAL DB_USER

Don't print, log, or persist the password. The credential is short-lived, so run get-credentials again when it expires. The sslrootcert path is the CA bundle location on RHEL-family systems. Replace it with your system's CA bundle, for example /etc/ssl/certs/ca-certificates.crt on Debian and Ubuntu or /etc/ssl/cert.pem on macOS.

To reach the endpoint privately from a VPC, use AWS PrivateLink. For more information, see Private connectivity with AWS PrivateLink.

To cancel a running query from a JDBC, ODBC, or psql client, run PG_CANCEL_BACKEND with the process ID of the query's session from another session. The session that runs the query can't cancel it.

To download and install the drivers, see the JDBC, ODBC, and Python driver topics.

Referencing and discovering your data

Reference your data with three-part names. The form depends on the data source, as shown in the following list:

  • For AWS Glue Data Catalog, use the form "awsdatacatalog"."database"."table".

  • For Redshift Managed Storage (RMS) registered through federated permissions, use the form "database@catalog"."schema"."table", for example "dev@my-namespace".public.t1.

  • For Amazon S3 Tables, use the form "table-bucket@s3tablescatalog"."namespace"."table".

To discover what you can query, use the SHOW commands. For AWS Glue Data Catalog data, use SHOW SCHEMAS FROM DATABASE awsdatacatalog. For Redshift Managed Storage and Amazon S3 Tables catalogs, use SHOW CATALOGS and then SHOW DATABASES FROM CATALOG "catalog". You can also use the Data API metadata operations (ListDatabases, ListSchemas, ListTables, and DescribeTable). ListDatabases returns names in the same forms that you use in three-part names.