Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

pg_sqlgen is a database extension for PostgreSQL that enables text-to-sql functionality. It is based on the Dubo-SQL method for fine-tuned Text-to-SQL generation.

As an extension, pg_sqlgen provides a number of advantages over other text-to-sql solutions, including:

  • Performance, eliminates network round-trips and connection overhead.
  • Security and data locality, no data is sent over a network or to an external service.
  • Authorization, everything lives within Postgres’ permission model instead of an external service.
  • Consistency, real-time RAG metadata maintenance via triggers.

Features

  • Simple text-to-sql generation via sqlgen.generate().
  • Explain what queries do and how they work via sqlgen.explain_query().
  • Continuous schema-change capture through extension-managed triggers.
  • Support for multiple model APIs
  • Support for multiple independent text-to-SQL engines with isolated RAG metadata.