Home icon

Migrate SQL Server multi-result-set procedures to PostgreSQL

Database Blog



This article explains how to migrate SQL Server multi-result-set stored procedures to PostgreSQL, which doesn't natively support returning multiple independent result sets from a single procedure call.

  • SQL Server procedures return multiple result sets via separate SELECT statements; PostgreSQL requires alternative patterns
  • Temporary tables approach: procedure creates session-scoped tables, caller reads them sequentially in same transaction
  • JSON aggregation approach: function returns all result sets in single structured JSON document with named arrays
  • Temporary tables suit large result sets and row-by-row retrieval; JSON aggregation suits bounded results and single-response patterns
  • Performance testing shows JSON faster at 100-1,000 rows per result set; temporary tables 31% faster at 10,000 rows
  • Includes .NET/Npgsql code examples, validation strategies, and operational considerations for transactions and connection pooling

Choose the approach based on result-set size, retrieval patterns, and application requirements, then validate functional equivalence before production deployment.



Go to article

The AWS News Feed is currently looking for gold sponsors. If you want to support the AWS community and reach a large audience of AWS professionals, consider sponsoring the AWS News Feed.

Related articles

Aug 20
2026
Migrate multilingual full-text search from SQL Server to PostgreSQL
Jan 30
2024
Use the tds_fdw extension to migrate data from SQL Server to PostgreSQL
Sep 1
2026
SQL Server to Aurora PostgreSQL conversion with AI agents for AWS DMS
Aug 7
2026
Migrating and Modernizing Oracle Databases to PostgreSQL on AWS – Part 3: Planning and Execution

The AWS News Feed is currently looking for silver sponsors. If you want to support the AWS community and reach a large audience of AWS professionals, consider sponsoring the AWS News Feed.