You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio Code的.NET Interactive Notebook中查询PostgreSQL数据库?

Querying PostgreSQL with .NET Interactive Notebooks in VS Code

Got it, replicating your SQL Server workflow for PostgreSQL in VS Code using .NET Interactive Notebooks is straightforward—here’s the step-by-step breakdown:

  • Install the required extension (same as with SQL Server): Make sure you have the .NET Interactive Notebooks extension installed in VS Code. If not, grab it from the Extensions marketplace.
  • Create a blank notebook: Press Ctrl+P, then select .NET Interactive: Create new blank notebook to generate a notebook with the .dib file extension.
  • Set up the PostgreSQL connection in a C# cell:
    1. First, load the PostgreSQL NuGet package for .NET Interactive by running this line:
      #r "nuget:Microsoft.DotNet.Interactive.PostgreSQL,*-*"
      
    2. Next, establish a connection to your PostgreSQL database using the #!connect magic command. Replace the placeholder values with your actual database credentials:
      #!connect postgresql "Host=your-db-host;Username=your-username;Password=your-password;Database=your-target-db" --kernel-name postgres-db
      
      The --kernel-name flag is optional but useful if you want to name your connection for clarity (you can reference it later if needed).
  • Run PostgreSQL queries in a SQL cell:
    Add a new cell, switch its kernel to SQL (.NET Interactive) (it should automatically associate with your PostgreSQL connection if you set it up correctly), then write and execute your PostgreSQL-specific SQL. For example:
    SELECT * FROM your_table LIMIT 10;
    

That’s all! The workflow mirrors your SQL Server setup—just swapped out the NuGet package and connection command to target PostgreSQL instead.

内容的提问来源于stack exchange,提问作者Wallace

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 18:22:51