6.1 Introduction to SQL blocks

Lesson

6.1 Introduction to SQL blocks

Mage SQL Blocks are designed to simplify and optimize SQL-based data operations. They offer a unique blend of flexibility, automation, and integration capabilities that set them apart from traditional SQL execution environments.

Mage SQL blocks offer two methods to execute SQL code and integrate with your databases or warehouses.

  1. Utilize SQL blocks UI to automate integration with target system

  2. Execute raw SQL commands to integrate with target system

Both methods will write data to the target system, however, depending on your use case one you may want to choose the Raw SQL method over utilizing the Mage UI.

The main use case for using the Mage UI is if you need to write a simple query to your database or warehouse. Simple SELECT statements that will not require multiple SQL Statements within a block. If you need to write multiple SQL statements like CREATE TABLE and MERGE then you will need to select the Raw SQL option.

Feature

Raw SQL Block

Automated SQL Block

Multiple statements

Supported

Not Supported

Write policies

Manual implementation

Built-in options

Database specific features

Full Access

Limited to common operations

DDL operations

Supported

Limited

Learning Curve

Requires SQL expertise

More accessible

Error handling

Manual

Partially automated

Code reusability

Higher flexibility

Standardized approach


Connect to upstream data

Mage SQL Blocks simplify the process of accessing data from upstream blocks, a feature that sets it apart from traditional SQL environments. You can directly reference upstream data using simple variables like {{ df_1 }} or {{ df_2 }}, eliminating the need for complex data export and import steps. The upstream block can be a Python, R, or another SQL block. This gives you the flexibility to interchange transformation block types throughout your data pipeline. This seamless integration allows for more dynamic and efficient data pipelines.