Skip to content

Commit 099fb37

Browse files
authored
Merge pull request #53132 from MScalopez/postgresql-ai-final
Add Agent and Copilot modules to PostgreSQL LP
2 parents 70a9b8b + 759a7c4 commit 099fb37

38 files changed

Lines changed: 813 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.enhance-postgresql-development-github-copilot-visual-studio-code.introduction
3+
title: Introduction
4+
metadata:
5+
title: Introduction
6+
description: Learn how GitHub Copilot and the PostgreSQL extension enhance SQL development in Visual Studio Code.
7+
author: wwlpublish
8+
ms.author: calopez
9+
ms.date: 12/08/2025
10+
ms.topic: unit
11+
durationInMinutes: 3
12+
content: |
13+
[!include[](includes/01-introduction.md)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.enhance-postgresql-development-github-copilot-visual-studio-code.understand-postgresql-extension
3+
title: Understand how the PostgreSQL extension supports SQL development
4+
metadata:
5+
title: Understand how the PostgreSQL extension supports SQL development
6+
description: Learn how the PostgreSQL extension enables connecting, browsing objects, and running SQL inside Visual Studio Code.
7+
author: wwlpublish
8+
ms.author: calopez
9+
ms.date: 12/08/2025
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/02-understand-postgresql-extension.md)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.enhance-postgresql-development-github-copilot-visual-studio-code.understand-github-copilot-integration
3+
title: Understand how GitHub Copilot integrates with the PostgreSQL extension
4+
metadata:
5+
title: Understand how GitHub Copilot integrates with the PostgreSQL extension
6+
description: Learn how GitHub Copilot provides inline SQL suggestions through the PostgreSQL extension in Visual Studio Code.
7+
author: wwlpublish
8+
ms.author: calopez
9+
ms.date: 12/08/2025
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/03-understand-github-copilot-integration.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.enhance-postgresql-development-github-copilot-visual-studio-code.generate-refine-queries
3+
title: Use GitHub Copilot to generate, refine, and troubleshoot SQL queries
4+
metadata:
5+
title: Use GitHub Copilot to generate, refine, and troubleshoot SQL queries
6+
description: Learn how GitHub Copilot helps generate, refine, and troubleshoot SQL queries by using database-aware prompts in Visual Studio Code.
7+
author: wwlpublish
8+
ms.author: calopez
9+
ms.date: 12/08/2025
10+
ms.topic: unit
11+
durationInMinutes: 6
12+
content: |
13+
[!include[](includes/04-generate-refine-queries.md)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.enhance-postgresql-development-github-copilot-visual-studio-code.exercise-enhance-postgresql-development-github-copilot
3+
title: Exercise - Enhance PostgreSQL development with GitHub Copilot
4+
metadata:
5+
title: Exercise - Enhance PostgreSQL development with GitHub Copilot
6+
description: Use the PostgreSQL extension and GitHub Copilot to generate, explain, and fix SQL queries in Visual Studio Code.
7+
author: wwlpublish
8+
ms.author: calopez
9+
ms.date: 12/08/2025
10+
ms.topic: unit
11+
durationInMinutes: 30
12+
content: |
13+
[!include[](includes/05-exercise-enhance-postgresql-development.md)]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.enhance-postgresql-development-github-copilot-visual-studio-code.knowledge-check
3+
title: Knowledge check
4+
metadata:
5+
title: Knowledge check
6+
description: "Knowledge check"
7+
ms.date: 12/16/2025
8+
author: wwlpublish
9+
ms.author: calopez
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
quiz:
14+
title: "Check your knowledge"
15+
questions:
16+
- content: What primary capability does the PostgreSQL extension add to Visual Studio Code?
17+
choices:
18+
- content: A built-in PostgreSQL server that runs locally
19+
isCorrect: false
20+
explanation: Incorrect. The extension connects to existing PostgreSQL databases; it doesn't host a server.
21+
- content: Database connections, object exploration, query execution, and results viewing inside the editor
22+
isCorrect: true
23+
explanation: Correct. The extension adds core PostgreSQL management and development tools to Visual Studio Code.
24+
- content: Automatic schema migrations for PostgreSQL databases
25+
isCorrect: false
26+
explanation: Incorrect. Schema migrations aren't a built-in feature of the extension.
27+
- content: What type of context does the @pgsql Copilot participant provide?
28+
choices:
29+
- content: The PostgreSQL database schema and metadata from the active connection
30+
isCorrect: true
31+
explanation: Correct. @pgsql uses the connected database context.
32+
- content: The contents of the SQL query editor
33+
isCorrect: false
34+
explanation: Incorrect. Query editor context is separate from database context.
35+
- content: Application source code in the workspace
36+
isCorrect: false
37+
explanation: Incorrect. @pgsql focuses on database context.
38+
- content: Which workflow best represents how the PostgreSQL extension and GitHub Copilot are used together?
39+
choices:
40+
- content: Copilot executes queries first, then the extension displays results
41+
isCorrect: false
42+
explanation: Incorrect. Developers control execution through the extension.
43+
- content: Copilot assists with generating or refining SQL, and the extension executes and displays results
44+
isCorrect: true
45+
explanation: Correct. Copilot provides guidance, and the extension handles execution and results.
46+
- content: The extension generates SQL, and Copilot only formats it
47+
isCorrect: false
48+
explanation: Incorrect. SQL generation assistance comes from Copilot.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.enhance-postgresql-development-github-copilot-visual-studio-code.summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: Review what you learned about enhancing PostgreSQL development with GitHub Copilot in Visual Studio Code.
7+
author: wwlpublish
8+
ms.author: calopez
9+
ms.date: 12/08/2025
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/07-summary.md)]
14+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Developing PostgreSQL solutions in Visual Studio Code involves more than writing SQL queries. Developers need to connect to databases, explore schemas and tables, run queries, and review results as part of their daily work. The PostgreSQL extension provides these capabilities directly inside Visual Studio Code. GitHub Copilot builds on this experience by offering AI-assisted help that uses the context of the connected PostgreSQL database.
2+
3+
Together, the PostgreSQL extension and GitHub Copilot support common PostgreSQL development tasks without requiring developers to switch to separate database tools. This approach keeps database work close to application code and helps teams stay focused while developing, testing, and refining PostgreSQL solutions.
4+
5+
Consider a rental agency called Margie’s Travel. The development team builds and maintains applications that rely on Azure Database for PostgreSQL to manage listings, reservations, and customer reviews. Their day-to-day work includes inspecting tables, writing and testing queries, investigating unexpected results, and refining SQL to meet application requirements. By using the PostgreSQL extension and GitHub Copilot inside Visual Studio Code, the Margie’s Travel team can explore database objects, generate and adjust SQL queries, and review results while working in a single development environment.
6+
7+
After completing this module, you’ll be able to:
8+
9+
- Explain how the PostgreSQL extension adds PostgreSQL database capabilities to Visual Studio Code.
10+
- Describe how GitHub Copilot integrates with the PostgreSQL extension to provide database-aware assistance.
11+
- Use Copilot Chat to generate and refine SQL queries based on natural-language prompts.
12+
- Execute SQL queries and review results using the PostgreSQL extension’s built-in tools.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
The PostgreSQL extension for Visual Studio Code provides a comprehensive set of tools for managing and developing PostgreSQL databases directly within the editor. It allows developers to connect to local or cloud-hosted PostgreSQL databases, explore database objects, write and execute SQL queries, and review query results without leaving Visual Studio Code. This integrated experience simplifies common database tasks and reduces the need to switch between separate tools.
2+
3+
Consider the Margie’s Travel scenario. The team works with Azure Database for PostgreSQL to store information such as reservations, listings, and customer data. By using the PostgreSQL extension inside Visual Studio Code, developers can connect to these databases, inspect tables and schemas, and validate SQL changes while continuing to work in the same development environment as their application code.
4+
5+
## Identify core capabilities
6+
7+
The PostgreSQL extension provides several core capabilities that support everyday PostgreSQL development and management tasks.
8+
9+
- **Connection management**
10+
Developers can create and save connections to PostgreSQL databases using connection details or connection strings. The extension supports connections to local databases as well as cloud-hosted databases, including Azure Database for PostgreSQL. Saved connections appear in the extension sidebar, making it easy to reconnect during future sessions.
11+
12+
- **Object Explorer**
13+
The Object Explorer presents a hierarchical view of database objects. Developers can expand a database to browse schemas, tables, views, functions, and stored procedures. This view makes it easier to understand database structure and locate the objects needed for development or troubleshooting.
14+
15+
- **Query Editor**
16+
The Query Editor provides a dedicated space for writing and executing SQL queries. Features such as syntax highlighting and context-aware IntelliSense help developers write queries more accurately and efficiently. Developers can launch new queries directly from database objects in the Object Explorer.
17+
18+
- **Results Viewer**
19+
Query results are displayed in the Results Viewer, where developers can search, filter, and sort returned data. Results can also be exported to formats such as CSV, JSON, or Excel for further analysis or sharing.
20+
21+
Together, these capabilities allow developers to move seamlessly from connecting to a database, to exploring its structure, to writing and validating SQL queries.
22+
23+
## Explore how developers use the extension
24+
25+
Developers install the PostgreSQL extension from the Visual Studio Code Extensions Marketplace and add a connection to a PostgreSQL database. Connections can be tested before saving, and successful connections are stored for reuse.
26+
27+
Once connected, developers use the Object Explorer to navigate database objects and understand how data is organized. From the Object Explorer, they can open a new query window, write SQL in the Query Editor, and execute the query against the connected database. Query results are immediately displayed in the Results Viewer, allowing developers to verify output or refine the query.
28+
29+
At Margie’s Travel, a developer might connect to the reservations database, expand the schemas to locate tables related to bookings, and run a query to confirm that recent updates were applied correctly. This workflow keeps database exploration, query execution, and result review within a single tool.
30+
31+
## Recognize workflow benefits
32+
33+
Using the PostgreSQL extension keeps database activities inside Visual Studio Code. Developers can connect to databases, explore objects, write SQL queries, execute them, and review results without switching to an external database client. This reduces context switching and supports a more focused development experience.
34+
35+
For Margie’s Travel, this integrated workflow helps developers validate changes more quickly, troubleshoot issues efficiently, and maintain consistency when working with both local PostgreSQL databases and Azure Database for PostgreSQL instances.
36+
37+
## What you’ve learned
38+
39+
You learned how the PostgreSQL extension supports PostgreSQL development in Visual Studio Code. You explored how developers connect to PostgreSQL databases, browse database objects, write and execute SQL queries, and review results using the extension’s built-in tools. These capabilities form the foundation for more advanced workflows, including GitHub Copilot integration in later units.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
GitHub Copilot integrates with the PostgreSQL extension in Visual Studio Code to provide AI-assisted database development. After connecting to a PostgreSQL database, Copilot can access contextual information from the live connection. This allows the `@pgsql` Copilot chat participant to generate schema-aware SQL queries and insights while developers remain in Visual Studio Code.
2+
3+
Consider the Margie’s Travel scenario. Developers work with PostgreSQL databases that store property listings and customer reviews. Copilot helps them understand database structures, generate SQL queries, and manage schema changes while keeping development work centralized in the editor.
4+
5+
## Identify the Copilot integration surface
6+
7+
The PostgreSQL extension exposes GitHub Copilot capabilities through Copilot Chat. Developers begin by right-clicking a database connection and selecting **Chat with this database**. When the Copilot chat interface opens, developers use the `@pgsql` prefix to ensure that Copilot responds using PostgreSQL database context.
8+
9+
Copilot uses information from the active connection to tailor its responses, enabling more relevant guidance than general-purpose AI assistance.
10+
11+
In addition to Copilot Chat, Copilot features can also be accessed from the editor by selecting SQL code and using right-click context menu options such as **Explain**, **Generate Code**, or **Open Inline Chat**.
12+
13+
## Understand the types of tasks Copilot supports
14+
15+
GitHub Copilot integration for PostgreSQL supports a range of database development tasks. These tasks span both read and write scenarios and are designed to reduce manual effort while keeping developers in control.
16+
17+
Common task categories include:
18+
19+
- **Exploring database structures**, such as tables, columns, and schemas.
20+
- **Generating SQL queries**, including queries for reporting, filtering, and aggregation.
21+
- **Assisting with schema changes**, such as creating or modifying tables and columns.
22+
- **Providing explanations and insights**, such as describing how a query works or identifying potential improvements.
23+
- **Query optimization**, where developers ask for help refining queries or resolving errors.
24+
- **Performance optimization**, such as guidance related to indexing, schema design, or query behavior.
25+
- **App development**, where Copilot helps generate SQL queries or database-related logic used by applications.
26+
27+
These capabilities allow developers to work more efficiently with PostgreSQL databases while staying within their existing development workflow.
28+
29+
## Use Copilot Chat for more than just PostgreSQL
30+
31+
While using `@pgsql` focuses on PostgreSQL-specific tasks, developers can also use Copilot Chat for general coding assistance. This includes writing application code, generating documentation, or addressing non-database-connected questions. The ability to switch between database-focused and general-purpose assistance makes Copilot Chat a versatile tool within Visual Studio Code.
32+
33+
If you preface your prompts with `@pgsql`, Copilot will respond with PostgreSQL-specific context. If you do not use the prefix, Copilot will provide general coding assistance. For example:
34+
35+
> `@pgsql How do I create an index on the listings table for the price column?`
36+
37+
Would yield a PostgreSQL-specific response, while:
38+
39+
> `How do I write a function in Python to connect to my PostgreSQL database?`
40+
41+
Would yield a general Python coding response.
42+
43+
Because both prompt types are accessible in the same chat interface, developers can fluidly switch between database and application development tasks pointing to the same context.
44+
45+
## Explore GitHub Copilot agent mode
46+
47+
So far we have focused on using Copilot Chat in a question-and-answer format. GitHub Copilot Chat also supports an ***agent mode*** that can autonomously perform multi-step database tasks.
48+
49+
GitHub Copilot Chat agent mode provides a database context aware intelligent assistant that can perform multi-stage tasks, moving beyond the question-and-answer chat experience. Agent mode enables Copilot to draw on additional workspace context and, when allowed, to independently generate and correct code. This capability supports PostgreSQL development by helping with tasks such as building application prototypes, diagnosing issues, adjusting database structures, and improving query performance.
50+
51+
## Understand safeguards and developer responsibility
52+
53+
Because Copilot can propose SQL that reads from or writes to the database, it includes safeguards to prevent unintended changes. For operations that modify data or schemas, Copilot requests explicit permission and confirmation before executing any SQL.
54+
55+
Developers are responsible for reviewing all generated SQL queries and schema changes before approval. This review step is especially important when working in staging or production environments.
56+
57+
At Margie’s Travel, this model ensures that Copilot improves productivity while maintaining control over database integrity and operational risk.
58+
59+
## What you’ve learned
60+
61+
In this unit, you learned how GitHub Copilot integrates with the PostgreSQL extension in Visual Studio Code. You learned where the integration appears, the types of database tasks it supports, and how confirmation and review help developers safely use Copilot for PostgreSQL development.

0 commit comments

Comments
 (0)