SQL Server → PostgreSQL

Simulating SQL Server Table Variables (@table) in PostgreSQL

DECLARE @table TABLE does not exist in PostgreSQL. Use CREATE TEMP TABLE or CTEs depending on data lifetime.

Table variables in SQL Server live in session memory and disappear when the batch ends. PostgreSQL has no direct equivalent — choose between a temp table or a CTE.

CREATE TEMP TABLE (most common substitute)

SQL Server

DECLARE @tmp TABLE (id int, name text);
INSERT INTO @tmp VALUES (1, 'A');

PostgreSQL

CREATE TEMP TABLE tmp (id int, name text) ON COMMIT PRESERVE ROWS;
INSERT INTO tmp VALUES (1, 'A');

Analisador de Impacto

Scripts full of @table break in bulk during migration. Run free diagnostics to map every occurrence.

Abrir Análise de Projeto →