Converting T-SQL code to PL/pgSQL with confidence

Google Cloud Tech · Beginner ·🔧 Backend Engineering ·2mo ago

Key Takeaways

Converting T-SQL code to PL/pgSQL using Database Migration Service (DMS) and understanding the performance benefits of refactored code, with explanations from Gemini, a trusted AI tutor on Google Cloud.

Full Transcript

You'll find stored procedures like this, complex [music] multi-step processes that rely on temporary tables or cursors to get the job done. They work, but they're often inefficient and don't translate well to modern database patterns. >> [music] >> A basic conversion tool might copy that logic line for line. Functional? Sure, but efficient? Not really. But what if your tool could act as a virtual architect, refactoring your code into better, more performant patterns? [music] Here we have a T-SQL procedure called get high value customers. It creates a temporary table, inserts some initial data, and updates it with more information before selecting the result. It's a classic procedural pattern. Now let's look at the conversion with Database Migration Service or DMS on the right. It hasn't created a temporary table. Instead, [music] it's refactored the entire multi-step process into a single elegant Postgres function using a common table expression or CTE. This isn't just [music] a translation, it's an intelligent modernization. DMS recognized the intent of the code and implemented it using a superior pattern. >> [music] >> But why is this better? Let's ask Gemini. Gemini's explanation is spot on. It tells us that the temporary table was refactored into a CTE [music] to promote a set-based approach, which is the standard way to do it in Postgres. It also dives in on the performance benefits. This allows the Postgres query planner to see the entire operation as a single unit, creating a much more efficient execution plan, and reducing IO compared to writing to and reading from a physical temporary table. DMS just taught us a performance tuning technique. DMS isn't just converting code, it's explaining and guiding you towards modern, maintainable, performant patterns with clear [music] intent and best practices built in. Ready to refactor and modernize your most complex legacy code? Let DMS help you modernize as you migrate. Check out the link in the description below. >> [music]

Original Description

Database Migration Service → https://goo.gle/48NKXTj Developers migrating apps to the cloud who need to convert database schemas and code to PostgreSQL, or anyone looking to improve PostgreSQL skills, can rely on Gemini as a trusted AI tutor on Google Cloud. Watch along to learn how to convert T-SQL code into PL/pgSQL, focusing on tricky situations like refactoring a T-SQL procedure into a PostgreSQL Common Table Expression. Gemini doesn't just convert code—it explains how the process works so developers can become PostgreSQL experts too. Watch more Gemini taught me PostgreSQL → https://goo.gle/ai-postgres-tutor 🔔 Subscribe to Google Cloud Tech → https://goo.gle/GoogleCloudTech #GoogleCloud #PostgreSQL Speakers: Gabe Weiss Products Mentioned: Database Migration Service, Gemini
Sign in to unlock AI tutor explanation · ⚡30

Learn how to convert T-SQL code to PL/pgSQL using Database Migration Service (DMS) and understand the performance benefits of refactored code, with explanations from Gemini, a trusted AI tutor on Google Cloud. This lesson covers the basics of database migration, code refactoring, and performance optimization.

Key Takeaways
  1. Identify the need for database migration
  2. Use DMS to convert T-SQL code to PL/pgSQL
  3. Understand the performance benefits of refactored code
  4. Apply CTEs for efficient queries
  5. Optimize database performance
💡 Refactoring code using DMS can lead to significant performance improvements by promoting a set-based approach and reducing IO operations.

Related Reads

Up next
OOP Concepts Explained|Object-Oriented Programming in 60 Seconds| #Shorts | #Simplilearn
Simplilearn
Watch →