All skills
aws avatar

/migrating-to-amazon-redshift

@5c779cf

Guides an end-to-end data-warehouse migration to Amazon Redshift — discovery, schema/SQL/stored-procedure/macro/script conversion, data migration, validation, performance comparison, and reporting. Source-routed via `references/<source>/`; Teradata (Vantage) is the supported source; additional sources are added as their own `references/<source>/` sets. Text-only knowledge (no executable code) — the AI generates all execution at runtime. Applies when a user wants to migrate Teradata to Amazon Redshift, convert Teradata DDL/SQL/stored procedures/macros/BTEQ to Redshift/RSQL, or assess Teradata-to-Redshift migration complexity. Applies only to migrations targeting Amazon Redshift; migrations to other platforms (Snowflake, BigQuery, Databricks, etc.) are out of scope regardless of source. Does not cover general Redshift administration, performance tuning, or troubleshooting of existing Redshift clusters (no migration involved), or sources not listed under references/.

Use this Skill: https://skilld.dev/gh/aws/agent-toolkit-for-aws/migrating-to-amazon-redshift

This session only. Nothing lands on disk.

referencesteradatastored-procedure-migration.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Stored Procedure & Macro Migration — Teradata → Redshift PL/pgSQL

Stored procedure rules

Teradata Redshift PL/pgSQL Notes
REPLACE PROCEDURE CREATE OR REPLACE PROCEDURE Add LANGUAGE plpgsql AS $$ … $$
OUT param INOUT param Redshift PL/pgSQL requirement
SET var = ACTIVITY_COUNT GET DIAGNOSTICS var = ROW_COUNT Row count after DML
DECLARE EXIT HANDLER FOR SQLEXCEPTION EXCEPTION WHEN OTHERS THEN Exception block
SQLCODE SQLERRM Text message, no numeric code in RS
DEFAULT param_value (remove) DEFAULT not supported on RS params
FORMAT 'fmt' in params (remove) Not applicable

Macro rules

Classify the macro first — it decides the target and whether the caller changes:

  1. Single-SELECT macro → VIEW (or inline SQL) — preserves the returned result set; no caller change.
  2. Multi-statement, one result set → PROCEDURE returning a refcursor (or a temp table the caller reads) — caller changes from EXEC macro to CALL proc + fetch; flag in manual_review.json.
  3. Multi-statement, multiple result sets → split into N single-cursor PROCEDUREs. Redshift opens only one cursor per session, so one procedure cannot return several refcursors — emit one procedure per result set (verified on the acceptance run). Flag in manual_review.json.
  4. Multi-statement, no result set → PROCEDURE (pattern below).
Teradata Redshift Notes
CREATE/REPLACE MACRO CREATE OR REPLACE PROCEDURE Macros don't exist in RS
:param binding direct variable reference PL/pgSQL uses names directly
DEFAULT values (remove) Not supported
EXEC macro_name CALL procedure_name Execution syntax

PL/pgSQL wrapper template

CREATE OR REPLACE PROCEDURE schema.procedure_name(
    IN p_param1 VARCHAR(100),
    INOUT p_param2 INTEGER
)
LANGUAGE plpgsql
AS $$
DECLARE
    v_row_count INTEGER;
    v_error_msg VARCHAR(500);
BEGIN
    -- body

    GET DIAGNOSTICS v_row_count = ROW_COUNT;
    RAISE INFO 'Step 1 completed: % rows affected', v_row_count;

EXCEPTION WHEN OTHERS THEN
    v_error_msg := SQLERRM;
    RAISE EXCEPTION 'Procedure failed: %', v_error_msg;
END;
$$;

Key paradigm shifts

  • Transaction model: TD auto-commits each statement (outside BT/ET); Redshift atomic SPs (default) wrap everything in one transaction; non-atomic SPs auto-commit each DML/DDL outside BEGIN/COMMIT.
  • Error handling: SQLCODE (numeric) → SQLERRM (text).
  • Logging: prefer RAISE INFO/NOTICE/WARNING over INSERT into log tables (avoids table-level locking). Messages land in SVL_STORED_PROC_MESSAGES (7-day retention); aggregate to permanent tables daily if needed.
  • Parameter defaults: not supported — require all params at the call site.
  • Row count: ACTIVITY_COUNT → GET DIAGNOSTICS var = ROW_COUNT.
  • Cursors: similar syntax but different performance; prefer set-based rewrites.

DECIMAL overflow prevention

param * 0.8 (DECIMAL) can hit 128-bit overflow in Redshift. Cast first:

v_result := CAST(p_amount AS DECIMAL(38,10)) * 0.8;

DATEADD returns TIMESTAMP

Redshift DATEADD returns TIMESTAMP even for DATE input. Cast when DATE is expected:

v_date := CAST(DATEADD(day, 30, v_date) AS DATE);

Multi-statement macro pattern (type 2 — returns a result set)

-- Teradata macro (ends in a SELECT → returns rows to the caller)
REPLACE MACRO schema.my_macro (p_date DATE) AS (
    DELETE FROM staging WHERE load_date < :p_date;
    INSERT INTO staging SELECT * FROM source WHERE load_date = :p_date;
    SELECT COUNT(*) FROM staging WHERE load_date = :p_date;
);

-- Redshift procedure — return the result set via a refcursor (preserves semantics)
CREATE OR REPLACE PROCEDURE schema.my_macro(IN p_date DATE, INOUT rc REFCURSOR)
LANGUAGE plpgsql
AS $$
BEGIN
    DELETE FROM staging WHERE load_date < p_date;
    INSERT INTO staging SELECT * FROM source WHERE load_date = p_date;
    OPEN rc FOR SELECT COUNT(*) FROM staging WHERE load_date = p_date;
END;
$$;
-- caller:  BEGIN; CALL schema.my_macro(DATE '2026-01-01', 'rc'); FETCH ALL FROM rc; COMMIT;

The earlier RAISE INFO form only logs the count — it does not return rows. Use the refcursor (or a temp table the caller reads), and flag type-2 macros in manual_review.json (caller changes from EXEC to CALL + fetch).

Multiple result sets: Redshift allows one open cursor per session, so a macro that returns several result sets cannot become one procedure with N refcursors — split it into N single-cursor procedures (one per result set), each called separately. (On the acceptance run a 3-result-set AML macro became 3 procedures; a 2-result-set macro became 2.)

UDF conversion quick reference

Teradata Redshift
ORDERED_CONCAT LISTAGG
INSTR STRPOS or REGEXP_INSTR
STRTOK_SPLIT_TO_TABLE SPLIT_PART + REGEXP_COUNT
Sel / Format / Substr / Oreplace SELECT / TO_CHAR / SUBSTRING / REPLACE
P_INTERSECT Custom UDF (PERIOD not supported)

Source: SKILL.md on GitHub

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides a structured methodology for migrating data from Teradata to Amazon Redshift, utilizing AI to generate environment-specific scripts at runtime. It incorporates strong security considerations such as identity-based access (IAM), encryption at rest and in transit, and secret management using native cloud services. While the skill utilizes dynamic script generation and external package installation, these are implemented with specific safety instructions like input validation and the use of trusted libraries.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 5c779cf. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 months ago
version
1

README badge

README badge for aws/agent-toolkit-for-aws/migrating-to-amazon-redshift