Querying a database - Amazon Redshift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Querying a database

To query databases hosted by your Amazon Redshift cluster, you have two options:

  • Connect to your cluster and run queries on the Amazon Web Services Management Console with the query editor.

    If you use the query editor on the Amazon Redshift console, you don't have to download and set up a SQL client application.

  • Connect to your cluster through a SQL client tool, such as SQL Workbench/J.

    Amazon Redshift supports SQL client tools connecting through Java Database Connectivity (JDBC) and Open Database Connectivity (ODBC). Amazon Redshift doesn't provide or install any SQL client tools or libraries, so you must install them on your client computer or Amazon EC2 instance to use them. You can use most SQL client tools that support JDBC or ODBC drivers.

Note

When you write stored procedures, we recommend a best practice for securing sensitive values:

Don't hard code any sensitive information in stored procedure logic. For example, don't assign a user password in a CREATE USER statement in the body of a stored procedure. This poses a security risk, because hard-coded values can be recorded as schema metadata in catalog tables. Instead, pass sensitive values, such as passwords, as arguments to the stored procedure, by means of parameters.

For more information about stored procedures, see CREATE PROCEDURE and Creating stored procedures in Amazon Redshift. For more information about catalog tables, see System catalog tables.

Connecting to Amazon Redshift

You can connect to your database using the following syntax.

cluster-name.account-number.aws-region.redshift.amazonaws.com/database-name

The syntax elements are defined as follows.

  • cluster-name

    Your cluster's name.

  • account-number

    The unique identifier associated with your Amazon account number in a given Amazon Web Services Region. All clusters created by a given account in a given Amazon Web Services Region have the same account-number.

  • aws-region

    The code for the Amazon Web Services Region that the cluster is in.

  • database-name

    Your database's name.

For example, the following connection string specifies the my-db database in the my-cluster cluster in the us-east-1 Amazon Web Services Region.

my-cluster.123456789012.us-east-1.redshift.amazonaws.com/my-db