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.
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
2026
2024
2026
2026
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.