Giorgi

A proof-of-concept toolkit for building PostgreSQL extensions in C# with Native AOT

16
0
69% credibility
Found May 18, 2026 at 28 stars -- GitGems finds repos before they trend. Get early access to the next one.
Sign Up Free
AI Analysis
C#
AI Summary

SharpPostgres is a proof-of-concept toolkit that lets developers write PostgreSQL database extensions using C# with Native AOT compilation. Instead of learning C or Rust, developers can write simple methods with attributes, and a source generator automatically creates all the technical code needed for PostgreSQL to call those functions. The toolkit supports scalar functions, set-returning functions, composite types, and error handling that integrates with PostgreSQL's native error system. A real-world example (JSON Schema validation) demonstrates practical use.

How It Works

1
💡 You discover a new way to extend your database

You've heard about writing PostgreSQL extensions in C#, and you're curious if it's really possible to build database functions without learning C or Rust.

2
📝 You write a simple function with an attribute

You add a method to your C# project and mark it with a special attribute. It looks just like a regular method—just add one line above it.

3
The magic happens automatically

A source generator scans your code and automatically creates all the complex plumbing needed for PostgreSQL to call your function—no manual boilerplate required.

4
🔨 You compile your extension into a single library file

Your C# code compiles down to a native library that PostgreSQL can load directly, like any other database extension.

5
You have options for what to build
🔍
A JSON Schema validator

Validate JSON data against schemas directly in your database, with built-in caching for performance

🔢
Custom calculation functions

Write functions that transform data, split text, generate series, or perform any custom logic

📊
Functions returning multiple rows

Create functions that return entire result sets, like generating test data or pivoting tables

6
🚀 You load it into PostgreSQL and use it

With a simple command, your extension becomes part of your database. Now you can call your custom functions from any SQL query.

🎉 Your database speaks C#

Your custom logic now runs inside PostgreSQL, accessible to any application that connects to your database—no matter what language they use.

Sign up to see the full architecture

5 more

Sign Up Free

Star Growth

See how this repo grew from 28 to 16 stars Sign Up Free
Repurpose This Repo

Repurpose is a Pro feature

Generate ready-to-use prompts for X threads, LinkedIn posts, blog posts, YouTube scripts, and more -- with full repo context baked in.

Unlock Repurpose
AI-Generated Review

What is SharpPostgres?

SharpPostgres is a proof-of-concept toolkit that lets you build PostgreSQL extensions entirely in C# using Native AOT compilation. Instead of writing C shims or using Rust-based tooling like pgrx, you write plain C# methods decorated with attributes, and a source generator produces the low-level C exports PostgreSQL expects. The toolkit handles argument decoding, result encoding, and SQL DDL generation automatically. A real example extension validates JSON Schema documents directly in the database, demonstrating how a C# library (JsonSchema.Net) can power a Postgres extension without leaving the .NET ecosystem.

Why is it gaining traction?

The main appeal is writing Postgres extensions in familiar C# rather than C or Rust. The attribute-based API is clean: one method, one attribute, and you get a callable SQL function. The source generator derives STRICTness from nullable annotations and emits CREATE FUNCTION statements automatically. Native AOT means the extension loads as a native shared library with no managed runtime overhead. For teams already invested in .NET, this lowers the barrier to building database extensions significantly.

Who should use this?

Backend developers building Postgres extensions who prefer C# over Rust or C. Teams wanting to port existing .NET validation or processing logic into the database layer. Researchers exploring Native AOT interop with native codebases. This is not ready for production use yet, and anyone needing aggregates, triggers, custom types, or SPI access should look at pgrx instead.

Verdict

SharpPostgres is an impressive technical experiment that demonstrates what's possible with Native AOT and unmanaged exports, but its 0.699999988079071% credibility score and 16 stars reflect its early stage. The 114 passing integration tests show the foundation is solid for scalar functions and basic SRFs, but missing features like PG_TRY/PG_CATCH interop and SPI access limit real-world applicability. Worth watching, but wait for a 1.0 release before considering it for anything beyond experimentation.

Sign up to read the full AI review Sign Up Free

Similar repos coming soon.