Different Redshift Join Types and Examples

SQL Join is a clause that is used for combining specific fields from two or more tables based on the common columns available. Joins are used to combine rows from multiple tables. In this article, we will learn about different Redshift join types with some examples. Below are the tables that we will be using to demonstrate different Join types available in Redshift: Students: Id   name   city 1    AAA    London 2    BBB    Mumbai 3    CCC    Bangalore 4    DDD    Mumbai 5    EEE     Bangalore Dept: Did  name    sid 100  CS       1 101 …

Continue ReadingDifferent Redshift Join Types and Examples
2 Comments

Amazon Redshift Extract Numbers using Regular Expressions

Amazon Redshift supports various built in functions, you can use them to extract the numbers, alphanumeric or specific patters from strings. In this article, we will discuss about Redshift extract numbers using regular expressions and examples. In data warehouse environment, you may have different types data files extracted from different data sources. Data might be corrupted or may have unwanted characters, you can clean such a data using Redshift regular expressions. You can read about regular expression in my other post: Redshift Regular Expression Functions and Examples Redshift Extract Numbers…

Continue ReadingAmazon Redshift Extract Numbers using Regular Expressions
Comments Off on Amazon Redshift Extract Numbers using Regular Expressions

Redshift NVL and NVL2 Functions with Examples

Like many other relational database or data warehouse appliances, Redshift supports NVL and NVL2 functions. These functions are mainly used to handle the null values in Redshift tables. Redshift NVL Function An NVL expression returns the value of the first expression in the list that is not null. The NVL function replaces a NULL value with a replacement string that you provide in the function as argument. This function returns the first argument if it is not null, otherwise the second argument. The Redshift NVL function is equivalent to the…

Continue ReadingRedshift NVL and NVL2 Functions with Examples
Comments Off on Redshift NVL and NVL2 Functions with Examples

How Redshift Distributes Table Data? Importance of right Distribution Key

Amazon Redshift uses the Massively parallel processing technique, Redshift automatically distributes data and query load across all nodes available in the cluster. In this article, we will check how Redshift distributes table data and importance of right distribution key. How Redshift distributes Table Data? Amazon Redshift uses the three types of distribution; EVEN, KEY and ALL. When you create tables you will have to tell the system which distribution it should use. You may read about distribution types and best practices: Amazon Redshift Distribution Types and Examples If you specify…

Continue ReadingHow Redshift Distributes Table Data? Importance of right Distribution Key
Comments Off on How Redshift Distributes Table Data? Importance of right Distribution Key

Redshift ROWNUM Pseudo Column Alternative

There is no ROWNUM pseudo column in Redshift. If you are coming from Oracle database background, you will find it difficult in Redshift without ROWNUM pseudo column. The one possible solution to this is ROW_NUMBER() analytical function as Redshift ROWNUM pseudo column alternative. ROWNUM is sometime useful when you are working with multi-level SQL queries. You can restrict the rows using ROW_NUMBER functions. Read: Redshift String Functions and Examples Amazon Redshift Date Functions and Examples Redshift Analytics Functions and Examples Redshift also support a LIMIT clause to restrict the output.…

Continue ReadingRedshift ROWNUM Pseudo Column Alternative
1 Comment

Amazon Redshift Date Format Conversion and Examples

Date data type is one of the complicated type is database. Date data types are used to store the date and time fraction values. Amazon Redshift Date format includes four data types, and are used to store the date with time details: DATE: for year, month, day storage. TIME: for hour, minute, second, fraction with (includes 6 decimal positions). TIMESTAMPTZ: same as TIME, also includes time zone information. TIMESTAMP: for year, month, day, hour, minute, second, fraction (includes 6 decimal positions). Amazon Redshift Date Format Conversion Redshift can convert quoted…

Continue ReadingAmazon Redshift Date Format Conversion and Examples
Comments Off on Amazon Redshift Date Format Conversion and Examples

Redshift SET ON_ERROR_STOP using psql and Examples

On Redshift data warehouse appliance, you will be executing multiple SQL statement in single SQL file. In this article, we will discuss about the Redshift SET ON_ERROR_STOP variable to stop the execution in case one of the sql statement encountered error inside SQL script file. Without setting this system variable, Amazon Redshitf will continue with other statements ignoring the failed query. PostgreSQL (psql) EXIT Status psql returns following EXIT status when you are executing Redshfit SQL from files: 0: to the shell if it finished sql execution normally. 1: if…

Continue ReadingRedshift SET ON_ERROR_STOP using psql and Examples
Comments Off on Redshift SET ON_ERROR_STOP using psql and Examples

Run Redshift SQL Script File using psql Variable Substitution

PostgreSQL or psql allows the variable substitution using -v option in Redshift sql query files. The variable substitution is very important when you are calling the Redshift sql scripts from shell or any other scripting language. You can pass the values to query that you are calling using -v option. In this article, we will see how to run Redshift sql script file using psql variable substitution. We also see some of the working examples that uses the psql variable substitution method. Run Redshift SQL Script File using psql Variable…

Continue ReadingRun Redshift SQL Script File using psql Variable Substitution
2 Comments

Amazon Redshift Create View Syntax and Examples

A View creates a pseudo-table or virtual table. It appears exactly as a regular table, you can use it in SELECT statements, JOINs etc. A view can be created from a subset of rows or columns of another table, or many tables via a JOIN. Redshift uses the CREATE VIEW statement from PostgreSQL syntax to create View. In this article, we will check Redshift create view syntax and some examples on how to create views. Just like views or table  in other database, a Redshift view contains rows and columns.…

Continue ReadingAmazon Redshift Create View Syntax and Examples
Comments Off on Amazon Redshift Create View Syntax and Examples

Amazon Redshift Hash Functions and Examples

You can use Amazon Redshift hash functions to encode the data by transforming the input into a hash code or hash values. If you use the hash function, no two inputs have same hash values. The hash algorithm are designed to minimize the collision (two inputs having same hash value). You can use the hash function to speed up the data record retrieval by using simple one way lookup. Hash code is used as an index into a hash table which has a pointer to data records. Redshift hash function…

Continue ReadingAmazon Redshift Hash Functions and Examples
2 Comments