# Table of Contents - [sqlc Documentation — sqlc 1.31.1 documentation](#sqlc-documentation-sqlc-1-31-1-documentation) - [sqlc Documentation — sqlc 1.31.1 documentation](#sqlc-documentation-sqlc-1-31-1-documentation) - [sqlc Documentation — sqlc 1.31.0 documentation](#sqlc-documentation-sqlc-1-31-0-documentation) - [sqlc Documentation — sqlc 1.31.1 documentation](#sqlc-documentation-sqlc-1-31-1-documentation) - [sqlc Documentation — sqlc 1.27.0 documentation](#sqlc-documentation-sqlc-1-27-0-documentation) - [sqlc Documentation — sqlc 1.30.0 documentation](#sqlc-documentation-sqlc-1-30-0-documentation) - [sqlc Documentation — sqlc 1.29.0 documentation](#sqlc-documentation-sqlc-1-29-0-documentation) - [sqlc Documentation — sqlc 1.28.0 documentation](#sqlc-documentation-sqlc-1-28-0-documentation) - [sqlc Documentation — sqlc 1.26.0 documentation](#sqlc-documentation-sqlc-1-26-0-documentation) - [sqlc Documentation — sqlc 1.25.0 documentation](#sqlc-documentation-sqlc-1-25-0-documentation) - [sqlc Documentation — sqlc 1.24.0 documentation](#sqlc-documentation-sqlc-1-24-0-documentation) - [sqlc Documentation — sqlc 1.19.0 documentation](#sqlc-documentation-sqlc-1-19-0-documentation) - [sqlc Documentation — sqlc 1.19.1 documentation](#sqlc-documentation-sqlc-1-19-1-documentation) - [sqlc Documentation — sqlc 1.23.0 documentation](#sqlc-documentation-sqlc-1-23-0-documentation) - [sqlc Documentation — sqlc 1.22.0 documentation](#sqlc-documentation-sqlc-1-22-0-documentation) - [sqlc Documentation — sqlc 1.18.0 documentation](#sqlc-documentation-sqlc-1-18-0-documentation) - [sqlc Documentation — sqlc 1.17.2 documentation](#sqlc-documentation-sqlc-1-17-2-documentation) - [sqlc Documentation — sqlc 1.20.0 documentation](#sqlc-documentation-sqlc-1-20-0-documentation) - [sqlc Documentation — sqlc 1.17.1 documentation](#sqlc-documentation-sqlc-1-17-1-documentation) - [sqlc Documentation — sqlc 1.17.0 documentation](#sqlc-documentation-sqlc-1-17-0-documentation) - [sqlc Documentation — sqlc 1.21.0 documentation](#sqlc-documentation-sqlc-1-21-0-documentation) - [sqlc Documentation — sqlc 1.16.0 documentation](#sqlc-documentation-sqlc-1-16-0-documentation) - [sqlc Documentation — sqlc 1.12.0 documentation](#sqlc-documentation-sqlc-1-12-0-documentation) - [sqlc Documentation — sqlc 1.14.0 documentation](#sqlc-documentation-sqlc-1-14-0-documentation) - [sqlc Documentation — sqlc 1.15.0 documentation](#sqlc-documentation-sqlc-1-15-0-documentation) - [sqlc Documentation — sqlc 1.12.0 documentation](#sqlc-documentation-sqlc-1-12-0-documentation) - [sqlc Documentation — sqlc 1.10.0 documentation](#sqlc-documentation-sqlc-1-10-0-documentation) - [sqlc Documentation — sqlc 1.6.0 documentation](#sqlc-documentation-sqlc-1-6-0-documentation) - [sqlc Documentation — sqlc 1.10.0 documentation](#sqlc-documentation-sqlc-1-10-0-documentation) - [sqlc Documentation — sqlc 1.9.0 documentation](#sqlc-documentation-sqlc-1-9-0-documentation) - [sqlc Documentation — sqlc 1.6.0 documentation](#sqlc-documentation-sqlc-1-6-0-documentation) - [Unknown](#unknown) - [Unknown](#unknown) - [Unknown](#unknown) - [Unknown](#unknown) - [Installing sqlc — sqlc 1.31.1 documentation](#installing-sqlc-sqlc-1-31-1-documentation) - [Getting started with MySQL — sqlc 1.31.1 documentation](#getting-started-with-mysql-sqlc-1-31-1-documentation) - [Getting started with PostgreSQL — sqlc 1.31.1 documentation](#getting-started-with-postgresql-sqlc-1-31-1-documentation) - [Getting started with SQLite — sqlc 1.31.1 documentation](#getting-started-with-sqlite-sqlc-1-31-1-documentation) - [push - Uploading projects — sqlc 1.31.1 documentation](#push-uploading-projects-sqlc-1-31-1-documentation) - [generate - Generating code — sqlc 1.31.1 documentation](#generate-generating-code-sqlc-1-31-1-documentation) - [verify - Verifying schema changes — sqlc 1.31.1 documentation](#verify-verifying-schema-changes-sqlc-1-31-1-documentation) - [Deleting rows — sqlc 1.31.1 documentation](#deleting-rows-sqlc-1-31-1-documentation) - [Counting rows — sqlc 1.31.1 documentation](#counting-rows-sqlc-1-31-1-documentation) - [Updating rows — sqlc 1.31.1 documentation](#updating-rows-sqlc-1-31-1-documentation) - [vet - Linting queries — sqlc 1.31.1 documentation](#vet-linting-queries-sqlc-1-31-1-documentation) - [Naming parameters — sqlc 1.31.1 documentation](#naming-parameters-sqlc-1-31-1-documentation) - [Inserting rows — sqlc 1.31.1 documentation](#inserting-rows-sqlc-1-31-1-documentation) - [Configuring generated structs — sqlc 1.31.1 documentation](#configuring-generated-structs-sqlc-1-31-1-documentation) - [Using transactions — sqlc 1.31.1 documentation](#using-transactions-sqlc-1-31-1-documentation) - [Embedding structs — sqlc 1.31.1 documentation](#embedding-structs-sqlc-1-31-1-documentation) - [Modifying the database schema — sqlc 1.31.1 documentation](#modifying-the-database-schema-sqlc-1-31-1-documentation) - [Retrieving rows — sqlc 1.31.1 documentation](#retrieving-rows-sqlc-1-31-1-documentation) - [Preparing queries — sqlc 1.31.1 documentation](#preparing-queries-sqlc-1-31-1-documentation) - [Renaming fields — sqlc 1.31.1 documentation](#renaming-fields-sqlc-1-31-1-documentation) - [Using Go and pgx — sqlc 1.31.1 documentation](#using-go-and-pgx-sqlc-1-31-1-documentation) - [Overriding types — sqlc 1.31.1 documentation](#overriding-types-sqlc-1-31-1-documentation) - [Database and language support — sqlc 1.27.0 documentation](#database-and-language-support-sqlc-1-27-0-documentation) - [CLI — sqlc 1.27.0 documentation](#cli-sqlc-1-27-0-documentation) - [Using plugins — sqlc 1.27.0 documentation](#using-plugins-sqlc-1-27-0-documentation) - [Using Go and pgx — sqlc 1.27.0 documentation](#using-go-and-pgx-sqlc-1-27-0-documentation) - [Getting started with MySQL — sqlc 1.31.0 documentation](#getting-started-with-mysql-sqlc-1-31-0-documentation) - [Environment variables — sqlc 1.31.1 documentation](#environment-variables-sqlc-1-31-1-documentation) - [Query annotations — sqlc 1.31.1 documentation](#query-annotations-sqlc-1-31-1-documentation) - [Datatypes — sqlc 1.31.1 documentation](#datatypes-sqlc-1-31-1-documentation) - [push - Uploading projects — sqlc 1.31.1 documentation](#push-uploading-projects-sqlc-1-31-1-documentation) - [Getting started with MySQL — sqlc 1.31.1 documentation](#getting-started-with-mysql-sqlc-1-31-1-documentation) - [Counting rows — sqlc 1.31.1 documentation](#counting-rows-sqlc-1-31-1-documentation) - [Inserting rows — sqlc 1.31.1 documentation](#inserting-rows-sqlc-1-31-1-documentation) - [Updating rows — sqlc 1.31.1 documentation](#updating-rows-sqlc-1-31-1-documentation) - [Naming parameters — sqlc 1.31.1 documentation](#naming-parameters-sqlc-1-31-1-documentation) - [Using transactions — sqlc 1.31.1 documentation](#using-transactions-sqlc-1-31-1-documentation) - [push - Uploading projects — sqlc 1.31.0 documentation](#push-uploading-projects-sqlc-1-31-0-documentation) - [Embedding structs — sqlc 1.31.1 documentation](#embedding-structs-sqlc-1-31-1-documentation) - [Counting rows — sqlc 1.31.0 documentation](#counting-rows-sqlc-1-31-0-documentation) - [Naming parameters — sqlc 1.31.0 documentation](#naming-parameters-sqlc-1-31-0-documentation) - [Updating rows — sqlc 1.31.0 documentation](#updating-rows-sqlc-1-31-0-documentation) - [Using transactions — sqlc 1.31.0 documentation](#using-transactions-sqlc-1-31-0-documentation) - [Embedding structs — sqlc 1.31.0 documentation](#embedding-structs-sqlc-1-31-0-documentation) - [push - Uploading projects — sqlc 1.31.1 documentation](#push-uploading-projects-sqlc-1-31-1-documentation) - [Counting rows — sqlc 1.31.1 documentation](#counting-rows-sqlc-1-31-1-documentation) - [Updating rows — sqlc 1.31.1 documentation](#updating-rows-sqlc-1-31-1-documentation) - [Using transactions — sqlc 1.31.1 documentation](#using-transactions-sqlc-1-31-1-documentation) - [CLI — sqlc 1.31.1 documentation](#cli-sqlc-1-31-1-documentation) - [Privacy and data collection — sqlc 1.31.1 documentation](#privacy-and-data-collection-sqlc-1-31-1-documentation) - [Privacy and data collection — sqlc 1.31.1 documentation](#privacy-and-data-collection-sqlc-1-31-1-documentation) - [Privacy and data collection — sqlc 1.31.0 documentation](#privacy-and-data-collection-sqlc-1-31-0-documentation) - [Updating rows — sqlc 1.27.0 documentation](#updating-rows-sqlc-1-27-0-documentation) - [Privacy and data collection — sqlc 1.31.1 documentation](#privacy-and-data-collection-sqlc-1-31-1-documentation) - [Using transactions — sqlc 1.27.0 documentation](#using-transactions-sqlc-1-27-0-documentation) - [Naming parameters — sqlc 1.27.0 documentation](#naming-parameters-sqlc-1-27-0-documentation) - [Modifying the database schema — sqlc 1.27.0 documentation](#modifying-the-database-schema-sqlc-1-27-0-documentation) - [Installing sqlc — sqlc 1.27.0 documentation](#installing-sqlc-sqlc-1-27-0-documentation) - [Deleting rows — sqlc 1.27.0 documentation](#deleting-rows-sqlc-1-27-0-documentation) - [push - Uploading projects — sqlc 1.27.0 documentation](#push-uploading-projects-sqlc-1-27-0-documentation) - [verify - Verifying schema changes — sqlc 1.27.0 documentation](#verify-verifying-schema-changes-sqlc-1-27-0-documentation) - [Overriding types — sqlc 1.27.0 documentation](#overriding-types-sqlc-1-27-0-documentation) - [Preparing queries — sqlc 1.27.0 documentation](#preparing-queries-sqlc-1-27-0-documentation) - [Counting rows — sqlc 1.27.0 documentation](#counting-rows-sqlc-1-27-0-documentation) - [Renaming fields — sqlc 1.27.0 documentation](#renaming-fields-sqlc-1-27-0-documentation) - [Macros — sqlc 1.27.0 documentation](#macros-sqlc-1-27-0-documentation) - [generate - Generating code — sqlc 1.27.0 documentation](#generate-generating-code-sqlc-1-27-0-documentation) - [Getting started with SQLite — sqlc 1.27.0 documentation](#getting-started-with-sqlite-sqlc-1-27-0-documentation) - [Query annotations — sqlc 1.27.0 documentation](#query-annotations-sqlc-1-27-0-documentation) - [Inserting rows — sqlc 1.27.0 documentation](#inserting-rows-sqlc-1-27-0-documentation) - [generate - Generating code — sqlc 1.31.1 documentation](#generate-generating-code-sqlc-1-31-1-documentation) - [Using plugins — sqlc 1.31.1 documentation](#using-plugins-sqlc-1-31-1-documentation) - [Installing sqlc — sqlc 1.31.0 documentation](#installing-sqlc-sqlc-1-31-0-documentation) - [Developing sqlc — sqlc 1.31.1 documentation](#developing-sqlc-sqlc-1-31-1-documentation) - [Installing sqlc — sqlc 1.31.1 documentation](#installing-sqlc-sqlc-1-31-1-documentation) - [Deleting rows — sqlc 1.31.1 documentation](#deleting-rows-sqlc-1-31-1-documentation) - [Using Go and pgx — sqlc 1.31.1 documentation](#using-go-and-pgx-sqlc-1-31-1-documentation) - [Using plugins — sqlc 1.31.1 documentation](#using-plugins-sqlc-1-31-1-documentation) - [CLI — sqlc 1.31.1 documentation](#cli-sqlc-1-31-1-documentation) - [Developing sqlc — sqlc 1.31.1 documentation](#developing-sqlc-sqlc-1-31-1-documentation) - [Preparing queries — sqlc 1.31.0 documentation](#preparing-queries-sqlc-1-31-0-documentation) - [Deleting rows — sqlc 1.31.0 documentation](#deleting-rows-sqlc-1-31-0-documentation) - [Using Go and pgx — sqlc 1.31.0 documentation](#using-go-and-pgx-sqlc-1-31-0-documentation) - [Using plugins — sqlc 1.31.0 documentation](#using-plugins-sqlc-1-31-0-documentation) - [CLI — sqlc 1.31.0 documentation](#cli-sqlc-1-31-0-documentation) - [Developing sqlc — sqlc 1.31.0 documentation](#developing-sqlc-sqlc-1-31-0-documentation) - [Installing sqlc — sqlc 1.31.1 documentation](#installing-sqlc-sqlc-1-31-1-documentation) - [Deleting rows — sqlc 1.31.1 documentation](#deleting-rows-sqlc-1-31-1-documentation) - [Using Go and pgx — sqlc 1.31.1 documentation](#using-go-and-pgx-sqlc-1-31-1-documentation) - [Using plugins — sqlc 1.31.1 documentation](#using-plugins-sqlc-1-31-1-documentation) - [CLI — sqlc 1.31.1 documentation](#cli-sqlc-1-31-1-documentation) - [Developing sqlc — sqlc 1.31.1 documentation](#developing-sqlc-sqlc-1-31-1-documentation) - [Managed databases — sqlc 1.27.0 documentation](#managed-databases-sqlc-1-27-0-documentation) - [Developing sqlc — sqlc 1.27.0 documentation](#developing-sqlc-sqlc-1-27-0-documentation) - [Privacy and data collection — sqlc 1.27.0 documentation](#privacy-and-data-collection-sqlc-1-27-0-documentation) - [Getting started with SQLite — sqlc 1.31.1 documentation](#getting-started-with-sqlite-sqlc-1-31-1-documentation) - [Macros — sqlc 1.31.1 documentation](#macros-sqlc-1-31-1-documentation) - [verify - Verifying schema changes — sqlc 1.31.1 documentation](#verify-verifying-schema-changes-sqlc-1-31-1-documentation) - [Using sqlc in CI/CD — sqlc 1.31.1 documentation](#using-sqlc-in-ci-cd-sqlc-1-31-1-documentation) - [Renaming fields — sqlc 1.31.1 documentation](#renaming-fields-sqlc-1-31-1-documentation) - [Preparing queries — sqlc 1.31.1 documentation](#preparing-queries-sqlc-1-31-1-documentation) - [Using sqlc in CI/CD — sqlc 1.31.1 documentation](#using-sqlc-in-ci-cd-sqlc-1-31-1-documentation) - [generate - Generating code — sqlc 1.31.0 documentation](#generate-generating-code-sqlc-1-31-0-documentation) - [Modifying the database schema — sqlc 1.31.1 documentation](#modifying-the-database-schema-sqlc-1-31-1-documentation) - [Getting started with SQLite — sqlc 1.31.0 documentation](#getting-started-with-sqlite-sqlc-1-31-0-documentation) - [verify - Verifying schema changes — sqlc 1.31.0 documentation](#verify-verifying-schema-changes-sqlc-1-31-0-documentation) - [Renaming fields — sqlc 1.31.0 documentation](#renaming-fields-sqlc-1-31-0-documentation) - [Modifying the database schema — sqlc 1.31.0 documentation](#modifying-the-database-schema-sqlc-1-31-0-documentation) - [Macros — sqlc 1.31.0 documentation](#macros-sqlc-1-31-0-documentation) - [verify - Verifying schema changes — sqlc 1.31.1 documentation](#verify-verifying-schema-changes-sqlc-1-31-1-documentation) - [generate - Generating code — sqlc 1.31.1 documentation](#generate-generating-code-sqlc-1-31-1-documentation) - [Preparing queries — sqlc 1.31.1 documentation](#preparing-queries-sqlc-1-31-1-documentation) - [Managed databases — sqlc 1.31.1 documentation](#managed-databases-sqlc-1-31-1-documentation) - [Getting started with SQLite — sqlc 1.31.1 documentation](#getting-started-with-sqlite-sqlc-1-31-1-documentation) - [Embedding structs — sqlc 1.31.1 documentation](#embedding-structs-sqlc-1-31-1-documentation) - [Macros — sqlc 1.31.1 documentation](#macros-sqlc-1-31-1-documentation) - [generate - Generating code — sqlc 1.30.0 documentation](#generate-generating-code-sqlc-1-30-0-documentation) - [Getting started with SQLite — sqlc 1.30.0 documentation](#getting-started-with-sqlite-sqlc-1-30-0-documentation) - [verify - Verifying schema changes — sqlc 1.30.0 documentation](#verify-verifying-schema-changes-sqlc-1-30-0-documentation) - [push - Uploading projects — sqlc 1.29.0 documentation](#push-uploading-projects-sqlc-1-29-0-documentation) - [Embedding structs — sqlc 1.30.0 documentation](#embedding-structs-sqlc-1-30-0-documentation) - [Modifying the database schema — sqlc 1.30.0 documentation](#modifying-the-database-schema-sqlc-1-30-0-documentation) - [Macros — sqlc 1.31.1 documentation](#macros-sqlc-1-31-1-documentation) - [vet - Linting queries — sqlc 1.31.1 documentation](#vet-linting-queries-sqlc-1-31-1-documentation) - [Overriding types — sqlc 1.31.1 documentation](#overriding-types-sqlc-1-31-1-documentation) - [Query annotations — sqlc 1.31.1 documentation](#query-annotations-sqlc-1-31-1-documentation) - [Inserting rows — sqlc 1.31.0 documentation](#inserting-rows-sqlc-1-31-0-documentation) - [Overriding types — sqlc 1.31.0 documentation](#overriding-types-sqlc-1-31-0-documentation) - [Modifying the database schema — sqlc 1.31.1 documentation](#modifying-the-database-schema-sqlc-1-31-1-documentation) - [Getting started with MySQL — sqlc 1.31.1 documentation](#getting-started-with-mysql-sqlc-1-31-1-documentation) - [Inserting rows — sqlc 1.31.1 documentation](#inserting-rows-sqlc-1-31-1-documentation) - [Query annotations — sqlc 1.31.0 documentation](#query-annotations-sqlc-1-31-0-documentation) - [Overriding types — sqlc 1.31.1 documentation](#overriding-types-sqlc-1-31-1-documentation) - [Query annotations — sqlc 1.31.1 documentation](#query-annotations-sqlc-1-31-1-documentation) - [Getting started with MySQL — sqlc 1.30.0 documentation](#getting-started-with-mysql-sqlc-1-30-0-documentation) - [Overriding types — sqlc 1.30.0 documentation](#overriding-types-sqlc-1-30-0-documentation) - [Getting started with MySQL — sqlc 1.29.0 documentation](#getting-started-with-mysql-sqlc-1-29-0-documentation) - [Macros — sqlc 1.30.0 documentation](#macros-sqlc-1-30-0-documentation) - [Inserting rows — sqlc 1.30.0 documentation](#inserting-rows-sqlc-1-30-0-documentation) - [Getting started with SQLite — sqlc 1.29.0 documentation](#getting-started-with-sqlite-sqlc-1-29-0-documentation) - [Getting started with PostgreSQL — sqlc 1.27.0 documentation](#getting-started-with-postgresql-sqlc-1-27-0-documentation) - [Getting started with MySQL — sqlc 1.27.0 documentation](#getting-started-with-mysql-sqlc-1-27-0-documentation) - [Environment variables — sqlc 1.27.0 documentation](#environment-variables-sqlc-1-27-0-documentation) - [Managed databases — sqlc 1.31.1 documentation](#managed-databases-sqlc-1-31-1-documentation) - [Managed databases — sqlc 1.31.1 documentation](#managed-databases-sqlc-1-31-1-documentation) - [Database and language support — sqlc 1.31.1 documentation](#database-and-language-support-sqlc-1-31-1-documentation) - [Managed databases — sqlc 1.31.0 documentation](#managed-databases-sqlc-1-31-0-documentation) - [Database and language support — sqlc 1.31.0 documentation](#database-and-language-support-sqlc-1-31-0-documentation) - [Database and language support — sqlc 1.31.1 documentation](#database-and-language-support-sqlc-1-31-1-documentation) - [Configuring generated structs — sqlc 1.27.0 documentation](#configuring-generated-structs-sqlc-1-27-0-documentation) - [Preparing queries — sqlc 1.30.0 documentation](#preparing-queries-sqlc-1-30-0-documentation) - [Installing sqlc — sqlc 1.30.0 documentation](#installing-sqlc-sqlc-1-30-0-documentation) - [Renaming fields — sqlc 1.30.0 documentation](#renaming-fields-sqlc-1-30-0-documentation) - [Deleting rows — sqlc 1.30.0 documentation](#deleting-rows-sqlc-1-30-0-documentation) - [CLI — sqlc 1.30.0 documentation](#cli-sqlc-1-30-0-documentation) - [Installing sqlc — sqlc 1.29.0 documentation](#installing-sqlc-sqlc-1-29-0-documentation) - [Embedding structs — sqlc 1.27.0 documentation](#embedding-structs-sqlc-1-27-0-documentation) - [Environment variables — sqlc 1.31.1 documentation](#environment-variables-sqlc-1-31-1-documentation) - [Getting started with PostgreSQL — sqlc 1.31.1 documentation](#getting-started-with-postgresql-sqlc-1-31-1-documentation) - [Datatypes — sqlc 1.31.1 documentation](#datatypes-sqlc-1-31-1-documentation) - [vet - Linting queries — sqlc 1.31.0 documentation](#vet-linting-queries-sqlc-1-31-0-documentation) - [Datatypes — sqlc 1.31.0 documentation](#datatypes-sqlc-1-31-0-documentation) - [Environment variables — sqlc 1.31.0 documentation](#environment-variables-sqlc-1-31-0-documentation) - [Getting started with PostgreSQL — sqlc 1.31.1 documentation](#getting-started-with-postgresql-sqlc-1-31-1-documentation) - [vet - Linting queries — sqlc 1.31.1 documentation](#vet-linting-queries-sqlc-1-31-1-documentation) - [Datatypes — sqlc 1.31.1 documentation](#datatypes-sqlc-1-31-1-documentation) - [Environment variables — sqlc 1.31.1 documentation](#environment-variables-sqlc-1-31-1-documentation) - [Getting started with PostgreSQL — sqlc 1.30.0 documentation](#getting-started-with-postgresql-sqlc-1-30-0-documentation) - [Configuring generated structs — sqlc 1.31.1 documentation](#configuring-generated-structs-sqlc-1-31-1-documentation) - [Configuring generated structs — sqlc 1.31.0 documentation](#configuring-generated-structs-sqlc-1-31-0-documentation) - [Configuring generated structs — sqlc 1.31.1 documentation](#configuring-generated-structs-sqlc-1-31-1-documentation) - [Managed databases — sqlc 1.30.0 documentation](#managed-databases-sqlc-1-30-0-documentation) - [Naming parameters — sqlc 1.31.1 documentation](#naming-parameters-sqlc-1-31-1-documentation) - [Renaming fields — sqlc 1.31.1 documentation](#renaming-fields-sqlc-1-31-1-documentation) - [push - Uploading projects — sqlc 1.30.0 documentation](#push-uploading-projects-sqlc-1-30-0-documentation) - [Counting rows — sqlc 1.30.0 documentation](#counting-rows-sqlc-1-30-0-documentation) - [Updating rows — sqlc 1.30.0 documentation](#updating-rows-sqlc-1-30-0-documentation) - [Using transactions — sqlc 1.30.0 documentation](#using-transactions-sqlc-1-30-0-documentation) - [Naming parameters — sqlc 1.30.0 documentation](#naming-parameters-sqlc-1-30-0-documentation) - [Using plugins — sqlc 1.30.0 documentation](#using-plugins-sqlc-1-30-0-documentation) - [Query annotations — sqlc 1.30.0 documentation](#query-annotations-sqlc-1-30-0-documentation) - [vet - Linting queries — sqlc 1.30.0 documentation](#vet-linting-queries-sqlc-1-30-0-documentation) - [Datatypes — sqlc 1.30.0 documentation](#datatypes-sqlc-1-30-0-documentation) - [vet - Linting queries — sqlc 1.27.0 documentation](#vet-linting-queries-sqlc-1-27-0-documentation) - [Datatypes — sqlc 1.27.0 documentation](#datatypes-sqlc-1-27-0-documentation) - [Configuring generated structs — sqlc 1.30.0 documentation](#configuring-generated-structs-sqlc-1-30-0-documentation) - [Database and language support — sqlc 1.31.1 documentation](#database-and-language-support-sqlc-1-31-1-documentation) - [Database and language support — sqlc 1.30.0 documentation](#database-and-language-support-sqlc-1-30-0-documentation) - [Environment variables — sqlc 1.30.0 documentation](#environment-variables-sqlc-1-30-0-documentation) - [Getting started with PostgreSQL — sqlc 1.31.0 documentation](#getting-started-with-postgresql-sqlc-1-31-0-documentation) - [Getting started with PostgreSQL — sqlc 1.29.0 documentation](#getting-started-with-postgresql-sqlc-1-29-0-documentation) - [Using Go and pgx — sqlc 1.30.0 documentation](#using-go-and-pgx-sqlc-1-30-0-documentation) - [verify - Verifying schema changes — sqlc 1.29.0 documentation](#verify-verifying-schema-changes-sqlc-1-29-0-documentation) - [Retrieving rows — sqlc 1.30.0 documentation](#retrieving-rows-sqlc-1-30-0-documentation) - [Retrieving rows — sqlc 1.31.1 documentation](#retrieving-rows-sqlc-1-31-1-documentation) - [Retrieving rows — sqlc 1.31.0 documentation](#retrieving-rows-sqlc-1-31-0-documentation) - [Using sqlc in CI/CD — sqlc 1.27.0 documentation](#using-sqlc-in-ci-cd-sqlc-1-27-0-documentation) - [Retrieving rows — sqlc 1.31.1 documentation](#retrieving-rows-sqlc-1-31-1-documentation) - [Retrieving rows — sqlc 1.27.0 documentation](#retrieving-rows-sqlc-1-27-0-documentation) - [Using sqlc in CI/CD — sqlc 1.31.0 documentation](#using-sqlc-in-ci-cd-sqlc-1-31-0-documentation) - [Using sqlc in CI/CD — sqlc 1.31.1 documentation](#using-sqlc-in-ci-cd-sqlc-1-31-1-documentation) - [Configuration — sqlc 1.31.1 documentation](#configuration-sqlc-1-31-1-documentation) - [generate - Generating code — sqlc 1.29.0 documentation](#generate-generating-code-sqlc-1-29-0-documentation) - [Configuration — sqlc 1.31.1 documentation](#configuration-sqlc-1-31-1-documentation) - [Using sqlc in CI/CD — sqlc 1.30.0 documentation](#using-sqlc-in-ci-cd-sqlc-1-30-0-documentation) - [Configuration — sqlc 1.31.0 documentation](#configuration-sqlc-1-31-0-documentation) - [Configuration — sqlc 1.31.1 documentation](#configuration-sqlc-1-31-1-documentation) - [Configuration — sqlc 1.30.0 documentation](#configuration-sqlc-1-30-0-documentation) - [Configuration — sqlc 1.27.0 documentation](#configuration-sqlc-1-27-0-documentation) - [Changelog — sqlc 1.27.0 documentation](#changelog-sqlc-1-27-0-documentation) - [Changelog — sqlc 1.31.1 documentation](#changelog-sqlc-1-31-1-documentation) - [Changelog — sqlc 1.30.0 documentation](#changelog-sqlc-1-30-0-documentation) - [Changelog — sqlc 1.31.1 documentation](#changelog-sqlc-1-31-1-documentation) - [Changelog — sqlc 1.31.0 documentation](#changelog-sqlc-1-31-0-documentation) - [Changelog — sqlc 1.31.1 documentation](#changelog-sqlc-1-31-1-documentation) --- # sqlc Documentation — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/#) * sqlc Documentation * [View page source](https://docs.sqlc.dev/en/latest/_sources/index.rst.txt) * * * sqlc Documentation[](https://docs.sqlc.dev/en/latest/#sqlc-documentation "Link to this heading") ================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/#) * sqlc Documentation * [View page source](https://docs.sqlc.dev/en/stable/_sources/index.rst.txt) * * * sqlc Documentation[](https://docs.sqlc.dev/en/stable/#sqlc-documentation "Link to this heading") ================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/#) * sqlc Documentation * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/index.rst.txt) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.31.0/#sqlc-documentation "Link to this heading") =================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/#) * sqlc Documentation * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/index.rst.txt) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.31.1/#sqlc-documentation "Link to this heading") =================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.27.0/#sqlc-documentation "Link to this heading") =================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/#) * sqlc Documentation * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/index.rst.txt) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.30.0/#sqlc-documentation "Link to this heading") =================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/#) * sqlc Documentation * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/index.rst.txt) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.29.0/#sqlc-documentation "Link to this heading") =================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.28.0 documentation * [](https://docs.sqlc.dev/en/v1.28.0/#) * sqlc Documentation * [View page source](https://docs.sqlc.dev/en/v1.28.0/_sources/index.rst.txt) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.28.0/#sqlc-documentation "Link to this heading") =================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.26.0 documentation * [](https://docs.sqlc.dev/en/v1.26.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.26.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.26.0/#sqlc-documentation "Permalink to this heading") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.25.0 documentation * [](https://docs.sqlc.dev/en/v1.25.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.25.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.25.0/#sqlc-documentation "Permalink to this heading") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.24.0 documentation * [](https://docs.sqlc.dev/en/v1.24.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.24.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.24.0/#sqlc-documentation "Permalink to this heading") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.19.0 documentation * [](https://docs.sqlc.dev/en/v1.19.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.19.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.19.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.19.1 documentation * [](https://docs.sqlc.dev/en/v1.19.1/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.19.1/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.19.1/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.23.0 documentation * [](https://docs.sqlc.dev/en/v1.23.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.23.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.23.0/#sqlc-documentation "Permalink to this heading") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.22.0 documentation * [](https://docs.sqlc.dev/en/v1.22.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.22.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.22.0/#sqlc-documentation "Permalink to this heading") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.18.0 documentation * [](https://docs.sqlc.dev/en/v1.18.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.18.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.18.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.17.2 documentation * [](https://docs.sqlc.dev/en/v1.17.2/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.17.2/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.17.2/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.20.0 documentation * [](https://docs.sqlc.dev/en/v1.20.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.20.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.20.0/#sqlc-documentation "Permalink to this heading") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.17.1 documentation * [](https://docs.sqlc.dev/en/v1.17.1/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.17.1/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.17.1/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.17.0 documentation * [](https://docs.sqlc.dev/en/v1.17.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.17.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.17.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.21.0 documentation * [](https://docs.sqlc.dev/en/v1.21.0/#) * sqlc Documentation * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.21.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.21.0/#sqlc-documentation "Permalink to this heading") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.16.0 documentation * [](https://docs.sqlc.dev/en/v1.16.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.16.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.16.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.12.0 documentation * [](https://docs.sqlc.dev/en/v1.13.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.13.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.13.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.14.0 documentation * [](https://docs.sqlc.dev/en/v1.14.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.14.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.14.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.15.0 documentation * [](https://docs.sqlc.dev/en/v1.15.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.15.0/docs/index.rst) * * * sqlc Documentation[](https://docs.sqlc.dev/en/v1.15.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.12.0 documentation * [](https://docs.sqlc.dev/en/v1.12.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.12.0/docs/index.rst) * * * sqlc Documentation[¶](https://docs.sqlc.dev/en/v1.12.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.10.0 documentation * [](https://docs.sqlc.dev/en/v1.11.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.11.0/docs/index.rst) * * * sqlc Documentation[¶](https://docs.sqlc.dev/en/v1.11.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.6.0 documentation * [](https://docs.sqlc.dev/en/v1.8.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.8.0/docs/index.rst) * * * sqlc Documentation[¶](https://docs.sqlc.dev/en/v1.8.0/#sqlc-documentation "Permalink to this headline") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.10.0 documentation * [](https://docs.sqlc.dev/en/v1.10.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.10.0/docs/index.rst) * * * sqlc Documentation[¶](https://docs.sqlc.dev/en/v1.10.0/#sqlc-documentation "Permalink to this headline") ========================================================================================================= > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.9.0 documentation * [](https://docs.sqlc.dev/en/v1.9.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.9.0/docs/index.rst) * * * sqlc Documentation[¶](https://docs.sqlc.dev/en/v1.9.0/#sqlc-documentation "Permalink to this headline") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # sqlc Documentation — sqlc 1.6.0 documentation * [](https://docs.sqlc.dev/en/v1.7.0/#) » * sqlc Documentation * [Edit on GitHub](https://github.com/kyleconroy/sqlc/blob/v1.7.0/docs/index.rst) * * * sqlc Documentation[¶](https://docs.sqlc.dev/en/v1.7.0/#sqlc-documentation "Permalink to this headline") ======================================================================================================== > And lo, the Great One looked down upon the people and proclaimed: > > “SQL is actually pretty great” sqlc generates **fully type-safe idiomatic Go code** from SQL. Here’s how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it’s that easy. You don’t have to write any boilerplate SQL querying code ever again. --- # Unknown .. sqlc documentation master file, created by sphinx-quickstart on Mon Feb 1 23:18:36 2021. You can adapt this file completely to your liking, but it should at least contain the root \`toctree\` directive. sqlc Documentation ================== And lo, the Great One looked down upon the people and proclaimed: "SQL is actually pretty great" sqlc generates \*\*fully type-safe idiomatic Go code\*\* from SQL. Here's how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it's that easy. You don't have to write any boilerplate SQL querying code ever again. .. toctree:: :maxdepth: 2 :caption: Overview :hidden: overview/install.md .. toctree:: :maxdepth: 2 :caption: Tutorials :hidden: tutorials/getting-started-mysql.md tutorials/getting-started-postgresql.md tutorials/getting-started-sqlite.md .. toctree:: :maxdepth: 2 :caption: Commands :hidden: howto/generate.md howto/push.md howto/verify.md howto/vet.md .. toctree:: :maxdepth: 2 :caption: How-to Guides :hidden: howto/select.md howto/query\_count.md howto/insert.md howto/update.md howto/delete.md howto/prepared\_query.md howto/transactions.md howto/named\_parameters.md howto/ddl.md howto/structs.md howto/embedding.md howto/overrides.md howto/rename.md .. toctree:: :maxdepth: 3 :caption: sqlc Cloud :hidden: howto/managed-databases.md .. toctree:: :maxdepth: 3 :caption: Reference :hidden: reference/changelog.md reference/cli.md reference/config.md reference/datatypes.md reference/environment-variables.md reference/language-support.rst reference/macros.md reference/query-annotations.md .. toctree:: :maxdepth: 2 :caption: Conceptual Guides :hidden: howto/ci-cd.md guides/using-go-and-pgx.rst guides/plugins.md guides/development.md guides/privacy.md --- # Unknown .. sqlc documentation master file, created by sphinx-quickstart on Mon Feb 1 23:18:36 2021. You can adapt this file completely to your liking, but it should at least contain the root \`toctree\` directive. sqlc Documentation ================== And lo, the Great One looked down upon the people and proclaimed: "SQL is actually pretty great" sqlc generates \*\*fully type-safe idiomatic Go code\*\* from SQL. Here's how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it's that easy. You don't have to write any boilerplate SQL querying code ever again. .. toctree:: :maxdepth: 2 :caption: Overview :hidden: overview/install.md .. toctree:: :maxdepth: 2 :caption: Tutorials :hidden: tutorials/getting-started-mysql.md tutorials/getting-started-postgresql.md tutorials/getting-started-sqlite.md .. toctree:: :maxdepth: 2 :caption: Commands :hidden: howto/generate.md howto/push.md howto/verify.md howto/vet.md .. toctree:: :maxdepth: 2 :caption: How-to Guides :hidden: howto/select.md howto/query\_count.md howto/insert.md howto/update.md howto/delete.md howto/prepared\_query.md howto/transactions.md howto/named\_parameters.md howto/ddl.md howto/structs.md howto/embedding.md howto/overrides.md howto/rename.md .. toctree:: :maxdepth: 3 :caption: sqlc Cloud :hidden: howto/managed-databases.md .. toctree:: :maxdepth: 3 :caption: Reference :hidden: reference/changelog.md reference/cli.md reference/config.md reference/datatypes.md reference/environment-variables.md reference/language-support.rst reference/macros.md reference/query-annotations.md .. toctree:: :maxdepth: 2 :caption: Conceptual Guides :hidden: howto/ci-cd.md guides/using-go-and-pgx.rst guides/plugins.md guides/development.md guides/privacy.md --- # Unknown .. sqlc documentation master file, created by sphinx-quickstart on Mon Feb 1 23:18:36 2021. You can adapt this file completely to your liking, but it should at least contain the root \`toctree\` directive. sqlc Documentation ================== And lo, the Great One looked down upon the people and proclaimed: "SQL is actually pretty great" sqlc generates \*\*fully type-safe idiomatic Go code\*\* from SQL. Here's how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it's that easy. You don't have to write any boilerplate SQL querying code ever again. .. toctree:: :maxdepth: 2 :caption: Overview :hidden: overview/install.md .. toctree:: :maxdepth: 2 :caption: Tutorials :hidden: tutorials/getting-started-mysql.md tutorials/getting-started-postgresql.md tutorials/getting-started-sqlite.md .. toctree:: :maxdepth: 2 :caption: Commands :hidden: howto/generate.md howto/push.md howto/verify.md howto/vet.md .. toctree:: :maxdepth: 2 :caption: How-to Guides :hidden: howto/select.md howto/query\_count.md howto/insert.md howto/update.md howto/delete.md howto/prepared\_query.md howto/transactions.md howto/named\_parameters.md howto/ddl.md howto/structs.md howto/embedding.md howto/overrides.md howto/rename.md .. toctree:: :maxdepth: 3 :caption: sqlc Cloud :hidden: howto/managed-databases.md .. toctree:: :maxdepth: 3 :caption: Reference :hidden: reference/changelog.md reference/cli.md reference/config.md reference/datatypes.md reference/environment-variables.md reference/language-support.rst reference/macros.md reference/query-annotations.md .. toctree:: :maxdepth: 2 :caption: Conceptual Guides :hidden: howto/ci-cd.md guides/using-go-and-pgx.rst guides/plugins.md guides/development.md guides/privacy.md --- # Unknown .. sqlc documentation master file, created by sphinx-quickstart on Mon Feb 1 23:18:36 2021. You can adapt this file completely to your liking, but it should at least contain the root \`toctree\` directive. sqlc Documentation ================== And lo, the Great One looked down upon the people and proclaimed: "SQL is actually pretty great" sqlc generates \*\*fully type-safe idiomatic Go code\*\* from SQL. Here's how it works: 1. You write SQL queries 2. You run sqlc to generate Go code that presents type-safe interfaces to those queries 3. You write application code that calls the methods sqlc generated Seriously, it's that easy. You don't have to write any boilerplate SQL querying code ever again. .. toctree:: :maxdepth: 2 :caption: Overview :hidden: overview/install.md .. toctree:: :maxdepth: 2 :caption: Tutorials :hidden: tutorials/getting-started-mysql.md tutorials/getting-started-postgresql.md tutorials/getting-started-sqlite.md .. toctree:: :maxdepth: 2 :caption: Commands :hidden: howto/generate.md howto/push.md howto/verify.md howto/vet.md .. toctree:: :maxdepth: 2 :caption: How-to Guides :hidden: howto/select.md howto/query\_count.md howto/insert.md howto/update.md howto/delete.md howto/prepared\_query.md howto/transactions.md howto/named\_parameters.md howto/ddl.md howto/structs.md howto/embedding.md howto/overrides.md howto/rename.md .. toctree:: :maxdepth: 3 :caption: sqlc Cloud :hidden: howto/managed-databases.md .. toctree:: :maxdepth: 3 :caption: Reference :hidden: reference/changelog.md reference/cli.md reference/config.md reference/datatypes.md reference/environment-variables.md reference/language-support.rst reference/macros.md reference/query-annotations.md .. toctree:: :maxdepth: 2 :caption: Conceptual Guides :hidden: howto/ci-cd.md guides/using-go-and-pgx.rst guides/plugins.md guides/development.md guides/privacy.md --- # Installing sqlc — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Installing sqlc * [View page source](https://docs.sqlc.dev/en/latest/_sources/overview/install.md.txt) * * * Installing sqlc[](https://docs.sqlc.dev/en/latest/overview/install.html#installing-sqlc "Link to this heading") ================================================================================================================= sqlc is distributed as a single binary with zero dependencies. macOS[](https://docs.sqlc.dev/en/latest/overview/install.html#macos "Link to this heading") --------------------------------------------------------------------------------------------- brew install sqlc Ubuntu[](https://docs.sqlc.dev/en/latest/overview/install.html#ubuntu "Link to this heading") ----------------------------------------------------------------------------------------------- sudo snap install sqlc go install[](https://docs.sqlc.dev/en/latest/overview/install.html#go-install "Link to this heading") ------------------------------------------------------------------------------------------------------- Installing recent versions of sqlc requires Go 1.21+. go install github.com/sqlc\-dev/sqlc/cmd/sqlc@latest Docker[](https://docs.sqlc.dev/en/latest/overview/install.html#docker "Link to this heading") ----------------------------------------------------------------------------------------------- docker pull sqlc/sqlc Run `sqlc` using `docker run`: docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate Run `sqlc` using `docker run` in the Command Prompt on Windows (`cmd`): docker run \--rm \-v "%cd%:/src" \-w /src sqlc/sqlc generate Downloads[](https://docs.sqlc.dev/en/latest/overview/install.html#downloads "Link to this heading") ----------------------------------------------------------------------------------------------------- Get pre-built binaries for _v1.31.1_: * [Linux](https://downloads.sqlc.dev/sqlc_1.31.1_linux_amd64.tar.gz) * [macOS](https://downloads.sqlc.dev/sqlc_1.31.1_darwin_amd64.zip) * [Windows](https://downloads.sqlc.dev/sqlc_1.31.1_windows_amd64.zip) See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions. --- # Getting started with MySQL — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Getting started with MySQL * [View page source](https://docs.sqlc.dev/en/latest/_sources/tutorials/getting-started-mysql.md.txt) * * * Getting started with MySQL[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-mysql.html#getting-started-with-mysql "Link to this heading") ====================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/latest/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/latest/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-mysql.html#setting-up "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-mysql.html#schema-and-queries "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGINT NOT NULL AUTO\_INCREMENT PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following four queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :execresult INSERT INTO authors ( name, bio ) VALUES ( ?, ? ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; Generating code[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-mysql.html#generating-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-mysql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------ You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" "log" "reflect" \_ "github.com/go-sql-driver/mysql" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() db, err := sql.Open("mysql", "user:password@/dbname?parseTime=true") if err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant MySQL driver: go get github.com/go-sql-driver/mysql go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `sql.Open()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-mysql.html#query-verification "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial --- # Getting started with PostgreSQL — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Getting started with PostgreSQL * [View page source](https://docs.sqlc.dev/en/latest/_sources/tutorials/getting-started-postgresql.md.txt) * * * Getting started with PostgreSQL[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html#getting-started-with-postgresql "Link to this heading") ===================================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/latest/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/latest/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html#setting-up "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app`: go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Schema and queries[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html#schema-and-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1 RETURNING \*; Generating code[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html#generating-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html#using-generated-code "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "log" "reflect" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() conn, err := pgx.Connect(ctx, "user=pqgotest dbname=pqgotest sslmode=verify-full") if err != nil { return err } defer conn.Close(ctx) queries := tutorial.New(conn) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant PostgreSQL driver. You can use `lib/pq` with the standard library’s `database/sql` package, but in this tutorial we’ve used `pgx/v5`: go get github.com/jackc/pgx/v5 go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `pgx.Connect()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html#query-verification "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial In the sidebar, go to the “Queries” section to see your published queries. Run `verify` to ensure that previously published queries continue to work against updated database schema. $ sqlc verify \--against tutorial --- # Getting started with SQLite — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Getting started with SQLite * [View page source](https://docs.sqlc.dev/en/latest/_sources/tutorials/getting-started-sqlite.md.txt) * * * Getting started with SQLite[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-sqlite.html#getting-started-with-sqlite "Link to this heading") ========================================================================================================================================================= This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/latest/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/latest/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. Setting up[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-sqlite.html#setting-up "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "sqlite" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-sqlite.html#schema-and-queries "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id INTEGER PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= ?, bio \= ? WHERE id \= ?; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= ?, bio \= ? WHERE id \= ? RETURNING \*; Generating code[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-sqlite.html#generating-code "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/latest/tutorials/getting-started-sqlite.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" \_ "embed" "log" "reflect" \_ "modernc.org/sqlite" "tutorial.sqlc.dev/app/tutorial" ) //go:embed schema.sql var ddl string func run() error { ctx := context.Background() db, err := sql.Open("sqlite", ":memory:") if err != nil { return err } // create tables if \_, err := db.ExecContext(ctx, ddl); err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant SQLite driver: go get modernc.org/sqlite go build ./... The program should compile without errors, and run successfully. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. --- # push - Uploading projects — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * `push` - Uploading projects * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/push.md.txt) * * * `push` - Uploading projects[](https://docs.sqlc.dev/en/latest/howto/push.html#push-uploading-projects "Link to this heading") =============================================================================================================================== Note `push` is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. _Added in v1.24.0_ We’ve renamed the `upload` sub-command to `push`. We’ve also changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. Add configuration[](https://docs.sqlc.dev/en/latest/howto/push.html#add-configuration "Link to this heading") --------------------------------------------------------------------------------------------------------------- After creating a project, add the project ID to your sqlc configuration file. version: "2" cloud: project: "" You’ll also need to create an auth token and make it available via the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Dry run[](https://docs.sqlc.dev/en/latest/howto/push.html#dry-run "Link to this heading") ------------------------------------------------------------------------------------------- You can see what’s included when uploading your project by using using the `--dry-run` flag: $ sqlc push \--dry-run 2023/11/21 10:39:51 INFO config file\=sqlc.yaml bytes\=912 2023/11/21 10:39:51 INFO codegen\_request queryset\=app file\=codegen\_request.pb 2023/11/21 10:39:51 INFO schema queryset\=app file\=migrations/00001\_initial.sql bytes\=3033 2023/11/21 10:39:51 INFO query queryset\=app file\=queries/app.sql bytes\=1150 The output is the files `sqlc` would have sent without the `--dry-run` flag. Push[](https://docs.sqlc.dev/en/latest/howto/push.html#push "Link to this heading") ------------------------------------------------------------------------------------- Once you’re ready to push, remove the `--dry-run` flag. $ sqlc push ### Tags[](https://docs.sqlc.dev/en/latest/howto/push.html#tags "Link to this heading") You can provide tags to associate with a push, primarily as a convenient reference when using `sqlc verify` with the `against` argument. Tags only refer to a single push, so if you pass an existing tag to `push` it will overwrite the previous reference. $ sqlc push \--tag main ### Annotations[](https://docs.sqlc.dev/en/latest/howto/push.html#annotations "Link to this heading") Annotations are added to each push request. By default, we include these environment variables (if they are present). GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA --- # generate - Generating code — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * `generate` - Generating code * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/generate.md.txt) * * * `generate` - Generating code[](https://docs.sqlc.dev/en/latest/howto/generate.html#generate-generating-code "Link to this heading") ===================================================================================================================================== `sqlc generate` parses SQL, analyzes the results, and outputs code. Your schema and queries are stored in separate SQL files. The paths to these files live in a `sqlc.yaml` configuration file. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" We’ve written extensive docs on [retrieving](https://docs.sqlc.dev/en/latest/howto/select.html) , [inserting](https://docs.sqlc.dev/en/latest/howto/insert.html) , [updating](https://docs.sqlc.dev/en/latest/howto/update.html) , and [deleting](https://docs.sqlc.dev/en/latest/howto/delete.html) rows. By default, sqlc runs its analysis using a built-in query analysis engine. While fast, this engine can’t handle some complex queries and type-inference. You can configure sqlc to use a database connection for enhanced analysis using metadata from that database. The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. Enhanced analysis with managed databases[](https://docs.sqlc.dev/en/latest/howto/generate.html#enhanced-analysis-with-managed-databases "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------------- With [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html) configured, `generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with an up-to-date schema. Here’s a minimal working configuration: version: "2" servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: managed: true gen: go: out: "db" sql\_package: "pgx/v5" Enhanced analysis using your own database[](https://docs.sqlc.dev/en/latest/howto/generate.html#enhanced-analysis-using-your-own-database "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can opt-in to database-backed analysis using your own database, by providing a `uri` in your sqlc [database](https://docs.sqlc.dev/en/latest/reference/config.html#database) configuration. The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: uri: "postgres://postgres:${PG\_PASSWORD}@localhost:5432/postgres" gen: go: out: "db" sql\_package: "pgx/v5" Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc generate`. --- # verify - Verifying schema changes — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * `verify` - Verifying schema changes * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/verify.md.txt) * * * `verify` - Verifying schema changes[](https://docs.sqlc.dev/en/latest/howto/verify.html#verify-verifying-schema-changes "Link to this heading") ================================================================================================================================================= _Added in v1.24.0_ Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. Using `verify` requires that you push your queries and schema when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. Authentication[](https://docs.sqlc.dev/en/latest/howto/verify.html#authentication "Link to this heading") ----------------------------------------------------------------------------------------------------------- `sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Expected workflow[](https://docs.sqlc.dev/en/latest/howto/verify.html#expected-workflow "Link to this heading") ----------------------------------------------------------------------------------------------------------------- Using `sqlc verify` requires pushing your queries and schema to sqlc Cloud. When you release a new version of your application, you should push your schema and queries as well. For example, we run `sqlc push` after any change has been merged into our `main` branch on Github, as we deploy every commit to production. $ sqlc push \--tag main Locally or in pull requests, run `sqlc verify` to check that existing queries continue to work with your current database schema. $ sqlc verify \--against main Picking a tag[](https://docs.sqlc.dev/en/latest/howto/verify.html#picking-a-tag "Link to this heading") --------------------------------------------------------------------------------------------------------- Without an `against` argument, `verify` will run its analysis of the provided schema using your most-recently pushed queries. We suggest using the `against` argument to explicitly select a set of queries for comparison. $ sqlc verify \--against \[tag\] --- # Deleting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Deleting rows * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/delete.md.txt) * * * Deleting rows[](https://docs.sqlc.dev/en/latest/howto/delete.html#deleting-rows "Link to this heading") ========================================================================================================= CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; **MySQL and SQLite:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const deleteAuthor \= \`-- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $1 \` func (q \*Queries) DeleteAuthor(ctx context.Context, id int) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } --- # Counting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Counting rows * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/query_count.md.txt) * * * Counting rows[](https://docs.sqlc.dev/en/latest/howto/query_count.html#counting-rows "Link to this heading") ============================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, hometown text NOT NULL ); \-- name: CountAuthors :one SELECT count(\*) FROM authors; \-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1; package db import ( "context" "database/sql" ) type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const countAuthors \= \`-- name: CountAuthors :one SELECT count(\*) FROM authors \` func (q \*Queries) CountAuthors(ctx context.Context) (int, error) { row := q.db.QueryRowContext(ctx, countAuthors) var i int err := row.Scan(&i) return i, err } const countAuthorsByTown \= \`-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1 \` type CountAuthorsByTownRow struct { Hometown string Count int } func (q \*Queries) CountAuthorsByTown(ctx context.Context) (\[\]CountAuthorsByTownRow, error) { rows, err := q.db.QueryContext(ctx, countAuthorsByTown) if err != nil { return nil, err } defer rows.Close() items := \[\]CountAuthorsByTownRow{} for rows.Next() { var i CountAuthorsByTownRow if err := rows.Scan(&i.Hometown, &i.Count); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Updating rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Updating rows * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/update.md.txt) * * * Updating rows[](https://docs.sqlc.dev/en/latest/howto/update.html#updating-rows "Link to this heading") ========================================================================================================= CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); Single parameter[](https://docs.sqlc.dev/en/latest/howto/update.html#single-parameter "Link to this heading") --------------------------------------------------------------------------------------------------------------- If your query has a single parameter, your Go method will also have a single parameter. The parameter syntax varies by database engine: **PostgreSQL:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= $1; **MySQL and SQLite:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthorBios \= \`-- name: UpdateAuthorBios :exec UPDATE authors SET bio = $1 \` func (q \*Queries) UpdateAuthorBios(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, updateAuthorBios, bio) return err } Multiple parameters[](https://docs.sqlc.dev/en/latest/howto/update.html#multiple-parameters "Link to this heading") --------------------------------------------------------------------------------------------------------------------- If your query has more than one parameter, your Go method will accept a `Params` struct. **PostgreSQL:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= $2 WHERE id \= $1; **MySQL and SQLite:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= ? WHERE id \= ?; Note: For MySQL and SQLite, parameters are bound in the order they appear in the query, regardless of the order in the function signature. package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthor \= \`-- name: UpdateAuthor :exec UPDATE authors SET bio = $2 WHERE id = $1 \` type UpdateAuthorParams struct { ID int32 Bio string } func (q \*Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error { \_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio) return err } --- # vet - Linting queries — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * `vet` - Linting queries * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/vet.md.txt) * * * `vet` - Linting queries[](https://docs.sqlc.dev/en/latest/howto/vet.html#vet-linting-queries "Link to this heading") ====================================================================================================================== _Added in v1.19.0_ `sqlc vet` runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/latest/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, `sqlc vet` will report an error using the given message. Defining lint rules[](https://docs.sqlc.dev/en/latest/howto/vet.html#defining-lint-rules "Link to this heading") ------------------------------------------------------------------------------------------------------------------ Each lint rule’s CEL expression has access to information from your sqlc configuration and queries via variables defined in the following proto messages. message Config { string version \= 1; string engine \= 2 ; repeated string schema \= 3; repeated string queries \= 4; } message Query { // SQL body string sql \= 1; // Name of the query string name \= 2; // One of "many", "one", "exec", etc. string cmd \= 3; // Query parameters, if any repeated Parameter params \= 4; } message Parameter { int32 number \= 1; } In addition to this basic information, when you have a PostgreSQL or MySQL [database connection configured](https://docs.sqlc.dev/en/latest/reference/config.html#database) each CEL expression has access to the output from running `EXPLAIN ...` on your query via the `postgresql.explain` and `mysql.explain` variables. This output is quite complex and depends on the structure of your query but sqlc attempts to parse and provide as much information as it can. See [Rules using `EXPLAIN ...` output](https://docs.sqlc.dev/en/latest/howto/vet.html#rules-using-explain-output) for more information. Here are a few example rules just using the basic configuration and query information available to the CEL expression environment. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Rules using `EXPLAIN ...` output[](https://docs.sqlc.dev/en/latest/howto/vet.html#rules-using-explain-output "Link to this heading") _Added in v1.20.0_ The CEL expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/latest/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- debug rules: \- name: debug rule: "!has(postgresql.explain)" \# A dummy rule to trigger explain Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with rules that depend on `EXPLAIN ...` output. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. Built-in rules[](https://docs.sqlc.dev/en/latest/howto/vet.html#built-in-rules "Link to this heading") -------------------------------------------------------------------------------------------------------- ### sqlc/db-prepare[](https://docs.sqlc.dev/en/latest/howto/vet.html#sqlc-db-prepare "Link to this heading") When a [database](https://docs.sqlc.dev/en/latest/reference/config.html#database) connection is configured, you can run the built-in `sqlc/db-prepare` rule. This rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with the `sqlc/db-prepare` rule. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. version: 2 cloud: project: "" sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: managed: true rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Running lint rules[](https://docs.sqlc.dev/en/latest/howto/vet.html#running-lint-rules "Link to this heading") ---------------------------------------------------------------------------------------------------------------- When you add the name of a defined rule to the rules list for a [sql package](https://docs.sqlc.dev/en/latest/reference/config.html#sql) , `sqlc vet` will evaluate that rule against every query in the package. In the example below, two rules are defined but only one is enabled. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-delete rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") ### Opting-out of lint rules[](https://docs.sqlc.dev/en/latest/howto/vet.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. The annotation accepts a list of rules to ignore. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; The rules can also be split across lines. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare \*/ /\* @sqlc-vet-disable no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; To skip all rules for a query, you can provide the `@sqlc-vet-disable` annotation without any parameters. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; --- # Naming parameters — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Naming parameters * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/named_parameters.md.txt) * * * Naming parameters[](https://docs.sqlc.dev/en/latest/howto/named_parameters.html#naming-parameters "Link to this heading") =========================================================================================================================== sqlc tries to generate good names for positional parameters, but sometimes it lacks enough context. The following SQL generates parameters with less than ideal names: \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN $1::bool THEN $2::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { Column1 bool \`json:""\` Column2\_2 string \`json:"\_2"\` } In these cases, named parameters give you the control over field names on the Params struct. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN sqlc.arg(set\_name)::bool THEN sqlc.arg(name)::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { SetName bool \`json:"set\_name"\` Name string \`json:"name"\` } If the `sqlc.arg()` syntax is too verbose for your taste, you can use the `@` operator as a shortcut. Note The `@` operator as a shortcut for `sqlc.arg()` is not supported in MySQL. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN @set\_name::bool THEN @name::text ELSE name END RETURNING \*; Nullable parameters[](https://docs.sqlc.dev/en/latest/howto/named_parameters.html#nullable-parameters "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------- sqlc infers the nullability of any specified parameters, and often does exactly what you want. If you want finer control over the nullability of your parameters, you may use `sqlc.narg()` (**n**ullable arg) to override the default behavior. Using `sqlc.narg` tells sqlc to ignore whatever nullability it has inferred and generate a nullable parameter instead. There is no nullable equivalent of the `@` syntax. Here is an example that uses a single query to allow updating an author’s name, bio or both. \-- name: UpdateAuthor :one UPDATE author SET name \= coalesce(sqlc.narg('name'), name), bio \= coalesce(sqlc.narg('bio'), bio) WHERE id \= sqlc.arg('id') RETURNING \*; The following code is generated: type UpdateAuthorParams struct { Name sql.NullString Bio sql.NullString ID int64 } --- # Inserting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Inserting rows * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/insert.md.txt) * * * Inserting rows[](https://docs.sqlc.dev/en/latest/howto/insert.html#inserting-rows "Link to this heading") =========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1); **MySQL and SQLite:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES (?); package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const createAuthor \= \`-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1) \` func (q \*Queries) CreateAuthor(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, createAuthor, bio) return err } Returning columns from inserted rows[](https://docs.sqlc.dev/en/latest/howto/insert.html#returning-columns-from-inserted-rows "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------- sqlc has full support for the `RETURNING` statement. \-- Example queries for sqlc CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); **PostgreSQL:** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id; **SQLite (with RETURNING support):** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING id; Note: MySQL does not support the `RETURNING` clause. Use `:execresult` instead to get the last insert ID. package db import ( "context" "database/sql" ) const createAuthor \= \`-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id, name, bio \` type CreateAuthorParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) var i Author err := row.Scan(&i.ID, &i.Name, &i.Bio) return i, err } const createAuthorAndReturnId \= \`-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id \` type CreateAuthorAndReturnIdParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthorAndReturnId(ctx context.Context, arg CreateAuthorAndReturnIdParams) (int64, error) { row := q.db.QueryRowContext(ctx, createAuthorAndReturnId, arg.Name, arg.Bio) var id int64 err := row.Scan(&id) return id, err } Using CopyFrom[](https://docs.sqlc.dev/en/latest/howto/insert.html#using-copyfrom "Link to this heading") ----------------------------------------------------------------------------------------------------------- ### PostgreSQL[](https://docs.sqlc.dev/en/latest/howto/insert.html#postgresql "Link to this heading") PostgreSQL supports the [COPY protocol](https://www.postgresql.org/docs/current/sql-copy.html) that can insert rows a lot faster than sequential inserts. You can use this easily with sqlc: CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text NOT NULL ); \-- name: CreateAuthors :copyfrom INSERT INTO authors (name, bio) VALUES ($1, $2); type CreateAuthorsParams struct { Name string Bio string } func (q \*Queries) CreateAuthors(ctx context.Context, arg \[\]CreateAuthorsParams) (int64, error) { ... } The `:copyfrom` command requires either `pgx/v4` or `pgx/v5`. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" ### MySQL[](https://docs.sqlc.dev/en/latest/howto/insert.html#mysql "Link to this heading") MySQL supports a similar feature using [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) . Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use SHOW WARNINGS to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } The `:copyfrom` command requires setting the `sql_package` and `sql_driver` options. version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "database/sql" sql\_driver: "github.com/go-sql-driver/mysql" out: "db" --- # Configuring generated structs — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Configuring generated structs * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/structs.md.txt) * * * Configuring generated structs[](https://docs.sqlc.dev/en/latest/howto/structs.html#configuring-generated-structs "Link to this heading") ========================================================================================================================================== Naming scheme[](https://docs.sqlc.dev/en/latest/howto/structs.html#naming-scheme "Link to this heading") ---------------------------------------------------------------------------------------------------------- Structs generated from tables will attempt to use the singular form of a table name if the table name is pluralized. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL ); package db // Struct names use the singular form of table names type Author struct { ID int Name string } JSON tags[](https://docs.sqlc.dev/en/latest/howto/structs.html#json-tags "Link to this heading") -------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL ); sqlc can generate structs with JSON tags by adding the `emit_json_tags` key to the configuration file as it shows on [configuration reference](https://docs.sqlc.dev/en/latest/reference/config.html) . The JSON name for a field matches the column name in the database. package db import ( "time" ) type Author struct { ID int \`json:"id"\` CreatedAt time.Time \`json:"created\_at"\` } More control[](https://docs.sqlc.dev/en/latest/howto/structs.html#more-control "Link to this heading") -------------------------------------------------------------------------------------------------------- See the guide to [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for fine-grained control over struct field types and tags. --- # Using transactions — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Using transactions * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/transactions.md.txt) * * * Using transactions[](https://docs.sqlc.dev/en/latest/howto/transactions.html#using-transactions "Link to this heading") ========================================================================================================================= In the code generated by sqlc, the `WithTx` method allows a `Queries` instance to be associated with a transaction. For example, with the following SQL structure: `schema.sql`: CREATE TABLE records ( id SERIAL PRIMARY KEY, counter INT NOT NULL ); `query.sql` \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; \-- name: UpdateRecord :exec UPDATE records SET counter \= $2 WHERE id \= $1; And the generated code from sqlc in `db.go`: package tutorial import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } You’d use it like this: // Using \`github/lib/pq\` as the driver. func bumpCounter(ctx context.Context, db \*sql.DB, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin() if err != nil { return err } defer tx.Rollback() qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit() } // Using \`github.com/jackc/pgx/v5\` as the driver. func bumpCounter(ctx context.Context, db \*pgx.Conn, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin(ctx) if err != nil { return err } defer tx.Rollback(ctx) qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit(ctx) } --- # Embedding structs — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Embedding structs * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/embedding.md.txt) * * * Embedding structs[](https://docs.sqlc.dev/en/latest/howto/embedding.html#embedding-structs "Link to this heading") ==================================================================================================================== Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text NOT NULL, age integer NOT NULL ); CREATE TABLE test\_scores ( student\_id bigint NOT NULL, score integer NOT NULL, grade text NOT NULL ); We want to select the student record and the scores they got on a test. Here’s how we’d usually do that: \-- name: ScoreAndTests :many SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; When using Go, sqlc will produce a struct like this: type ScoreAndTestsRow struct { ID int64 Name string Age int32 StudentID int64 Score int32 Grade string } With embedding, the struct will contain a model for both tables instead of a flattened list of columns. \-- name: ScoreAndTests :many SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; type ScoreAndTestsRow struct { Student Student TestScore TestScore } --- # Modifying the database schema — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Modifying the database schema * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/ddl.md.txt) * * * Modifying the database schema[](https://docs.sqlc.dev/en/latest/howto/ddl.html#modifying-the-database-schema "Link to this heading") ====================================================================================================================================== sqlc parses `CREATE TABLE` and `ALTER TABLE` statements in order to generate the necessary code. CREATE TABLE authors ( id SERIAL PRIMARY KEY, birth\_year int NOT NULL ); ALTER TABLE authors ADD COLUMN bio text NOT NULL; ALTER TABLE authors DROP COLUMN birth\_year; ALTER TABLE authors RENAME TO writers; package db type Writer struct { ID int Bio string } Handling SQL migrations[](https://docs.sqlc.dev/en/latest/howto/ddl.html#handling-sql-migrations "Link to this heading") -------------------------------------------------------------------------------------------------------------------------- sqlc does not perform database migrations for you. However, sqlc is able to differentiate between up and down migrations. sqlc ignores down migrations when parsing SQL files. sqlc supports parsing migrations from the following tools: * [atlas](https://github.com/ariga/atlas) * [dbmate](https://github.com/amacneil/dbmate) * [golang-migrate](https://github.com/golang-migrate/migrate) * [goose](https://github.com/pressly/goose) * [sql-migrate](https://github.com/rubenv/sql-migrate) * [tern](https://github.com/jackc/tern) To enable migration parsing, specify the migration directory instead of a schema file: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "db/migrations" gen: go: package: "tutorial" out: "tutorial" ### atlas[](https://docs.sqlc.dev/en/latest/howto/ddl.html#atlas "Link to this heading") \-- Create "post" table CREATE TABLE "public"."post" ("id" integer NOT NULL, "title" text NULL, "body" text NULL, PRIMARY KEY ("id")); package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### dbmate[](https://docs.sqlc.dev/en/latest/howto/ddl.html#dbmate "Link to this heading") \-- migrate:up CREATE TABLE foo (bar INT NOT NULL); \-- migrate:down DROP TABLE foo; package db type Foo struct { Bar int32 } ### golang-migrate[](https://docs.sqlc.dev/en/latest/howto/ddl.html#golang-migrate "Link to this heading") **Warning:** [golang-migrate interprets](https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md#migration-filename-format) migration filenames numerically. However, sqlc parses migration files in lexicographic order. If you choose to have sqlc enumerate your migration files, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.up.sql ... 9\_foo.up.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.up.sql This worked as intended. 001\_initial.up.sql ... 009\_foo.up.sql 010\_bar.up.sql In `20060102.up.sql`: CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); In `20060102.down.sql`: DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### goose[](https://docs.sqlc.dev/en/latest/howto/ddl.html#goose "Link to this heading") **Warning:** sqlc parses migration files in lexicographic order. **If you are using numeric filenames for migrations in Goose and you choose to have sqlc enumerate your migration files**, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.sql ... 9\_foo.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.sql This worked as intended. 001\_initial.sql ... 009\_foo.sql 010\_bar.sql \-- +goose Up CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); \-- +goose Down DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### sql-migrate[](https://docs.sqlc.dev/en/latest/howto/ddl.html#sql-migrate "Link to this heading") \-- +migrate Up \-- SQL in section 'Up' is executed when this migration is applied CREATE TABLE people (id int); \-- +migrate Down \-- SQL section 'Down' is executed when this migration is rolled back DROP TABLE people; package db type People struct { ID int32 } ### tern[](https://docs.sqlc.dev/en/latest/howto/ddl.html#tern "Link to this heading") CREATE TABLE comment (id int NOT NULL, text text NOT NULL); \---- create above / drop below ---- DROP TABLE comment; package db type Comment struct { ID int32 Text string } --- # Retrieving rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Retrieving rows * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/select.md.txt) * * * Retrieving rows[](https://docs.sqlc.dev/en/latest/howto/select.html#retrieving-rows "Link to this heading") ============================================================================================================= To generate a database access method, annotate a query with a specific comment. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; **MySQL and SQLite:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ?; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; A few new pieces of code are generated beyond the `Author` struct. An interface for the underlying database is generated. The `*sql.DB` and `*sql.Tx` types satisfy this interface. The database access methods are added to a `Queries` struct, which is created using the `New` method. Note that the `*` in our query has been replaced with explicit column names. This change ensures that the query will never return unexpected data. Our query was annotated with `:one`, meaning that it should only return a single row. We scan the data from that one into a `Author` struct. Since the get query has a single parameter, the `GetAuthor` method takes a single `int` as an argument. Since the list query has no parameters, the `ListAuthors` method accepts no arguments. package db import ( "context" "database/sql" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getAuthor \= \`-- name: GetAuthor :one SELECT id, bio, birth\_year FROM authors WHERE id = $1 \` func (q \*Queries) GetAuthor(ctx context.Context, id int) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) var i Author err := row.Scan(&i.ID, &i.Bio, &i.BirthYear) return i, err } const listAuthors \= \`-- name: ListAuthors :many SELECT id, bio, birth\_year FROM authors ORDER BY id \` func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } Selecting columns[](https://docs.sqlc.dev/en/latest/howto/select.html#selecting-columns "Link to this heading") ----------------------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id \= $1; \-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id \= $1; When selecting a single column, only that value is returned. The `GetBioForAuthor` method takes a single `int` as an argument and returns a `string` and an `error`. When selecting multiple columns, a row record (method-specific struct) is returned. In this case, `GetInfoForAuthor` returns a struct with two fields: `Bio` and `BirthYear`. If a query result has no row records, a zero value and an `ErrNoRows` error are returned instead of a zero value and `nil`. For instance, when the `GetBioForAuthor` result has no rows, it will return `""` and `ErrNoRows`. package db import ( "context" "database/sql" ) type DBTX interface { QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getBioForAuthor \= \`-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id = $1 \` func (q \*Queries) GetBioForAuthor(ctx context.Context, id int) (string, error) { row := q.db.QueryRowContext(ctx, getBioForAuthor, id) var i string err := row.Scan(&i) return i, err } const getInfoForAuthor \= \`-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id = $1 \` type GetInfoForAuthorRow struct { Bio string BirthYear int } func (q \*Queries) GetInfoForAuthor(ctx context.Context, id int) (GetInfoForAuthorRow, error) { row := q.db.QueryRowContext(ctx, getInfoForAuthor, id) var i GetInfoForAuthorRow err := row.Scan(&i.Bio, &i.BirthYear) return i, err } Passing a slice as a parameter to a query[](https://docs.sqlc.dev/en/latest/howto/select.html#passing-a-slice-as-a-parameter-to-a-query "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------------- ### PostgreSQL[](https://docs.sqlc.dev/en/latest/howto/select.html#postgresql "Link to this heading") In PostgreSQL, [ANY](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.28.16) allows you to check if a value exists in an array expression. Queries using ANY with a single parameter will generate method signatures with slices as arguments. Use the postgres data types, eg: int, varchar, etc. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id \= ANY($1::int\[\]); The above SQL will generate the following code: package db import ( "context" "database/sql" "github.com/lib/pq" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const listAuthors \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id = ANY($1::int\[\]) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors, pq.Array(ids)) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } ### MySQL and SQLite[](https://docs.sqlc.dev/en/latest/howto/select.html#mysql-and-sqlite "Link to this heading") MySQL and SQLite differ from PostgreSQL in that placeholders must be generated based on the number of elements in the slice you pass in. Though trivial it is still something of a nuisance. The passed in slice must not be nil or empty or an error will be returned (ie not a panic). The placeholder insertion location is marked by the meta-function `sqlc.slice()` (which is similar to `sqlc.arg()` that you see documented under [Naming parameters](https://docs.sqlc.dev/en/latest/howto/named_parameters.html) ). To rephrase, the `sqlc.slice('param')` behaves identically to `sqlc.arg()` it terms of how it maps the explicit argument to the function signature, eg: * `sqlc.slice('ids')` maps to `ids []GoType` in the function signature * `sqlc.slice(cust_ids)` maps to `custIds []GoType` in the function signature (like `sqlc.arg()`, the parameter does not have to be quoted) This feature is not compatible with `emit_prepared_queries` statement found in the [Configuration file](https://docs.sqlc.dev/en/latest/reference/config.html) . CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id IN (sqlc.slice('ids')); The above SQL will generate the following code: package db import ( "context" "database/sql" "fmt" "strings" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } const listAuthorsByIDs \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id IN (/\*SLICE:ids\*/?) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int64) (\[\]Author, error) { sql := listAuthorsByIDs var queryParams \[\]interface{} if len(ids) \== 0 { return nil, fmt.Errorf("slice ids must have at least one element") } for \_, v := range ids { queryParams \= append(queryParams, v) } sql \= strings.Replace(sql, "/\*SLICE:ids\*/?", strings.Repeat(",?", len(ids))\[1:\], 1) rows, err := q.db.QueryContext(ctx, sql, queryParams...) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Preparing queries — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Preparing queries * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/prepared_query.md.txt) * * * Preparing queries[](https://docs.sqlc.dev/en/latest/howto/prepared_query.html#preparing-queries "Link to this heading") ========================================================================================================================= If you’re using `pgx/v5` you get its [implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching) for prepared statements. No additional `sqlc` configuration is required. For other drivers, `sqlc` can give you the option to explicitly use prepared queries. These prepared queries also work with transactions. You’ll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration to generate code similar to the example below. CREATE TABLE records ( id SERIAL PRIMARY KEY ); \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; package db import ( "context" "database/sql" "fmt" ) type Record struct { ID int32 } type DBTX interface { PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } func Prepare(ctx context.Context, db DBTX) (\*Queries, error) { q := Queries{db: db} var err error if q.getRecordStmt, err \= db.PrepareContext(ctx, getRecord); err != nil { return nil, fmt.Errorf("error preparing query GetRecord: %w", err) } return &q, nil } func (q \*Queries) queryRow(ctx context.Context, stmt \*sql.Stmt, query string, args ...interface{}) \*sql.Row { switch { case stmt != nil && q.tx != nil: return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...) case stmt != nil: return stmt.QueryRowContext(ctx, args...) default: return q.db.QueryRowContext(ctx, query, args...) } } type Queries struct { db DBTX tx \*sql.Tx getRecordStmt \*sql.Stmt } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, tx: tx, getRecordStmt: q.getRecordStmt, } } const getRecord \= \`-- name: GetRecord :one SELECT id FROM records WHERE id = $1 \` func (q \*Queries) GetRecord(ctx context.Context, id int32) (int32, error) { row := q.queryRow(ctx, q.getRecordStmt, getRecord, id) err := row.Scan(&id) return id, err } --- # Renaming fields — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Renaming fields * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/rename.md.txt) * * * Renaming fields[](https://docs.sqlc.dev/en/latest/howto/rename.html#renaming-fields "Link to this heading") ============================================================================================================= Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" rename: spotify\_url: "SpotifyURL" Tables[](https://docs.sqlc.dev/en/latest/howto/rename.html#tables "Link to this heading") ------------------------------------------------------------------------------------------- The output structs associated with tables can also be renamed. By default, the struct name will be the singular version of the table name. For example, the `authors` table will generate an `Author` struct and the `book_publishers` table will generate a `BookPublisher` struct. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); CREATE TABLE book\_publishers ( id BIGSERIAL PRIMARY KEY, name text NOT NULL ); package db import ( "database/sql" ) type Author struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } To rename these structs, you must use the generated struct name. In this example, that would be `author` and `book_publisher`. Use the `rename` map to change the name of these struct to `Writer` and `BookPublisher` (note the camel-casing and the underscore for multi-worded tables). version: '1' packages: \- path: db engine: postgresql schema: query.sql queries: query.sql rename: author: Writer book\_publisher: Publisher version: "2" sql: \- engine: postgresql queries: query.sql schema: query.sql overrides: go: rename: author: Writer book\_publisher: Publisher package db import ( "database/sql" ) type Writer struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } Limitations[](https://docs.sqlc.dev/en/latest/howto/rename.html#limitations "Link to this heading") ----------------------------------------------------------------------------------------------------- Rename mappings apply to an entire package. Therefore, a column named `foo` and a table name `foo` can’t map to different rename values. --- # Using Go and pgx — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Using Go and pgx * [View page source](https://docs.sqlc.dev/en/latest/_sources/guides/using-go-and-pgx.rst.txt) * * * Using Go and pgx[](https://docs.sqlc.dev/en/latest/guides/using-go-and-pgx.html#using-go-and-pgx "Link to this heading") ========================================================================================================================== Note `pgx/v5` is supported starting from v1.18.0. pgx is a pure Go driver and toolkit for PostgreSQL. It’s become the default PostgreSQL package for many Gophers since lib/pq was put into maintenance mode. Getting started[](https://docs.sqlc.dev/en/latest/guides/using-go-and-pgx.html#getting-started "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ To start generating code that uses pgx, set the `sql_package` field in your `sqlc.yaml` configuration file. Valid options are `pgx/v4` or `pgx/v5` version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" If you don’t have an existing sqlc project on hand, create a directory with the configuration file above and the following `query.sql` file. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; Generating the code will now give you pgx-compatible database access methods. sqlc generate Generated code walkthrough[](https://docs.sqlc.dev/en/latest/guides/using-go-and-pgx.html#generated-code-walkthrough "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------- The generated code is very similar to the code generated when using `lib/pq`. However, instead of using `database/sql`, the code uses pgx types directly. package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v5" "example.com/sqlc-tutorial/db" ) func main() { // urlExample := "postgres://username:password@localhost:5432/database\_name" conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\\n", err) os.Exit(1) } defer conn.Close(context.Background()) q := db.New(conn) author, err := q.GetAuthor(context.Background(), 1) if err != nil { fmt.Fprintf(os.Stderr, "GetAuthor failed: %v\\n", err) os.Exit(1) } fmt.Println(author.Name) } Note For production applications, consider using pgxpool for connection pooling: import ( "github.com/jackc/pgx/v5/pgxpool" "example.com/sqlc-tutorial/db" ) func main() { pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\\n", err) os.Exit(1) } defer pool.Close() q := db.New(pool) // Use q the same way as with single connections } --- # Overriding types — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Overriding types * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/overrides.md.txt) * * * Overriding types[](https://docs.sqlc.dev/en/latest/howto/overrides.html#overriding-types "Link to this heading") ================================================================================================================== Note Type overrides and field renaming are only fully-supported for Go. In many cases it’s useful to tell `sqlc` explicitly what Go type you want it to use for a query input or output. For instance, by default when you use `pgx/v5`, `sqlc` will map a PostgreSQL UUID type to `UUID` from `github.com/jackc/pgx/pgtype`. But you may want `sqlc` to use `UUID` from `github.com/google/uuid` instead. To tell `sqlc` to use a different Go type, add an entry to the `overrides` list in your configuration. `sqlc` offers two kinds of Go type overrides: * `db_type` overrides, which override the Go type for a specific database type. * `column` overrides, which override the Go type for a column or columns by name. Here’s an example including one of each kind: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" nullable: true go\_type: import: "github.com/google/uuid" type: "UUID" \- column: "users.birthday" go\_type: "time.Time" Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. The `overrides` list[](https://docs.sqlc.dev/en/latest/howto/overrides.html#the-overrides-list "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ Each element in the `overrides` list has the following keys: * `db_type`: * A database type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use pg\_catalog-prefixed names where available. `db_type` and `column` are mutually exclusive. * `column`: * A column name to override. The value should be of the form `table.column` but you can also specify `schema.table.column` or `catalog.schema.table.column`. `column` and `db_type` are mutually exclusive. * `go_type`: * The fully-qualified name of a Go type to use in generated code. This is usually a string but can also be [a map](https://docs.sqlc.dev/en/latest/howto/overrides.html#the-go-type-map) for more complex configurations. * `go_struct_tag`: * A reflect-style struct tag to use in generated code, e.g. `a:"b" x:"y,z"`. If you want `json` or `db` tags for all fields, configure `emit_json_tags` or `emit_db_tags` instead. * `unsigned`: * If `true`, sqlc will apply this override when a numeric column is unsigned. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. * `nullable`: * If `true`, sqlc will apply this override when a column is nullable. Otherwise `sqlc` will apply this override when a column is non-nullable. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. Note When generating code, `column` override configurations take precedence over `db_type` configurations. ### The `go_type` map[](https://docs.sqlc.dev/en/latest/howto/overrides.html#the-go-type-map "Link to this heading") Some overrides may require more detailed configuration. If necessary, `go_type` can be a map with the following keys: * `import`: * The import path for the package where the type is defined. * `package`: * The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name. * `type`: * The type name itself, without any package prefix. * `pointer`: * If `true`, generated code will use a pointer to the type rather than the type itself. * `slice`: * If `true`, generated code will use a slice of the type rather than the type itself. An example: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" go\_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true Global overrides[](https://docs.sqlc.dev/en/latest/howto/overrides.html#global-overrides "Link to this heading") ------------------------------------------------------------------------------------------------------------------ To override types in all packages that `sqlc` generates, add an override configuration to the top-level `overrides` section of your `sqlc` config: version: "2" overrides: go: overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "service1/schema.sql" queries: "service1/query.sql" engine: "postgresql" gen: go: package: "service1" out: "service1" \- schema: "service2/schema.sql" queries: "service2/query.sql" engine: "postgresql" gen: go: package: "service2" out: "service2" Using this configuration, whenever there is a nullable `timestamp with time zone` column in a Postgres table, `sqlc` will generate Go code using `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in per-package type overrides. This field is only used when there are multiple `sql` sections using different engines. If you’re only generating code for a single database engine you can omit it. ### Version 1 configuration[](https://docs.sqlc.dev/en/latest/howto/overrides.html#version-1-configuration "Link to this heading") If you are using the older version 1 of the `sqlc` configuration format, override configurations themselves are unchanged but are nested differently. Per-package configurations are nested under the `overrides` key within an item in the `packages` list: version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" overrides: \[...\] And global configurations are nested under the top-level `overrides` key: version: "1" packages: \[...\] overrides: \- db\_type: "uuid" go\_type: "github.com/gofrs/uuid.UUID" --- # Database and language support — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Database and language support * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/language-support.rst) * * * Database and language support[](https://docs.sqlc.dev/en/v1.27.0/reference/language-support.html#database-and-language-support "Link to this heading") ======================================================================================================================================================== | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Go | (built-in) | Stable | Stable | Beta | | Go | [sqlc-gen-go](https://github.com/sqlc-dev/sqlc-gen-go) | Stable | Stable | Beta | | Kotlin | [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) | Beta | Beta | Not implemented | | Python | [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) | Beta | Beta | Not implemented | | TypeScript | [sqlc-gen-typescript](https://github.com/sqlc-dev/sqlc-gen-typescript) | Beta | Beta | Not implemented | Community language support[](https://docs.sqlc.dev/en/v1.27.0/reference/language-support.html#community-language-support "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------- New languages can be added via [plugins](https://docs.sqlc.dev/en/v1.27.0/guides/plugins.html) . | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | F# | [kaashyapan/sqlc-gen-fsharp](https://github.com/kaashyapan/sqlc-gen-fsharp) | Not implemented | Beta | Beta | | C# | [DaredevilOSS/sqlc-gen-csharp](https://github.com/DaredevilOSS/sqlc-gen-csharp) | Beta | Beta | Not implemented | | Ruby | [DaredevilOSS/sqlc-gen-ruby](https://github.com/DaredevilOSS/sqlc-gen-ruby) | Beta | Beta | Beta | Future language support[](https://docs.sqlc.dev/en/v1.27.0/reference/language-support.html#future-language-support "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- --- # CLI — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * CLI * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/cli.md) * * * CLI[](https://docs.sqlc.dev/en/v1.27.0/reference/cli.html#cli "Link to this heading") ======================================================================================= Usage: sqlc \[command\] Available Commands: compile Statically check SQL for syntax and type errors completion Generate the autocompletion script for the specified shell createdb Create an ephemeral database diff Compare the generated files to the existing files generate Generate source code from SQL help Help about any command init Create an empty sqlc.yaml settings file push Push the schema, queries, and configuration for this project verify Verify schema, queries, and configuration for this project version Print the sqlc version number vet Vet examines queries Flags: \-f, \--file string specify an alternate config file (default: sqlc.yaml) \-h, \--help help for sqlc \--no-database disable database connections (default: false) \--no-remote disable remote execution (default: false) Use "sqlc \[command\] --help" for more information about a command. --- # Using plugins — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Using plugins * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/guides/plugins.md) * * * Using plugins[](https://docs.sqlc.dev/en/v1.27.0/guides/plugins.html#using-plugins "Link to this heading") ============================================================================================================ To use plugins, you must be using [Version 2](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#version-2) of the configuration file. The top-level `plugins` array defines the available plugins. WASM plugins[](https://docs.sqlc.dev/en/v1.27.0/guides/plugins.html#wasm-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------- > WASM plugins are fully sandboxed; they do not have access to the network, filesystem, or environment variables. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: greeter wasm: url: https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm sha256: afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07 sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: greeter options: lang: en-US For a complete working example see the following files: * [sqlc-gen-greeter](https://github.com/sqlc-dev/sqlc-gen-greeter) * A WASM plugin (written in Rust) that outputs a friendly message * [wasm\_plugin\_sqlc\_gen\_greeter](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter) * An example project showing how to use a WASM plugin Process plugins[](https://docs.sqlc.dev/en/v1.27.0/guides/plugins.html#process-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------------- > Process-based plugins offer minimal security. Only use plugins that you trust. Better yet, only use plugins that you’ve written yourself. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: jsonb process: cmd: sqlc-gen-json sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: jsonb options: indent: " " filename: codegen.json For a complete working example see the following files: * [sqlc-gen-json](https://github.com/sqlc-dev/sqlc/tree/main/cmd/sqlc-gen-json) * A process-based plugin that serializes the CodeGenRequest to JSON * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json) * An example project showing how to use a process-based plugin Environment variables[](https://docs.sqlc.dev/en/v1.27.0/guides/plugins.html#environment-variables "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- By default, plugins do not inherit access to environment variables. Instead, you can configure access on a per-variable basis. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. --- # Using Go and pgx — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Using Go and pgx * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/guides/using-go-and-pgx.rst) * * * Using Go and pgx[](https://docs.sqlc.dev/en/v1.27.0/guides/using-go-and-pgx.html#using-go-and-pgx "Link to this heading") =========================================================================================================================== Note `pgx/v5` is supported starting from v1.18.0. pgx is a pure Go driver and toolkit for PostgreSQL. It’s become the default PostgreSQL package for many Gophers since lib/pq was put into maintenance mode. Getting started[](https://docs.sqlc.dev/en/v1.27.0/guides/using-go-and-pgx.html#getting-started "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- To start generating code that uses pgx, set the `sql_package` field in your `sqlc.yaml` configuration file. Valid options are `pgx/v4` or `pgx/v5` version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" If you don’t have an existing sqlc project on hand, create a directory with the configuration file above and the following `query.sql` file. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; Generating the code will now give you pgx-compatible database access methods. sqlc generate Generated code walkthrough[](https://docs.sqlc.dev/en/v1.27.0/guides/using-go-and-pgx.html#generated-code-walkthrough "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------- The generated code is very similar to the code generated when using `lib/pq`. However, instead of using `database/sql`, the code uses pgx types directly. package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v5" "example.com/sqlc-tutorial/db" ) func main() { // urlExample := "postgres://username:password@localhost:5432/database\_name" conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\\n", err) os.Exit(1) } defer conn.Close(context.Background()) q := db.New(conn) author, err := q.GetAuthor(context.Background(), 1) if err != nil { fmt.Fprintf(os.Stderr, "GetAuthor failed: %v\\n", err) os.Exit(1) } fmt.Println(author.Name) } --- # Getting started with MySQL — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Getting started with MySQL * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/tutorials/getting-started-mysql.md.txt) * * * Getting started with MySQL[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-mysql.html#getting-started-with-mysql "Link to this heading") ======================================================================================================================================================= This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.31.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.31.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-mysql.html#setting-up "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-mysql.html#schema-and-queries "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGINT NOT NULL AUTO\_INCREMENT PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following four queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :execresult INSERT INTO authors ( name, bio ) VALUES ( ?, ? ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; Generating code[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-mysql.html#generating-code "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-mysql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" "log" "reflect" \_ "github.com/go-sql-driver/mysql" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() db, err := sql.Open("mysql", "user:password@/dbname?parseTime=true") if err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant MySQL driver: go get github.com/go-sql-driver/mysql go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `sql.Open()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-mysql.html#query-verification "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial --- # Environment variables — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Environment variables * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/environment-variables.md.txt) * * * Environment variables[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#environment-variables "Link to this heading") ============================================================================================================================================ SQLCEXPERIMENT[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#sqlcexperiment "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------ The `SQLCEXPERIMENT` variable controls experimental features within sqlc. It is a comma-separated list of experiment names. This is modeled after Go’s [GOEXPERIMENT](https://pkg.go.dev/internal/goexperiment) environment variable. Experiment names can be prefixed with `no` to explicitly disable them. SQLCEXPERIMENT\=foo,bar \# enable foo and bar experiments SQLCEXPERIMENT\=nofoo \# explicitly disable foo experiment SQLCEXPERIMENT\=foo,nobar \# enable foo, disable bar Currently, no experiments are defined. Experiments will be documented here as they are introduced. SQLCCACHE[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#sqlccache "Link to this heading") -------------------------------------------------------------------------------------------------------------------- The `SQLCCACHE` environment variable dictates where `sqlc` will store cached WASM-based plugins and modules. By default `sqlc` follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) . SQLCDEBUG[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#sqlcdebug "Link to this heading") -------------------------------------------------------------------------------------------------------------------- The `SQLCDEBUG` variable controls debugging variables within the runtime. It is a comma-separated list of name=val pairs settings. ### dumpast[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#dumpast "Link to this heading") The `dumpast` command shows the SQL AST that was generated by the parser. Note that this is the generic SQL AST, not the engine-specific SQL AST. SQLCDEBUG\=dumpast\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc0004f48c0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc0004f4930)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc00052ff20)({ Rel: (\*ast.TableName)(0xc00052fda0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### dumpcatalog[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#dumpcatalog "Link to this heading") The `dumpcatalog` command outputs the entire catalog. If you’re using MySQL or PostgreSQL, this can be a bit overwhelming. Expect this output to change in future versions. SQLCDEBUG\=dumpcatalog\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc00050d1f0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc00050d260)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc0000c0840)({ Rel: (\*ast.TableName)(0xc0000c06c0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### trace[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#trace "Link to this heading") The `trace` command is helpful for tracking down performance issues. `SQLCDEBUG=trace=1` By default, the trace output is written to `trace.out` in the current working directory. You can configure a different path if needed. `SQLCDEBUG=trace=name.out` View the execution trace using the Go `trace` tool. go tool trace trace.out There’s a ton of different views for the trace output, but here’s an example log showing the execution time for each package. 0.000043897 . 1 task sqlc (id 1, parent 0) created 0.000144923 . 101026 1 region generate started (duration: 47.619781ms) 0.001048975 . 904052 1 region package started (duration: 14.588456ms) 0.001054616 . 5641 1 name\=authors dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.001071257 . 16641 1 region parse started (duration: 7.966549ms) 0.009043960 . 7972703 1 region codegen started (duration: 6.587086ms) 0.009171704 . 127744 1 new goroutine 35: text/template/parse.lex·dwrap·1 0.010361654 . 1189950 1 new goroutine 36: text/template/parse.lex·dwrap·1 0.015641815 . 5280161 1 region package started (duration: 10.904938ms) 0.015644943 . 3128 1 name\=booktest dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.015647431 . 2488 1 region parse started (duration: 4.207749ms) 0.019860308 . 4212877 1 region codegen started (duration: 6.681624ms) 0.020028488 . 168180 1 new goroutine 37: text/template/parse.lex·dwrap·1 0.021020310 . 991822 1 new goroutine 8: text/template/parse.lex·dwrap·1 0.026551163 . 5530853 1 region package started (duration: 9.217294ms) 0.026554368 . 3205 1 name\=jets dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.026556804 . 2436 1 region parse started (duration: 3.491005ms) 0.030051911 . 3495107 1 region codegen started (duration: 5.711931ms) 0.030213937 . 162026 1 new goroutine 20: text/template/parse.lex·dwrap·1 0.031099938 . 886001 1 new goroutine 38: text/template/parse.lex·dwrap·1 0.035772637 . 4672699 1 region package started (duration: 10.267039ms) 0.035775688 . 3051 1 name\=ondeck dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.035778150 . 2462 1 region parse started (duration: 4.094518ms) 0.039877181 . 4099031 1 region codegen started (duration: 6.156341ms) 0.040010771 . 133590 1 new goroutine 39: text/template/parse.lex·dwrap·1 0.040894567 . 883796 1 new goroutine 40: text/template/parse.lex·dwrap·1 0.046042779 . 5148212 1 region writefiles started (duration: 1.718259ms) 0.047767781 . 1725002 1 task end ### processplugins[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#processplugins "Link to this heading") Setting this value to `0` disables process-based plugins. If a process-based plugin is declared in the configuration file, running any `sqlc` command will return an error. `SQLCDEBUG=processplugins=0` ### dumpvetenv[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#dumpvetenv "Link to this heading") The `dumpvetenv` command prints the variables available to a `sqlc vet` rule during evaluation. `SQLCDEBUG=dumpvetenv=1` ### dumpexplain[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#dumpexplain "Link to this heading") The `dumpexplain` command prints the JSON-formatted result from running `EXPLAIN ...` on a query when a `sqlc vet` rule evaluation requires its output. `SQLCDEBUG=dumpexplain=1` SQLCTMPDIR[](https://docs.sqlc.dev/en/latest/reference/environment-variables.html#sqlctmpdir "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- If specified, use the given directory as the base for temporary folders. Only applies when using WASM-based codegen plugins. When not specified, this defaults to passing an empty string to [`os.MkdirTemp`](https://pkg.go.dev/os#MkdirTemp) . --- # Query annotations — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Query annotations * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/query-annotations.md.txt) * * * Query annotations[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#query-annotations "Link to this heading") ================================================================================================================================ sqlc requires each query to have a small comment indicating the name and command. The format of this comment is as follows: \-- name: `:exec`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#exec "Link to this heading") --------------------------------------------------------------------------------------------------------- The generated method will return the error from [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; func (q \*Queries) DeleteAuthor(ctx context.Context, id int64) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } `:execresult`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#execresult "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The generated method will return the [sql.Result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execresult DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (sql.Result, error) { return q.db.ExecContext(ctx, deleteAllAuthors) } `:execrows`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#execrows "Link to this heading") ----------------------------------------------------------------------------------------------------------------- The generated method will return the number of affected rows from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execrows DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (int64, error) { \_, err := q.db.ExecContext(ctx, deleteAllAuthors) // ... } `:execlastid`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#execlastid "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The generated method will return the number generated by the database from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: InsertAuthor :execlastid INSERT INTO authors (name) VALUES (?); func (q \*Queries) InsertAuthor(ctx context.Context, name string) (int64, error) { \_, err := q.db.ExecContext(ctx, insertAuthor, name) // ... } `:many`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#many "Link to this heading") --------------------------------------------------------------------------------------------------------- The generated method will return a slice of records via [QueryContext](https://golang.org/pkg/database/sql/#DB.QueryContext) . \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) // ... } `:one`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#one "Link to this heading") ------------------------------------------------------------------------------------------------------- The generated method will return a single record via [QueryRowContext](https://golang.org/pkg/database/sql/#DB.QueryRowContext) . \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; func (q \*Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) // ... } `:batchexec`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#batchexec "Link to this heading") ------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Exec`, that takes a `func(int, error)` parameter, * `Close`, to close the batch operation early. \-- name: DeleteBook :batchexec DELETE FROM books WHERE book\_id \= $1; type DeleteBookBatchResults struct { br pgx.BatchResults ind int } func (q \*Queries) DeleteBook(ctx context.Context, bookID \[\]int32) \*DeleteBookBatchResults { //... } func (b \*DeleteBookBatchResults) Exec(f func(int, error)) { //... } func (b \*DeleteBookBatchResults) Close() error { //... } `:batchmany`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#batchmany "Link to this heading") ------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Query`, that takes a `func(int, []T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: BooksByTitleYear :batchmany SELECT \* FROM books WHERE title \= $1 AND year \= $2; type BooksByTitleYearBatchResults struct { br pgx.BatchResults ind int } type BooksByTitleYearParams struct { Title string \`json:"title"\` Year int32 \`json:"year"\` } func (q \*Queries) BooksByTitleYear(ctx context.Context, arg \[\]BooksByTitleYearParams) \*BooksByTitleYearBatchResults { //... } func (b \*BooksByTitleYearBatchResults) Query(f func(int, \[\]Book, error)) { //... } func (b \*BooksByTitleYearBatchResults) Close() error { //... } `:batchone`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#batchone "Link to this heading") ----------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `QueryRow`, that takes a `func(int, T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: CreateBook :batchone INSERT INTO books ( author\_id, isbn ) VALUES ( $1, $2 ) RETURNING book\_id, author\_id, isbn type CreateBookBatchResults struct { br pgx.BatchResults ind int } type CreateBookParams struct { AuthorID int32 \`json:"author\_id"\` Isbn string \`json:"isbn"\` } func (q \*Queries) CreateBook(ctx context.Context, arg \[\]CreateBookParams) \*CreateBookBatchResults { //... } func (b \*CreateBookBatchResults) QueryRow(f func(int, Book, error)) { //... } func (b \*CreateBookBatchResults) Close() error { //... } `:copyfrom`[](https://docs.sqlc.dev/en/latest/reference/query-annotations.html#copyfrom "Link to this heading") ----------------------------------------------------------------------------------------------------------------- \_\_NOTE: This command is driver and package specific, see [how to insert](https://docs.sqlc.dev/en/latest/howto/insert.html#using-copyfrom) This command is used to insert rows a lot faster than sequential inserts. --- # Datatypes — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Datatypes * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/datatypes.md.txt) * * * Datatypes[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#datatypes "Link to this heading") ======================================================================================================== `sqlc` attempts to make reasonable default choices when mapping internal database types to Go types. Choices for more complex types are described below. If you’re unsatisfied with the default, you can override any type using the [overrides list](https://docs.sqlc.dev/en/latest/reference/config.html#overrides) in your `sqlc` config file. Arrays[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#arrays "Link to this heading") -------------------------------------------------------------------------------------------------- PostgreSQL [arrays](https://www.postgresql.org/docs/current/arrays.html) are materialized as Go slices. CREATE TABLE places ( name text not null, tags text\[\] ); package db type Place struct { Name string Tags \[\]string } Dates and times[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#dates-and-times "Link to this heading") -------------------------------------------------------------------------------------------------------------------- All date and time types are returned as `time.Time` structs. For null time or date values, the `NullTime` type from `database/sql` is used. The `pgx/v5` sql package uses the appropriate pgx types. For MySQL users relying on `github.com/go-sql-driver/mysql`, ensure that `parseTime=true` is added to your database connection string. CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL DEFAULT NOW(), updated\_at timestamp ); package db import ( "database/sql" "time" ) type Author struct { ID int CreatedAt time.Time UpdatedAt sql.NullTime } Enums[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#enums "Link to this heading") ------------------------------------------------------------------------------------------------ PostgreSQL [enums](https://www.postgresql.org/docs/current/datatype-enum.html) are mapped to an aliased string type. CREATE TYPE status AS ENUM ( 'open', 'closed' ); CREATE TABLE stores ( name text PRIMARY KEY, status status NOT NULL ); package db type Status string const ( StatusOpen Status \= "open" StatusClosed Status \= "closed" ) type Store struct { Name string Status Status } Null[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#null "Link to this heading") ---------------------------------------------------------------------------------------------- For structs, null values are represented using the appropriate type from the `database/sql` or `pgx` package. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text ); package db import ( "database/sql" ) type Author struct { ID int Name string Bio sql.NullString } UUIDs[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#uuids "Link to this heading") ------------------------------------------------------------------------------------------------ The Go standard library does not come with a `uuid` package. For UUID support, sqlc uses the excellent `github.com/google/uuid` package. The pgx/v5 sql package uses `pgtype.UUID`. CREATE TABLE records ( id uuid PRIMARY KEY ); package db import ( "github.com/google/uuid" ) type Author struct { ID uuid.UUID } For MySQL, there is no native `uuid` data type. When using `UUID_TO_BIN` to store a `UUID()`, the underlying field type is `BINARY(16)` which by default sqlc would map to `sql.NullString`. To have sqlc automatically convert these fields to a `uuid.UUID` type, use an overide on the column storing the `uuid` (see [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for details). { "overrides": \[\ {\ "column": "\*.uuid",\ "go\_type": "github.com/google/uuid.UUID"\ }\ \] } JSON[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#json "Link to this heading") ---------------------------------------------------------------------------------------------- By default, sqlc will generate the `[]byte`, `pgtype.JSON` or `json.RawMessage` for JSON column type. But if you use the `pgx/v5` sql package then you can specify a struct instead of the default type (see [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for details). The `pgx` implementation will marshal/unmarshal the struct automatically. package dto type BookData struct { Genres \[\]string \`json:"genres"\` Title string \`json:"title"\` Published bool \`json:"published"\` } CREATE TABLE books ( data jsonb ); { "overrides": \[\ {\ "column": "books.data",\ "go\_type": {\ "import":"example.com/db",\ "package": "dto",\ "type":"BookData",\ "pointer": true\ }\ }\ \] } package db import ( "example.com/db/dto" ) type Book struct { Data \*dto.BookData } TEXT[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#text "Link to this heading") ---------------------------------------------------------------------------------------------- In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a Go string by default. This default mapping applies to `TEXT` columns that are not nullable. However, for nullable `TEXT` columns, sqlc maps them to `pgtype.Text` when using the pgx/v5 driver. This distinction is crucial for developers looking to handle null values appropriately in their Go applications. To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in your sqlc config file (see [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for details). Geometry[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#geometry "Link to this heading") ------------------------------------------------------------------------------------------------------ ### PostGIS[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#postgis "Link to this heading") #### Using `github.com/twpayne/go-geos` (pgx/v5 only)[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#using-github-com-twpayne-go-geos-pgx-v5-only "Link to this heading") sqlc can be configured to use the [geos](https://github.com/twpayne/go-geos) package for working with PostGIS geometry types in [GEOS](https://libgeos.org/) . There are three steps: 1. Configure sqlc to use `*github.com/twpayne/go-geos.Geom` for geometry types (see [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for details). 2. Call `github.com/twpayne/pgx-geos.Register` on each `*github.com/jackc/pgx/v5.Conn`. 3. Annotate your SQL with `::geometry` typecasts, if needed. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetCentroids :many SELECT id, name, ST\_Centroid(geom)::geometry FROM shapes; { "version": 2, "gen": { "go": { "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": {\ "import": "github.com/twpayne/go-geos",\ "package": "geos",\ "pointer": true,\ "type": "Geom"\ },\ "nullable": true\ }\ \] } } } import ( "github.com/twpayne/go-geos" pgxgeos "github.com/twpayne/pgx-geos" ) // ... config.AfterConnect \= func(ctx context.Context, conn \*pgx.Conn) error { if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil { return err } return nil } #### Using `github.com/twpayne/go-geom`[](https://docs.sqlc.dev/en/latest/reference/datatypes.html#using-github-com-twpayne-go-geom "Link to this heading") sqlc can be configured to use the [geom](https://github.com/twpayne/go-geom) package for working with PostGIS geometry types. See [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for more information. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetShapes :many SELECT \* FROM shapes; { "version": "1", "packages": \[\ {\ "path": "db",\ "engine": "postgresql",\ "schema": "query.sql",\ "queries": "query.sql"\ }\ \], "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon"\ },\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon",\ "nullable": true\ }\ \] } --- # push - Uploading projects — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * `push` - Uploading projects * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/push.md.txt) * * * `push` - Uploading projects[](https://docs.sqlc.dev/en/stable/howto/push.html#push-uploading-projects "Link to this heading") =============================================================================================================================== Note `push` is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. _Added in v1.24.0_ We’ve renamed the `upload` sub-command to `push`. We’ve also changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. Add configuration[](https://docs.sqlc.dev/en/stable/howto/push.html#add-configuration "Link to this heading") --------------------------------------------------------------------------------------------------------------- After creating a project, add the project ID to your sqlc configuration file. version: "2" cloud: project: "" You’ll also need to create an auth token and make it available via the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Dry run[](https://docs.sqlc.dev/en/stable/howto/push.html#dry-run "Link to this heading") ------------------------------------------------------------------------------------------- You can see what’s included when uploading your project by using using the `--dry-run` flag: $ sqlc push \--dry-run 2023/11/21 10:39:51 INFO config file\=sqlc.yaml bytes\=912 2023/11/21 10:39:51 INFO codegen\_request queryset\=app file\=codegen\_request.pb 2023/11/21 10:39:51 INFO schema queryset\=app file\=migrations/00001\_initial.sql bytes\=3033 2023/11/21 10:39:51 INFO query queryset\=app file\=queries/app.sql bytes\=1150 The output is the files `sqlc` would have sent without the `--dry-run` flag. Push[](https://docs.sqlc.dev/en/stable/howto/push.html#push "Link to this heading") ------------------------------------------------------------------------------------- Once you’re ready to push, remove the `--dry-run` flag. $ sqlc push ### Tags[](https://docs.sqlc.dev/en/stable/howto/push.html#tags "Link to this heading") You can provide tags to associate with a push, primarily as a convenient reference when using `sqlc verify` with the `against` argument. Tags only refer to a single push, so if you pass an existing tag to `push` it will overwrite the previous reference. $ sqlc push \--tag main ### Annotations[](https://docs.sqlc.dev/en/stable/howto/push.html#annotations "Link to this heading") Annotations are added to each push request. By default, we include these environment variables (if they are present). GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA --- # Getting started with MySQL — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Getting started with MySQL * [View page source](https://docs.sqlc.dev/en/stable/_sources/tutorials/getting-started-mysql.md.txt) * * * Getting started with MySQL[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-mysql.html#getting-started-with-mysql "Link to this heading") ====================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/stable/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/stable/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-mysql.html#setting-up "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-mysql.html#schema-and-queries "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGINT NOT NULL AUTO\_INCREMENT PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following four queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :execresult INSERT INTO authors ( name, bio ) VALUES ( ?, ? ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; Generating code[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-mysql.html#generating-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-mysql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------ You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" "log" "reflect" \_ "github.com/go-sql-driver/mysql" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() db, err := sql.Open("mysql", "user:password@/dbname?parseTime=true") if err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant MySQL driver: go get github.com/go-sql-driver/mysql go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `sql.Open()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-mysql.html#query-verification "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial --- # Counting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Counting rows * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/query_count.md.txt) * * * Counting rows[](https://docs.sqlc.dev/en/stable/howto/query_count.html#counting-rows "Link to this heading") ============================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, hometown text NOT NULL ); \-- name: CountAuthors :one SELECT count(\*) FROM authors; \-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1; package db import ( "context" "database/sql" ) type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const countAuthors \= \`-- name: CountAuthors :one SELECT count(\*) FROM authors \` func (q \*Queries) CountAuthors(ctx context.Context) (int, error) { row := q.db.QueryRowContext(ctx, countAuthors) var i int err := row.Scan(&i) return i, err } const countAuthorsByTown \= \`-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1 \` type CountAuthorsByTownRow struct { Hometown string Count int } func (q \*Queries) CountAuthorsByTown(ctx context.Context) (\[\]CountAuthorsByTownRow, error) { rows, err := q.db.QueryContext(ctx, countAuthorsByTown) if err != nil { return nil, err } defer rows.Close() items := \[\]CountAuthorsByTownRow{} for rows.Next() { var i CountAuthorsByTownRow if err := rows.Scan(&i.Hometown, &i.Count); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Inserting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Inserting rows * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/insert.md.txt) * * * Inserting rows[](https://docs.sqlc.dev/en/stable/howto/insert.html#inserting-rows "Link to this heading") =========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1); **MySQL and SQLite:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES (?); package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const createAuthor \= \`-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1) \` func (q \*Queries) CreateAuthor(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, createAuthor, bio) return err } Returning columns from inserted rows[](https://docs.sqlc.dev/en/stable/howto/insert.html#returning-columns-from-inserted-rows "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------- sqlc has full support for the `RETURNING` statement. \-- Example queries for sqlc CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); **PostgreSQL:** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id; **SQLite (with RETURNING support):** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING id; Note: MySQL does not support the `RETURNING` clause. Use `:execresult` instead to get the last insert ID. package db import ( "context" "database/sql" ) const createAuthor \= \`-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id, name, bio \` type CreateAuthorParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) var i Author err := row.Scan(&i.ID, &i.Name, &i.Bio) return i, err } const createAuthorAndReturnId \= \`-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id \` type CreateAuthorAndReturnIdParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthorAndReturnId(ctx context.Context, arg CreateAuthorAndReturnIdParams) (int64, error) { row := q.db.QueryRowContext(ctx, createAuthorAndReturnId, arg.Name, arg.Bio) var id int64 err := row.Scan(&id) return id, err } Using CopyFrom[](https://docs.sqlc.dev/en/stable/howto/insert.html#using-copyfrom "Link to this heading") ----------------------------------------------------------------------------------------------------------- ### PostgreSQL[](https://docs.sqlc.dev/en/stable/howto/insert.html#postgresql "Link to this heading") PostgreSQL supports the [COPY protocol](https://www.postgresql.org/docs/current/sql-copy.html) that can insert rows a lot faster than sequential inserts. You can use this easily with sqlc: CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text NOT NULL ); \-- name: CreateAuthors :copyfrom INSERT INTO authors (name, bio) VALUES ($1, $2); type CreateAuthorsParams struct { Name string Bio string } func (q \*Queries) CreateAuthors(ctx context.Context, arg \[\]CreateAuthorsParams) (int64, error) { ... } The `:copyfrom` command requires either `pgx/v4` or `pgx/v5`. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" ### MySQL[](https://docs.sqlc.dev/en/stable/howto/insert.html#mysql "Link to this heading") MySQL supports a similar feature using [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) . Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use SHOW WARNINGS to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } The `:copyfrom` command requires setting the `sql_package` and `sql_driver` options. version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "database/sql" sql\_driver: "github.com/go-sql-driver/mysql" out: "db" --- # Updating rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Updating rows * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/update.md.txt) * * * Updating rows[](https://docs.sqlc.dev/en/stable/howto/update.html#updating-rows "Link to this heading") ========================================================================================================= CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); Single parameter[](https://docs.sqlc.dev/en/stable/howto/update.html#single-parameter "Link to this heading") --------------------------------------------------------------------------------------------------------------- If your query has a single parameter, your Go method will also have a single parameter. The parameter syntax varies by database engine: **PostgreSQL:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= $1; **MySQL and SQLite:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthorBios \= \`-- name: UpdateAuthorBios :exec UPDATE authors SET bio = $1 \` func (q \*Queries) UpdateAuthorBios(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, updateAuthorBios, bio) return err } Multiple parameters[](https://docs.sqlc.dev/en/stable/howto/update.html#multiple-parameters "Link to this heading") --------------------------------------------------------------------------------------------------------------------- If your query has more than one parameter, your Go method will accept a `Params` struct. **PostgreSQL:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= $2 WHERE id \= $1; **MySQL and SQLite:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= ? WHERE id \= ?; Note: For MySQL and SQLite, parameters are bound in the order they appear in the query, regardless of the order in the function signature. package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthor \= \`-- name: UpdateAuthor :exec UPDATE authors SET bio = $2 WHERE id = $1 \` type UpdateAuthorParams struct { ID int32 Bio string } func (q \*Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error { \_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio) return err } --- # Naming parameters — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Naming parameters * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/named_parameters.md.txt) * * * Naming parameters[](https://docs.sqlc.dev/en/stable/howto/named_parameters.html#naming-parameters "Link to this heading") =========================================================================================================================== sqlc tries to generate good names for positional parameters, but sometimes it lacks enough context. The following SQL generates parameters with less than ideal names: \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN $1::bool THEN $2::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { Column1 bool \`json:""\` Column2\_2 string \`json:"\_2"\` } In these cases, named parameters give you the control over field names on the Params struct. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN sqlc.arg(set\_name)::bool THEN sqlc.arg(name)::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { SetName bool \`json:"set\_name"\` Name string \`json:"name"\` } If the `sqlc.arg()` syntax is too verbose for your taste, you can use the `@` operator as a shortcut. Note The `@` operator as a shortcut for `sqlc.arg()` is not supported in MySQL. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN @set\_name::bool THEN @name::text ELSE name END RETURNING \*; Nullable parameters[](https://docs.sqlc.dev/en/stable/howto/named_parameters.html#nullable-parameters "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------- sqlc infers the nullability of any specified parameters, and often does exactly what you want. If you want finer control over the nullability of your parameters, you may use `sqlc.narg()` (**n**ullable arg) to override the default behavior. Using `sqlc.narg` tells sqlc to ignore whatever nullability it has inferred and generate a nullable parameter instead. There is no nullable equivalent of the `@` syntax. Here is an example that uses a single query to allow updating an author’s name, bio or both. \-- name: UpdateAuthor :one UPDATE author SET name \= coalesce(sqlc.narg('name'), name), bio \= coalesce(sqlc.narg('bio'), bio) WHERE id \= sqlc.arg('id') RETURNING \*; The following code is generated: type UpdateAuthorParams struct { Name sql.NullString Bio sql.NullString ID int64 } --- # Using transactions — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Using transactions * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/transactions.md.txt) * * * Using transactions[](https://docs.sqlc.dev/en/stable/howto/transactions.html#using-transactions "Link to this heading") ========================================================================================================================= In the code generated by sqlc, the `WithTx` method allows a `Queries` instance to be associated with a transaction. For example, with the following SQL structure: `schema.sql`: CREATE TABLE records ( id SERIAL PRIMARY KEY, counter INT NOT NULL ); `query.sql` \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; \-- name: UpdateRecord :exec UPDATE records SET counter \= $2 WHERE id \= $1; And the generated code from sqlc in `db.go`: package tutorial import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } You’d use it like this: // Using \`github/lib/pq\` as the driver. func bumpCounter(ctx context.Context, db \*sql.DB, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin() if err != nil { return err } defer tx.Rollback() qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit() } // Using \`github.com/jackc/pgx/v5\` as the driver. func bumpCounter(ctx context.Context, db \*pgx.Conn, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin(ctx) if err != nil { return err } defer tx.Rollback(ctx) qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit(ctx) } --- # push - Uploading projects — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * `push` - Uploading projects * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/push.md.txt) * * * `push` - Uploading projects[](https://docs.sqlc.dev/en/v1.31.0/howto/push.html#push-uploading-projects "Link to this heading") ================================================================================================================================ Note `push` is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. _Added in v1.24.0_ We’ve renamed the `upload` sub-command to `push`. We’ve also changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. Add configuration[](https://docs.sqlc.dev/en/v1.31.0/howto/push.html#add-configuration "Link to this heading") ---------------------------------------------------------------------------------------------------------------- After creating a project, add the project ID to your sqlc configuration file. version: "2" cloud: project: "" You’ll also need to create an auth token and make it available via the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Dry run[](https://docs.sqlc.dev/en/v1.31.0/howto/push.html#dry-run "Link to this heading") -------------------------------------------------------------------------------------------- You can see what’s included when uploading your project by using using the `--dry-run` flag: $ sqlc push \--dry-run 2023/11/21 10:39:51 INFO config file\=sqlc.yaml bytes\=912 2023/11/21 10:39:51 INFO codegen\_request queryset\=app file\=codegen\_request.pb 2023/11/21 10:39:51 INFO schema queryset\=app file\=migrations/00001\_initial.sql bytes\=3033 2023/11/21 10:39:51 INFO query queryset\=app file\=queries/app.sql bytes\=1150 The output is the files `sqlc` would have sent without the `--dry-run` flag. Push[](https://docs.sqlc.dev/en/v1.31.0/howto/push.html#push "Link to this heading") -------------------------------------------------------------------------------------- Once you’re ready to push, remove the `--dry-run` flag. $ sqlc push ### Tags[](https://docs.sqlc.dev/en/v1.31.0/howto/push.html#tags "Link to this heading") You can provide tags to associate with a push, primarily as a convenient reference when using `sqlc verify` with the `against` argument. Tags only refer to a single push, so if you pass an existing tag to `push` it will overwrite the previous reference. $ sqlc push \--tag main ### Annotations[](https://docs.sqlc.dev/en/v1.31.0/howto/push.html#annotations "Link to this heading") Annotations are added to each push request. By default, we include these environment variables (if they are present). GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA --- # Embedding structs — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Embedding structs * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/embedding.md.txt) * * * Embedding structs[](https://docs.sqlc.dev/en/stable/howto/embedding.html#embedding-structs "Link to this heading") ==================================================================================================================== Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text NOT NULL, age integer NOT NULL ); CREATE TABLE test\_scores ( student\_id bigint NOT NULL, score integer NOT NULL, grade text NOT NULL ); We want to select the student record and the scores they got on a test. Here’s how we’d usually do that: \-- name: ScoreAndTests :many SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; When using Go, sqlc will produce a struct like this: type ScoreAndTestsRow struct { ID int64 Name string Age int32 StudentID int64 Score int32 Grade string } With embedding, the struct will contain a model for both tables instead of a flattened list of columns. \-- name: ScoreAndTests :many SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; type ScoreAndTestsRow struct { Student Student TestScore TestScore } --- # Counting rows — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Counting rows * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/query_count.md.txt) * * * Counting rows[](https://docs.sqlc.dev/en/v1.31.0/howto/query_count.html#counting-rows "Link to this heading") =============================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, hometown text NOT NULL ); \-- name: CountAuthors :one SELECT count(\*) FROM authors; \-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1; package db import ( "context" "database/sql" ) type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const countAuthors \= \`-- name: CountAuthors :one SELECT count(\*) FROM authors \` func (q \*Queries) CountAuthors(ctx context.Context) (int, error) { row := q.db.QueryRowContext(ctx, countAuthors) var i int err := row.Scan(&i) return i, err } const countAuthorsByTown \= \`-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1 \` type CountAuthorsByTownRow struct { Hometown string Count int } func (q \*Queries) CountAuthorsByTown(ctx context.Context) (\[\]CountAuthorsByTownRow, error) { rows, err := q.db.QueryContext(ctx, countAuthorsByTown) if err != nil { return nil, err } defer rows.Close() items := \[\]CountAuthorsByTownRow{} for rows.Next() { var i CountAuthorsByTownRow if err := rows.Scan(&i.Hometown, &i.Count); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Naming parameters — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Naming parameters * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/named_parameters.md.txt) * * * Naming parameters[](https://docs.sqlc.dev/en/v1.31.0/howto/named_parameters.html#naming-parameters "Link to this heading") ============================================================================================================================ sqlc tries to generate good names for positional parameters, but sometimes it lacks enough context. The following SQL generates parameters with less than ideal names: \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN $1::bool THEN $2::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { Column1 bool \`json:""\` Column2\_2 string \`json:"\_2"\` } In these cases, named parameters give you the control over field names on the Params struct. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN sqlc.arg(set\_name)::bool THEN sqlc.arg(name)::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { SetName bool \`json:"set\_name"\` Name string \`json:"name"\` } If the `sqlc.arg()` syntax is too verbose for your taste, you can use the `@` operator as a shortcut. Note The `@` operator as a shortcut for `sqlc.arg()` is not supported in MySQL. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN @set\_name::bool THEN @name::text ELSE name END RETURNING \*; Nullable parameters[](https://docs.sqlc.dev/en/v1.31.0/howto/named_parameters.html#nullable-parameters "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------- sqlc infers the nullability of any specified parameters, and often does exactly what you want. If you want finer control over the nullability of your parameters, you may use `sqlc.narg()` (**n**ullable arg) to override the default behavior. Using `sqlc.narg` tells sqlc to ignore whatever nullability it has inferred and generate a nullable parameter instead. There is no nullable equivalent of the `@` syntax. Here is an example that uses a single query to allow updating an author’s name, bio or both. \-- name: UpdateAuthor :one UPDATE author SET name \= coalesce(sqlc.narg('name'), name), bio \= coalesce(sqlc.narg('bio'), bio) WHERE id \= sqlc.arg('id') RETURNING \*; The following code is generated: type UpdateAuthorParams struct { Name sql.NullString Bio sql.NullString ID int64 } --- # Updating rows — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Updating rows * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/update.md.txt) * * * Updating rows[](https://docs.sqlc.dev/en/v1.31.0/howto/update.html#updating-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); Single parameter[](https://docs.sqlc.dev/en/v1.31.0/howto/update.html#single-parameter "Link to this heading") ---------------------------------------------------------------------------------------------------------------- If your query has a single parameter, your Go method will also have a single parameter. The parameter syntax varies by database engine: **PostgreSQL:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= $1; **MySQL and SQLite:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthorBios \= \`-- name: UpdateAuthorBios :exec UPDATE authors SET bio = $1 \` func (q \*Queries) UpdateAuthorBios(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, updateAuthorBios, bio) return err } Multiple parameters[](https://docs.sqlc.dev/en/v1.31.0/howto/update.html#multiple-parameters "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- If your query has more than one parameter, your Go method will accept a `Params` struct. **PostgreSQL:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= $2 WHERE id \= $1; **MySQL and SQLite:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= ? WHERE id \= ?; Note: For MySQL and SQLite, parameters are bound in the order they appear in the query, regardless of the order in the function signature. package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthor \= \`-- name: UpdateAuthor :exec UPDATE authors SET bio = $2 WHERE id = $1 \` type UpdateAuthorParams struct { ID int32 Bio string } func (q \*Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error { \_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio) return err } --- # Using transactions — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Using transactions * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/transactions.md.txt) * * * Using transactions[](https://docs.sqlc.dev/en/v1.31.0/howto/transactions.html#using-transactions "Link to this heading") ========================================================================================================================== In the code generated by sqlc, the `WithTx` method allows a `Queries` instance to be associated with a transaction. For example, with the following SQL structure: `schema.sql`: CREATE TABLE records ( id SERIAL PRIMARY KEY, counter INT NOT NULL ); `query.sql` \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; \-- name: UpdateRecord :exec UPDATE records SET counter \= $2 WHERE id \= $1; And the generated code from sqlc in `db.go`: package tutorial import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } You’d use it like this: // Using \`github/lib/pq\` as the driver. func bumpCounter(ctx context.Context, db \*sql.DB, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin() if err != nil { return err } defer tx.Rollback() qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit() } // Using \`github.com/jackc/pgx/v5\` as the driver. func bumpCounter(ctx context.Context, db \*pgx.Conn, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin(ctx) if err != nil { return err } defer tx.Rollback(ctx) qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit(ctx) } --- # Embedding structs — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Embedding structs * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/embedding.md.txt) * * * Embedding structs[](https://docs.sqlc.dev/en/v1.31.0/howto/embedding.html#embedding-structs "Link to this heading") ===================================================================================================================== Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text NOT NULL, age integer NOT NULL ); CREATE TABLE test\_scores ( student\_id bigint NOT NULL, score integer NOT NULL, grade text NOT NULL ); We want to select the student record and the scores they got on a test. Here’s how we’d usually do that: \-- name: ScoreAndTests :many SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; When using Go, sqlc will produce a struct like this: type ScoreAndTestsRow struct { ID int64 Name string Age int32 StudentID int64 Score int32 Grade string } With embedding, the struct will contain a model for both tables instead of a flattened list of columns. \-- name: ScoreAndTests :many SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; type ScoreAndTestsRow struct { Student Student TestScore TestScore } --- # push - Uploading projects — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * `push` - Uploading projects * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/push.md.txt) * * * `push` - Uploading projects[](https://docs.sqlc.dev/en/v1.31.1/howto/push.html#push-uploading-projects "Link to this heading") ================================================================================================================================ Note `push` is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. _Added in v1.24.0_ We’ve renamed the `upload` sub-command to `push`. We’ve also changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. Add configuration[](https://docs.sqlc.dev/en/v1.31.1/howto/push.html#add-configuration "Link to this heading") ---------------------------------------------------------------------------------------------------------------- After creating a project, add the project ID to your sqlc configuration file. version: "2" cloud: project: "" You’ll also need to create an auth token and make it available via the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Dry run[](https://docs.sqlc.dev/en/v1.31.1/howto/push.html#dry-run "Link to this heading") -------------------------------------------------------------------------------------------- You can see what’s included when uploading your project by using using the `--dry-run` flag: $ sqlc push \--dry-run 2023/11/21 10:39:51 INFO config file\=sqlc.yaml bytes\=912 2023/11/21 10:39:51 INFO codegen\_request queryset\=app file\=codegen\_request.pb 2023/11/21 10:39:51 INFO schema queryset\=app file\=migrations/00001\_initial.sql bytes\=3033 2023/11/21 10:39:51 INFO query queryset\=app file\=queries/app.sql bytes\=1150 The output is the files `sqlc` would have sent without the `--dry-run` flag. Push[](https://docs.sqlc.dev/en/v1.31.1/howto/push.html#push "Link to this heading") -------------------------------------------------------------------------------------- Once you’re ready to push, remove the `--dry-run` flag. $ sqlc push ### Tags[](https://docs.sqlc.dev/en/v1.31.1/howto/push.html#tags "Link to this heading") You can provide tags to associate with a push, primarily as a convenient reference when using `sqlc verify` with the `against` argument. Tags only refer to a single push, so if you pass an existing tag to `push` it will overwrite the previous reference. $ sqlc push \--tag main ### Annotations[](https://docs.sqlc.dev/en/v1.31.1/howto/push.html#annotations "Link to this heading") Annotations are added to each push request. By default, we include these environment variables (if they are present). GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA --- # Counting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Counting rows * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/query_count.md.txt) * * * Counting rows[](https://docs.sqlc.dev/en/v1.31.1/howto/query_count.html#counting-rows "Link to this heading") =============================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, hometown text NOT NULL ); \-- name: CountAuthors :one SELECT count(\*) FROM authors; \-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1; package db import ( "context" "database/sql" ) type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const countAuthors \= \`-- name: CountAuthors :one SELECT count(\*) FROM authors \` func (q \*Queries) CountAuthors(ctx context.Context) (int, error) { row := q.db.QueryRowContext(ctx, countAuthors) var i int err := row.Scan(&i) return i, err } const countAuthorsByTown \= \`-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1 \` type CountAuthorsByTownRow struct { Hometown string Count int } func (q \*Queries) CountAuthorsByTown(ctx context.Context) (\[\]CountAuthorsByTownRow, error) { rows, err := q.db.QueryContext(ctx, countAuthorsByTown) if err != nil { return nil, err } defer rows.Close() items := \[\]CountAuthorsByTownRow{} for rows.Next() { var i CountAuthorsByTownRow if err := rows.Scan(&i.Hometown, &i.Count); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Updating rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Updating rows * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/update.md.txt) * * * Updating rows[](https://docs.sqlc.dev/en/v1.31.1/howto/update.html#updating-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); Single parameter[](https://docs.sqlc.dev/en/v1.31.1/howto/update.html#single-parameter "Link to this heading") ---------------------------------------------------------------------------------------------------------------- If your query has a single parameter, your Go method will also have a single parameter. The parameter syntax varies by database engine: **PostgreSQL:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= $1; **MySQL and SQLite:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthorBios \= \`-- name: UpdateAuthorBios :exec UPDATE authors SET bio = $1 \` func (q \*Queries) UpdateAuthorBios(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, updateAuthorBios, bio) return err } Multiple parameters[](https://docs.sqlc.dev/en/v1.31.1/howto/update.html#multiple-parameters "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- If your query has more than one parameter, your Go method will accept a `Params` struct. **PostgreSQL:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= $2 WHERE id \= $1; **MySQL and SQLite:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= ? WHERE id \= ?; Note: For MySQL and SQLite, parameters are bound in the order they appear in the query, regardless of the order in the function signature. package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthor \= \`-- name: UpdateAuthor :exec UPDATE authors SET bio = $2 WHERE id = $1 \` type UpdateAuthorParams struct { ID int32 Bio string } func (q \*Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error { \_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio) return err } --- # Using transactions — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Using transactions * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/transactions.md.txt) * * * Using transactions[](https://docs.sqlc.dev/en/v1.31.1/howto/transactions.html#using-transactions "Link to this heading") ========================================================================================================================== In the code generated by sqlc, the `WithTx` method allows a `Queries` instance to be associated with a transaction. For example, with the following SQL structure: `schema.sql`: CREATE TABLE records ( id SERIAL PRIMARY KEY, counter INT NOT NULL ); `query.sql` \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; \-- name: UpdateRecord :exec UPDATE records SET counter \= $2 WHERE id \= $1; And the generated code from sqlc in `db.go`: package tutorial import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } You’d use it like this: // Using \`github/lib/pq\` as the driver. func bumpCounter(ctx context.Context, db \*sql.DB, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin() if err != nil { return err } defer tx.Rollback() qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit() } // Using \`github.com/jackc/pgx/v5\` as the driver. func bumpCounter(ctx context.Context, db \*pgx.Conn, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin(ctx) if err != nil { return err } defer tx.Rollback(ctx) qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit(ctx) } --- # CLI — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * CLI * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/cli.md.txt) * * * CLI[](https://docs.sqlc.dev/en/latest/reference/cli.html#cli "Link to this heading") ====================================================================================== Usage: sqlc \[command\] Available Commands: compile Statically check SQL for syntax and type errors completion Generate the autocompletion script for the specified shell createdb Create an ephemeral database diff Compare the generated files to the existing files generate Generate source code from SQL help Help about any command init Create an empty sqlc.yaml settings file push Push the schema, queries, and configuration for this project verify Verify schema, queries, and configuration for this project version Print the sqlc version number vet Vet examines queries Flags: \-f, \--file string specify an alternate config file (default: sqlc.yaml) \-h, \--help help for sqlc \--no-database disable database connections (default: false) Use "sqlc \[command\] --help" for more information about a command. --- # Privacy and data collection — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Privacy and data collection * [View page source](https://docs.sqlc.dev/en/latest/_sources/guides/privacy.md.txt) * * * Privacy and data collection[](https://docs.sqlc.dev/en/latest/guides/privacy.html#privacy-and-data-collection "Link to this heading") ======================================================================================================================================= These days, it feels like every piece of software is tracking you. From your browser, to your phone, to your terminal, programs collect as much data about you as possible and send it off to the cloud for analysis. We believe the best way to keep data safe is to never collect it in the first place. Our Privacy Pledge[](https://docs.sqlc.dev/en/latest/guides/privacy.html#our-privacy-pledge "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `sqlc` command line tool does not collect any information. It does not send crash reports to a third-party. It does not gather anonymous aggregate user behaviour analytics. No analytics. No finger-printing. No tracking. Not now and not in the future. ### Distribution Channels[](https://docs.sqlc.dev/en/latest/guides/privacy.html#distribution-channels "Link to this heading") We distribute sqlc using popular package managers such as [Homebrew](https://brew.sh/) and [Snapcraft](https://snapcraft.io/) . These package managers and their associated command-line tools do collect usage metrics. We use these services to make it easy to for users to install sqlc. There will always be an option to download sqlc from a stable URL. Hosted Services[](https://docs.sqlc.dev/en/latest/guides/privacy.html#hosted-services "Link to this heading") --------------------------------------------------------------------------------------------------------------- We provide a few hosted services in addition to the sqlc command line tool. ### sqlc.dev[](https://docs.sqlc.dev/en/latest/guides/privacy.html#sqlc-dev "Link to this heading") * Hosted on [GitHub Pages](https://pages.github.com/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### docs.sqlc.dev[](https://docs.sqlc.dev/en/latest/guides/privacy.html#docs-sqlc-dev "Link to this heading") * Hosted on [Read the Docs](https://readthedocs.org/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### play.sqlc.dev[](https://docs.sqlc.dev/en/latest/guides/privacy.html#play-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Playground data stored in [Google Cloud Storage](https://cloud.google.com/storage) * Automatically deleted after 30 days ### app.sqlc.dev / api.sqlc.dev[](https://docs.sqlc.dev/en/latest/guides/privacy.html#app-sqlc-dev-api-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Error tracking and tracing with [Sentry](https://sentry.io/) --- # Privacy and data collection — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Privacy and data collection * [View page source](https://docs.sqlc.dev/en/stable/_sources/guides/privacy.md.txt) * * * Privacy and data collection[](https://docs.sqlc.dev/en/stable/guides/privacy.html#privacy-and-data-collection "Link to this heading") ======================================================================================================================================= These days, it feels like every piece of software is tracking you. From your browser, to your phone, to your terminal, programs collect as much data about you as possible and send it off to the cloud for analysis. We believe the best way to keep data safe is to never collect it in the first place. Our Privacy Pledge[](https://docs.sqlc.dev/en/stable/guides/privacy.html#our-privacy-pledge "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `sqlc` command line tool does not collect any information. It does not send crash reports to a third-party. It does not gather anonymous aggregate user behaviour analytics. No analytics. No finger-printing. No tracking. Not now and not in the future. ### Distribution Channels[](https://docs.sqlc.dev/en/stable/guides/privacy.html#distribution-channels "Link to this heading") We distribute sqlc using popular package managers such as [Homebrew](https://brew.sh/) and [Snapcraft](https://snapcraft.io/) . These package managers and their associated command-line tools do collect usage metrics. We use these services to make it easy to for users to install sqlc. There will always be an option to download sqlc from a stable URL. Hosted Services[](https://docs.sqlc.dev/en/stable/guides/privacy.html#hosted-services "Link to this heading") --------------------------------------------------------------------------------------------------------------- We provide a few hosted services in addition to the sqlc command line tool. ### sqlc.dev[](https://docs.sqlc.dev/en/stable/guides/privacy.html#sqlc-dev "Link to this heading") * Hosted on [GitHub Pages](https://pages.github.com/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### docs.sqlc.dev[](https://docs.sqlc.dev/en/stable/guides/privacy.html#docs-sqlc-dev "Link to this heading") * Hosted on [Read the Docs](https://readthedocs.org/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### play.sqlc.dev[](https://docs.sqlc.dev/en/stable/guides/privacy.html#play-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Playground data stored in [Google Cloud Storage](https://cloud.google.com/storage) * Automatically deleted after 30 days ### app.sqlc.dev / api.sqlc.dev[](https://docs.sqlc.dev/en/stable/guides/privacy.html#app-sqlc-dev-api-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Error tracking and tracing with [Sentry](https://sentry.io/) --- # Privacy and data collection — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Privacy and data collection * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/guides/privacy.md.txt) * * * Privacy and data collection[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#privacy-and-data-collection "Link to this heading") ======================================================================================================================================== These days, it feels like every piece of software is tracking you. From your browser, to your phone, to your terminal, programs collect as much data about you as possible and send it off to the cloud for analysis. We believe the best way to keep data safe is to never collect it in the first place. Our Privacy Pledge[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#our-privacy-pledge "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The `sqlc` command line tool does not collect any information. It does not send crash reports to a third-party. It does not gather anonymous aggregate user behaviour analytics. No analytics. No finger-printing. No tracking. Not now and not in the future. ### Distribution Channels[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#distribution-channels "Link to this heading") We distribute sqlc using popular package managers such as [Homebrew](https://brew.sh/) and [Snapcraft](https://snapcraft.io/) . These package managers and their associated command-line tools do collect usage metrics. We use these services to make it easy to for users to install sqlc. There will always be an option to download sqlc from a stable URL. Hosted Services[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#hosted-services "Link to this heading") ---------------------------------------------------------------------------------------------------------------- We provide a few hosted services in addition to the sqlc command line tool. ### sqlc.dev[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#sqlc-dev "Link to this heading") * Hosted on [GitHub Pages](https://pages.github.com/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### docs.sqlc.dev[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#docs-sqlc-dev "Link to this heading") * Hosted on [Read the Docs](https://readthedocs.org/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### play.sqlc.dev[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#play-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Playground data stored in [Google Cloud Storage](https://cloud.google.com/storage) * Automatically deleted after 30 days ### app.sqlc.dev / api.sqlc.dev[](https://docs.sqlc.dev/en/v1.31.0/guides/privacy.html#app-sqlc-dev-api-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Error tracking and tracing with [Sentry](https://sentry.io/) --- # Updating rows — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Updating rows * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/update.md) * * * Updating rows[](https://docs.sqlc.dev/en/v1.27.0/howto/update.html#updating-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); Single parameter[](https://docs.sqlc.dev/en/v1.27.0/howto/update.html#single-parameter "Link to this heading") ---------------------------------------------------------------------------------------------------------------- If your query has a single parameter, your Go method will also have a single parameter. \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= $1; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthorBios \= \`-- name: UpdateAuthorBios :exec UPDATE authors SET bio = $1 \` func (q \*Queries) UpdateAuthorBios(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, updateAuthorBios, bio) return err } Multiple parameters[](https://docs.sqlc.dev/en/v1.27.0/howto/update.html#multiple-parameters "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- If your query has more than one parameter, your Go method will accept a `Params` struct. \-- name: UpdateAuthor :exec UPDATE authors SET bio \= $2 WHERE id \= $1; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthor \= \`-- name: UpdateAuthor :exec UPDATE authors SET bio = $2 WHERE id = $1 \` type UpdateAuthorParams struct { ID int32 Bio string } func (q \*Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error { \_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio) return err } --- # Privacy and data collection — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Privacy and data collection * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/guides/privacy.md.txt) * * * Privacy and data collection[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#privacy-and-data-collection "Link to this heading") ======================================================================================================================================== These days, it feels like every piece of software is tracking you. From your browser, to your phone, to your terminal, programs collect as much data about you as possible and send it off to the cloud for analysis. We believe the best way to keep data safe is to never collect it in the first place. Our Privacy Pledge[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#our-privacy-pledge "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The `sqlc` command line tool does not collect any information. It does not send crash reports to a third-party. It does not gather anonymous aggregate user behaviour analytics. No analytics. No finger-printing. No tracking. Not now and not in the future. ### Distribution Channels[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#distribution-channels "Link to this heading") We distribute sqlc using popular package managers such as [Homebrew](https://brew.sh/) and [Snapcraft](https://snapcraft.io/) . These package managers and their associated command-line tools do collect usage metrics. We use these services to make it easy to for users to install sqlc. There will always be an option to download sqlc from a stable URL. Hosted Services[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#hosted-services "Link to this heading") ---------------------------------------------------------------------------------------------------------------- We provide a few hosted services in addition to the sqlc command line tool. ### sqlc.dev[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#sqlc-dev "Link to this heading") * Hosted on [GitHub Pages](https://pages.github.com/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### docs.sqlc.dev[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#docs-sqlc-dev "Link to this heading") * Hosted on [Read the Docs](https://readthedocs.org/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### play.sqlc.dev[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#play-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Playground data stored in [Google Cloud Storage](https://cloud.google.com/storage) * Automatically deleted after 30 days ### app.sqlc.dev / api.sqlc.dev[](https://docs.sqlc.dev/en/v1.31.1/guides/privacy.html#app-sqlc-dev-api-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Error tracking and tracing with [Sentry](https://sentry.io/) --- # Using transactions — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Using transactions * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/transactions.md) * * * Using transactions[](https://docs.sqlc.dev/en/v1.27.0/howto/transactions.html#using-transactions "Link to this heading") ========================================================================================================================== In the code generated by sqlc, the `WithTx` method allows a `Queries` instance to be associated with a transaction. For example, with the following SQL structure: `schema.sql`: CREATE TABLE records ( id SERIAL PRIMARY KEY, counter INT NOT NULL ); `query.sql` \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; \-- name: UpdateRecord :exec UPDATE records SET counter \= $2 WHERE id \= $1; And the generated code from sqlc in `db.go`: package tutorial import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } You’d use it like this: func bumpCounter(ctx context.Context, db \*sql.DB, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin() if err != nil { return err } defer tx.Rollback() qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit() } --- # Naming parameters — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Naming parameters * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/named_parameters.md) * * * Naming parameters[](https://docs.sqlc.dev/en/v1.27.0/howto/named_parameters.html#naming-parameters "Link to this heading") ============================================================================================================================ sqlc tries to generate good names for positional parameters, but sometimes it lacks enough context. The following SQL generates parameters with less than ideal names: \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN $1::bool THEN $2::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { Column1 bool \`json:""\` Column2\_2 string \`json:"\_2"\` } In these cases, named parameters give you the control over field names on the Params struct. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN sqlc.arg(set\_name)::bool THEN sqlc.arg(name)::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { SetName bool \`json:"set\_name"\` Name string \`json:"name"\` } If the `sqlc.arg()` syntax is too verbose for your taste, you can use the `@` operator as a shortcut. Note The `@` operator as a shortcut for `sqlc.arg()` is not supported in MySQL. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN @set\_name::bool THEN @name::text ELSE name END RETURNING \*; Nullable parameters[](https://docs.sqlc.dev/en/v1.27.0/howto/named_parameters.html#nullable-parameters "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------- sqlc infers the nullability of any specified parameters, and often does exactly what you want. If you want finer control over the nullability of your parameters, you may use `sqlc.narg()` (**n**ullable arg) to override the default behavior. Using `sqlc.narg` tells sqlc to ignore whatever nullability it has inferred and generate a nullable parameter instead. There is no nullable equivalent of the `@` syntax. Here is an example that uses a single query to allow updating an author’s name, bio or both. \-- name: UpdateAuthor :one UPDATE author SET name \= coalesce(sqlc.narg('name'), name), bio \= coalesce(sqlc.narg('bio'), bio) WHERE id \= sqlc.arg('id') RETURNING \*; The following code is generated: type UpdateAuthorParams struct { Name sql.NullString Bio sql.NullString ID int64 } --- # Modifying the database schema — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Modifying the database schema * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/ddl.md) * * * Modifying the database schema[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#modifying-the-database-schema "Link to this heading") ======================================================================================================================================= sqlc parses `CREATE TABLE` and `ALTER TABLE` statements in order to generate the necessary code. CREATE TABLE authors ( id SERIAL PRIMARY KEY, birth\_year int NOT NULL ); ALTER TABLE authors ADD COLUMN bio text NOT NULL; ALTER TABLE authors DROP COLUMN birth\_year; ALTER TABLE authors RENAME TO writers; package db type Writer struct { ID int Bio string } Handling SQL migrations[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#handling-sql-migrations "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- sqlc does not perform database migrations for you. However, sqlc is able to differentiate between up and down migrations. sqlc ignores down migrations when parsing SQL files. sqlc supports parsing migrations from the following tools: * [atlas](https://github.com/ariga/atlas) * [dbmate](https://github.com/amacneil/dbmate) * [golang-migrate](https://github.com/golang-migrate/migrate) * [goose](https://github.com/pressly/goose) * [sql-migrate](https://github.com/rubenv/sql-migrate) * [tern](https://github.com/jackc/tern) To enable migration parsing, specify the migration directory instead of a schema file: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "db/migrations" gen: go: package: "tutorial" out: "tutorial" ### atlas[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#atlas "Link to this heading") \-- Create "post" table CREATE TABLE "public"."post" ("id" integer NOT NULL, "title" text NULL, "body" text NULL, PRIMARY KEY ("id")); package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### dbmate[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#dbmate "Link to this heading") \-- migrate:up CREATE TABLE foo (bar INT NOT NULL); \-- migrate:down DROP TABLE foo; package db type Foo struct { Bar int32 } ### golang-migrate[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#golang-migrate "Link to this heading") **Warning:** [golang-migrate interprets](https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md#migration-filename-format) migration filenames numerically. However, sqlc parses migration files in lexicographic order. If you choose to have sqlc enumerate your migration files, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.up.sql ... 9\_foo.up.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.up.sql This worked as intended. 001\_initial.up.sql ... 009\_foo.up.sql 010\_bar.up.sql In `20060102.up.sql`: CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); In `20060102.down.sql`: DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### goose[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#goose "Link to this heading") **Warning:** sqlc parses migration files in lexicographic order. **If you are using numeric filenames for migrations in Goose and you choose to have sqlc enumerate your migration files**, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.sql ... 9\_foo.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.sql This worked as intended. 001\_initial.sql ... 009\_foo.sql 010\_bar.sql \-- +goose Up CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); \-- +goose Down DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### sql-migrate[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#sql-migrate "Link to this heading") \-- +migrate Up \-- SQL in section 'Up' is executed when this migration is applied CREATE TABLE people (id int); \-- +migrate Down \-- SQL section 'Down' is executed when this migration is rolled back DROP TABLE people; package db type People struct { ID int32 } ### tern[](https://docs.sqlc.dev/en/v1.27.0/howto/ddl.html#tern "Link to this heading") CREATE TABLE comment (id int NOT NULL, text text NOT NULL); \---- create above / drop below ---- DROP TABLE comment; package db type Comment struct { ID int32 Text string } --- # Installing sqlc — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Installing sqlc * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/overview/install.md) * * * Installing sqlc[](https://docs.sqlc.dev/en/v1.27.0/overview/install.html#installing-sqlc "Link to this heading") ================================================================================================================== sqlc is distributed as a single binary with zero dependencies. macOS[](https://docs.sqlc.dev/en/v1.27.0/overview/install.html#macos "Link to this heading") ---------------------------------------------------------------------------------------------- brew install sqlc Ubuntu[](https://docs.sqlc.dev/en/v1.27.0/overview/install.html#ubuntu "Link to this heading") ------------------------------------------------------------------------------------------------ sudo snap install sqlc go install[](https://docs.sqlc.dev/en/v1.27.0/overview/install.html#go-install "Link to this heading") -------------------------------------------------------------------------------------------------------- Installing recent versions of sqlc requires Go 1.21+. go install github.com/sqlc\-dev/sqlc/cmd/sqlc@latest Docker[](https://docs.sqlc.dev/en/v1.27.0/overview/install.html#docker "Link to this heading") ------------------------------------------------------------------------------------------------ docker pull sqlc/sqlc Run `sqlc` using `docker run`: docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate Run `sqlc` using `docker run` in the Command Prompt on Windows (`cmd`): docker run \--rm \-v "%cd%:/src" \-w /src sqlc/sqlc generate Downloads[](https://docs.sqlc.dev/en/v1.27.0/overview/install.html#downloads "Link to this heading") ------------------------------------------------------------------------------------------------------ Get pre-built binaries for _v1.27.0_: * [Linux](https://downloads.sqlc.dev/sqlc_1.27.0_linux_amd64.tar.gz) * [macOS](https://downloads.sqlc.dev/sqlc_1.27.0_darwin_amd64.zip) * [Windows](https://downloads.sqlc.dev/sqlc_1.27.0_windows_amd64.zip) See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions. --- # Deleting rows — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Deleting rows * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/delete.md) * * * Deleting rows[](https://docs.sqlc.dev/en/v1.27.0/howto/delete.html#deleting-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const deleteAuthor \= \`-- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $1 \` func (q \*Queries) DeleteAuthor(ctx context.Context, id int) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } --- # push - Uploading projects — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * `push` - Uploading projects * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/push.md) * * * `push` - Uploading projects[](https://docs.sqlc.dev/en/v1.27.0/howto/push.html#push-uploading-projects "Link to this heading") ================================================================================================================================ Note `push` is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. _Added in v1.24.0_ We’ve renamed the `upload` sub-command to `push`. We’ve also changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. Add configuration[](https://docs.sqlc.dev/en/v1.27.0/howto/push.html#add-configuration "Link to this heading") ---------------------------------------------------------------------------------------------------------------- After creating a project, add the project ID to your sqlc configuration file. version: "2" cloud: project: "" You’ll also need to create an auth token and make it available via the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Dry run[](https://docs.sqlc.dev/en/v1.27.0/howto/push.html#dry-run "Link to this heading") -------------------------------------------------------------------------------------------- You can see what’s included when uploading your project by using using the `--dry-run` flag: $ sqlc push \--dry-run 2023/11/21 10:39:51 INFO config file\=sqlc.yaml bytes\=912 2023/11/21 10:39:51 INFO codegen\_request queryset\=app file\=codegen\_request.pb 2023/11/21 10:39:51 INFO schema queryset\=app file\=migrations/00001\_initial.sql bytes\=3033 2023/11/21 10:39:51 INFO query queryset\=app file\=queries/app.sql bytes\=1150 The output is the files `sqlc` would have sent without the `--dry-run` flag. Push[](https://docs.sqlc.dev/en/v1.27.0/howto/push.html#push "Link to this heading") -------------------------------------------------------------------------------------- Once you’re ready to push, remove the `--dry-run` flag. $ sqlc push ### Tags[](https://docs.sqlc.dev/en/v1.27.0/howto/push.html#tags "Link to this heading") You can provide tags to associate with a push, primarily as a convenient reference when using `sqlc verify` with the `against` argument. Tags only refer to a single push, so if you pass an existing tag to `push` it will overwrite the previous reference. $ sqlc push \--tag main ### Annotations[](https://docs.sqlc.dev/en/v1.27.0/howto/push.html#annotations "Link to this heading") Annotations are added to each push request. By default, we include these environment variables (if they are present). GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA --- # verify - Verifying schema changes — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * `verify` - Verifying schema changes * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/verify.md) * * * `verify` - Verifying schema changes[](https://docs.sqlc.dev/en/v1.27.0/howto/verify.html#verify-verifying-schema-changes "Link to this heading") ================================================================================================================================================== _Added in v1.24.0_ Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. Using `verify` requires that you push your queries and schema when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. Authentication[](https://docs.sqlc.dev/en/v1.27.0/howto/verify.html#authentication "Link to this heading") ------------------------------------------------------------------------------------------------------------ `sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Expected workflow[](https://docs.sqlc.dev/en/v1.27.0/howto/verify.html#expected-workflow "Link to this heading") ------------------------------------------------------------------------------------------------------------------ Using `sqlc verify` requires pushing your queries and schema to sqlc Cloud. When you release a new version of your application, you should push your schema and queries as well. For example, we run `sqlc push` after any change has been merged into our `main` branch on Github, as we deploy every commit to production. $ sqlc push \--tag main Locally or in pull requests, run `sqlc verify` to check that existing queries continue to work with your current database schema. $ sqlc verify \--against main Picking a tag[](https://docs.sqlc.dev/en/v1.27.0/howto/verify.html#picking-a-tag "Link to this heading") ---------------------------------------------------------------------------------------------------------- Without an `against` argument, `verify` will run its analysis of the provided schema using your most-recently pushed queries. We suggest using the `against` argument to explicitly select a set of queries for comparison. $ sqlc verify \--against \[tag\] --- # Overriding types — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Overriding types * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/overrides.md) * * * Overriding types[](https://docs.sqlc.dev/en/v1.27.0/howto/overrides.html#overriding-types "Link to this heading") =================================================================================================================== In many cases it’s useful to tell `sqlc` explicitly what Go type you want it to use for a query input or output. For instance, a PostgreSQL UUID type will map to `UUID` from `github.com/jackc/pgx/pgtype` by default when you use `pgx/v5`, but you may want `sqlc` to use `UUID` from `github.com/google/uuid` instead. If you’d like `sqlc` to use a different Go type, specify the package import path and type in the `overrides` list. version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" go\_type: import: "github.com/google/uuid" type: "UUID" The `overrides` list[](https://docs.sqlc.dev/en/v1.27.0/howto/overrides.html#the-overrides-list "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- Each element in the `overrides` list has the following keys: * `db_type`: * A database type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use pg\_catalog-prefixed names where available. `db_type` and `column` are mutually exclusive. * `column`: * A column name to override. The value should be of the form `table.column` but you can also specify `schema.table.column` or `catalog.schema.table.column`. `column` and `db_type` are mutually exclusive. * `go_type`: * The fully-qualified name of a Go type to use in generated code. This is usually a string but can also be [a map](https://docs.sqlc.dev/en/v1.27.0/howto/overrides.html#the-go-type-map) for more complex configurations. * `go_struct_tag`: * A reflect-style struct tag to use in generated code, e.g. `a:"b" x:"y,z"`. If you want `json` or `db` tags for all fields, use `emit_json_tags` or `emit_db_tags` instead. * `unsigned`: * If `true`, sqlc will apply this override when a numeric db\_type is unsigned. Note that this has no effect on `column` overrides. Defaults to `false`. * `nullable`: * If `true`, sqlc will apply this override when a column is nullable. Otherwise `sqlc` will apply this override when a column is non-nullable. Note that this has no effect on `column` overrides. Defaults to `false`. Note that a single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override in both cases, you’ll need to configure two overrides. When generating code, entries using the `column` key will always take precedence over entries using the `db_type` key. ### The `go_type` map[](https://docs.sqlc.dev/en/v1.27.0/howto/overrides.html#the-go-type-map "Link to this heading") Some overrides may require more detailed configuration. If necessary, `go_type` can be a map with the following keys: * `import`: * The import path for the package where the type is defined. * `package`: * The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name. * `type`: * The type name itself, without any package prefix. * `pointer`: * If `true`, generated code will use a pointer to the type rather than the type itself. * `slice`: * If `true`, generated code will use a slice of the type rather than the type itself. An example: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" go\_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true --- # Preparing queries — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Preparing queries * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/prepared_query.md) * * * Preparing queries[](https://docs.sqlc.dev/en/v1.27.0/howto/prepared_query.html#preparing-queries "Link to this heading") ========================================================================================================================== If you’re using `pgx/v5` you get its [implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching) for prepared statements. No additional `sqlc` configuration is required. For other drivers, `sqlc` can give you the option to explicitly use prepared queries. These prepared queries also work with transactions. You’ll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration to generate code similar to the example below. CREATE TABLE records ( id SERIAL PRIMARY KEY ); \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; package db import ( "context" "database/sql" "fmt" ) type Record struct { ID int32 } type DBTX interface { PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } func Prepare(ctx context.Context, db DBTX) (\*Queries, error) { q := Queries{db: db} var err error if q.getRecordStmt, err \= db.PrepareContext(ctx, getRecord); err != nil { return nil, fmt.Errorf("error preparing query GetRecord: %w", err) } return &q, nil } func (q \*Queries) queryRow(ctx context.Context, stmt \*sql.Stmt, query string, args ...interface{}) \*sql.Row { switch { case stmt != nil && q.tx != nil: return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...) case stmt != nil: return stmt.QueryRowContext(ctx, args...) default: return q.db.QueryRowContext(ctx, query, args...) } } type Queries struct { db DBTX tx \*sql.Tx getRecordStmt \*sql.Stmt } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, tx: tx, getRecordStmt: q.getRecordStmt, } } const getRecord \= \`-- name: GetRecord :one SELECT id FROM records WHERE id = $1 \` func (q \*Queries) GetRecord(ctx context.Context, id int32) (int32, error) { row := q.queryRow(ctx, q.getRecordStmt, getRecord, id) err := row.Scan(&id) return id, err } --- # Counting rows — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Counting rows * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/query_count.md) * * * Counting rows[](https://docs.sqlc.dev/en/v1.27.0/howto/query_count.html#counting-rows "Link to this heading") =============================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, hometown text NOT NULL ); \-- name: CountAuthors :one SELECT count(\*) FROM authors; \-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1; package db import ( "context" "database/sql" ) type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const countAuthors \= \`-- name: CountAuthors :one SELECT count(\*) FROM authors \` func (q \*Queries) CountAuthors(ctx context.Context) (int, error) { row := q.db.QueryRowContext(ctx, countAuthors) var i int err := row.Scan(&i) return i, err } const countAuthorsByTown \= \`-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1 \` type CountAuthorsByTownRow struct { Hometown string Count int } func (q \*Queries) CountAuthorsByTown(ctx context.Context) (\[\]CountAuthorsByTownRow, error) { rows, err := q.db.QueryContext(ctx, countAuthorsByTown) if err != nil { return nil, err } defer rows.Close() items := \[\]CountAuthorsByTownRow{} for rows.Next() { var i CountAuthorsByTownRow if err := rows.Scan(&i.Hometown, &i.Count); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Renaming fields — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Renaming fields * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/rename.md) * * * Renaming fields[](https://docs.sqlc.dev/en/v1.27.0/howto/rename.html#renaming-fields "Link to this heading") ============================================================================================================== Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" rename: spotify\_url: "SpotifyURL" Tables[](https://docs.sqlc.dev/en/v1.27.0/howto/rename.html#tables "Link to this heading") -------------------------------------------------------------------------------------------- The output structs associated with tables can also be renamed. By default, the struct name will be the singular version of the table name. For example, the `authors` table will generate an `Author` struct. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); package db import ( "database/sql" ) type Author struct { ID int64 Name string Bio sql.NullString } To rename this struct, you must use the generated struct name. In this example, that would be `author`. Use the `rename` map to change the name of this struct to `Writer` (note the uppercase `W`). version: '1' packages: \- path: db engine: postgresql schema: query.sql queries: query.sql rename: author: Writer version: "2" sql: \- engine: postgresql queries: query.sql schema: query.sql overrides: go: rename: author: Writer package db import ( "database/sql" ) type Writer struct { ID int64 Name string Bio sql.NullString } Limitations[](https://docs.sqlc.dev/en/v1.27.0/howto/rename.html#limitations "Link to this heading") ------------------------------------------------------------------------------------------------------ Rename mappings apply to an entire package. Therefore, a column named `foo` and a table name `foo` can’t map to different rename values. --- # Macros — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Macros * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/macros.md) * * * Macros[](https://docs.sqlc.dev/en/v1.27.0/reference/macros.html#macros "Link to this heading") ================================================================================================ `sqlc.arg`[](https://docs.sqlc.dev/en/v1.27.0/reference/macros.html#sqlc-arg "Link to this heading") ------------------------------------------------------------------------------------------------------ Attach a name to a parameter in a SQL query. This macro expands to an engine-specific parameter placeholder. The name of the parameter is noted and used during code generation. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.arg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.27.0/howto/named_parameters.html) . `sqlc.embed`[](https://docs.sqlc.dev/en/v1.27.0/reference/macros.html#sqlc-embed "Link to this heading") ---------------------------------------------------------------------------------------------------------- Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ); CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ); \-- name: GetStudentAndScore :one SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; \-- >>> EXPANDS TO >>> \-- name: GetStudentAndScore :one SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; The Go method will return a struct with a field for the `Student` and field for the test `TestScore` instead of each column existing on the struct. type GetStudentAndScoreRow struct { Student Student TestScore TestScore } func (q \*Queries) GetStudentAndScore(ctx context.Context, id int64) (GetStudentAndScoreRow, error) { // ... } See a full example in [Embedding structs](https://docs.sqlc.dev/en/v1.27.0/howto/embedding.html) . `sqlc.narg`[](https://docs.sqlc.dev/en/v1.27.0/reference/macros.html#sqlc-narg "Link to this heading") -------------------------------------------------------------------------------------------------------- The same as `sqlc.arg`, but always marks the parameter as nullable. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.narg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE LOWER(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.27.0/howto/named_parameters.html) . `sqlc.slice`[](https://docs.sqlc.dev/en/v1.27.0/reference/macros.html#sqlc-slice "Link to this heading") ---------------------------------------------------------------------------------------------------------- For drivers that do not support passing slices to the IN operator, the `sqlc.slice` macro generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) \-- >>> EXPANDS TO >>> /\* name: SelectStudents :many \*/ SELECT id, name, age FROM authors WHERE age IN (/\*SLICE:ages\*/?) Since the `/*SLICE:ages*/` placeholder is dynamically replaced on a per-query basis, this macro can’t be used with prepared statements. See a full example in [Passing a slice as a parameter to a query](https://docs.sqlc.dev/en/v1.27.0/howto/select.html#mysql-and-sqlite) . --- # generate - Generating code — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * `generate` - Generating code * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/generate.md) * * * `generate` - Generating code[](https://docs.sqlc.dev/en/v1.27.0/howto/generate.html#generate-generating-code "Link to this heading") ====================================================================================================================================== `sqlc generate` parses SQL, analyzes the results, and outputs code. Your schema and queries are stored in separate SQL files. The paths to these files live in a `sqlc.yaml` configuration file. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" We’ve written extensive docs on [retrieving](https://docs.sqlc.dev/en/v1.27.0/howto/select.html) , [inserting](https://docs.sqlc.dev/en/v1.27.0/howto/insert.html) , [updating](https://docs.sqlc.dev/en/v1.27.0/howto/update.html) , and [deleting](https://docs.sqlc.dev/en/v1.27.0/howto/delete.html) rows. By default, sqlc runs its analysis using a built-in query analysis engine. While fast, this engine can’t handle some complex queries and type-inference. You can configure sqlc to use a database connection for enhanced analysis using metadata from that database. The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. Enhanced analysis with managed databases[](https://docs.sqlc.dev/en/v1.27.0/howto/generate.html#enhanced-analysis-with-managed-databases "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ With [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html) configured, `generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with an up-to-date schema. Here’s a minimal working configuration: version: "2" servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: managed: true gen: go: out: "db" sql\_package: "pgx/v5" Enhanced analysis using your own database[](https://docs.sqlc.dev/en/v1.27.0/howto/generate.html#enhanced-analysis-using-your-own-database "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can opt-in to database-backed analysis using your own database, by providing a `uri` in your sqlc [database](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database) configuration. The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: uri: "postgres://postgres:${PG\_PASSWORD}@localhost:5432/postgres" gen: go: out: "db" sql\_package: "pgx/v5" Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc generate`. --- # Getting started with SQLite — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Getting started with SQLite * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/tutorials/getting-started-sqlite.md) * * * Getting started with SQLite[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-sqlite.html#getting-started-with-sqlite "Link to this heading") ========================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.27.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.27.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. Setting up[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-sqlite.html#setting-up "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "sqlite" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-sqlite.html#schema-and-queries "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id INTEGER PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= ?, bio \= ? WHERE id \= ?; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= ?, bio \= ? WHERE id \= ? RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-sqlite.html#generating-code "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-sqlite.html#using-generated-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" \_ "embed" "log" "reflect" \_ "github.com/mattn/go-sqlite3" "tutorial.sqlc.dev/app/tutorial" ) //go:embed schema.sql var ddl string func run() error { ctx := context.Background() db, err := sql.Open("sqlite3", ":memory:") if err != nil { return err } // create tables if \_, err := db.ExecContext(ctx, ddl); err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant SQLite driver: go get github.com/mattn/go-sqlite3 go build ./... The program should compile without errors, and run successfully. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. --- # Query annotations — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Query annotations * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/query-annotations.md) * * * Query annotations[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#query-annotations "Link to this heading") ================================================================================================================================= sqlc requires each query to have a small comment indicating the name and command. The format of this comment is as follows: \-- name: `:exec`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#exec "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return the error from [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; func (q \*Queries) DeleteAuthor(ctx context.Context, id int64) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } `:execresult`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#execresult "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the [sql.Result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execresult DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (sql.Result, error) { return q.db.ExecContext(ctx, deleteAllAuthors) } `:execrows`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#execrows "Link to this heading") ------------------------------------------------------------------------------------------------------------------ The generated method will return the number of affected rows from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execrows DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (int64, error) { \_, err := q.db.ExecContext(ctx, deleteAllAuthors) // ... } `:execlastid`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#execlastid "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the number generated by the database from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: InsertAuthor :execlastid INSERT INTO authors (name) VALUES (?); func (q \*Queries) InsertAuthor(ctx context.Context, name string) (int64, error) { \_, err := q.db.ExecContext(ctx, insertAuthor, name) // ... } `:many`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#many "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return a slice of records via [QueryContext](https://golang.org/pkg/database/sql/#DB.QueryContext) . \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) // ... } `:one`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#one "Link to this heading") -------------------------------------------------------------------------------------------------------- The generated method will return a single record via [QueryRowContext](https://golang.org/pkg/database/sql/#DB.QueryRowContext) . \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; func (q \*Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) // ... } `:batchexec`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#batchexec "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Exec`, that takes a `func(int, error)` parameter, * `Close`, to close the batch operation early. \-- name: DeleteBook :batchexec DELETE FROM books WHERE book\_id \= $1; type DeleteBookBatchResults struct { br pgx.BatchResults ind int } func (q \*Queries) DeleteBook(ctx context.Context, bookID \[\]int32) \*DeleteBookBatchResults { //... } func (b \*DeleteBookBatchResults) Exec(f func(int, error)) { //... } func (b \*DeleteBookBatchResults) Close() error { //... } `:batchmany`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#batchmany "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Query`, that takes a `func(int, []T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: BooksByTitleYear :batchmany SELECT \* FROM books WHERE title \= $1 AND year \= $2; type BooksByTitleYearBatchResults struct { br pgx.BatchResults ind int } type BooksByTitleYearParams struct { Title string \`json:"title"\` Year int32 \`json:"year"\` } func (q \*Queries) BooksByTitleYear(ctx context.Context, arg \[\]BooksByTitleYearParams) \*BooksByTitleYearBatchResults { //... } func (b \*BooksByTitleYearBatchResults) Query(f func(int, \[\]Book, error)) { //... } func (b \*BooksByTitleYearBatchResults) Close() error { //... } `:batchone`[](https://docs.sqlc.dev/en/v1.27.0/reference/query-annotations.html#batchone "Link to this heading") ------------------------------------------------------------------------------------------------------------------ **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `QueryRow`, that takes a `func(int, T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: CreateBook :batchone INSERT INTO books ( author\_id, isbn ) VALUES ( $1, $2 ) RETURNING book\_id, author\_id, isbn type CreateBookBatchResults struct { br pgx.BatchResults ind int } type CreateBookParams struct { AuthorID int32 \`json:"author\_id"\` Isbn string \`json:"isbn"\` } func (q \*Queries) CreateBook(ctx context.Context, arg \[\]CreateBookParams) \*CreateBookBatchResults { //... } func (b \*CreateBookBatchResults) QueryRow(f func(int, Book, error)) { //... } func (b \*CreateBookBatchResults) Close() error { //... } --- # Inserting rows — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Inserting rows * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/insert.md) * * * Inserting rows[](https://docs.sqlc.dev/en/v1.27.0/howto/insert.html#inserting-rows "Link to this heading") ============================================================================================================ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1); package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const createAuthor \= \`-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1) \` func (q \*Queries) CreateAuthor(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, createAuthor, bio) return err } Returning columns from inserted rows[](https://docs.sqlc.dev/en/v1.27.0/howto/insert.html#returning-columns-from-inserted-rows "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------- sqlc has full support for the `RETURNING` statement. \-- Example queries for sqlc CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id; package db import ( "context" "database/sql" ) const createAuthor \= \`-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id, name, bio \` type CreateAuthorParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) var i Author err := row.Scan(&i.ID, &i.Name, &i.Bio) return i, err } const createAuthorAndReturnId \= \`-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id \` type CreateAuthorAndReturnIdParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthorAndReturnId(ctx context.Context, arg CreateAuthorAndReturnIdParams) (int64, error) { row := q.db.QueryRowContext(ctx, createAuthorAndReturnId, arg.Name, arg.Bio) var id int64 err := row.Scan(&id) return id, err } Using CopyFrom[](https://docs.sqlc.dev/en/v1.27.0/howto/insert.html#using-copyfrom "Link to this heading") ------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.27.0/howto/insert.html#postgresql "Link to this heading") PostgreSQL supports the [COPY protocol](https://www.postgresql.org/docs/current/sql-copy.html) that can insert rows a lot faster than sequential inserts. You can use this easily with sqlc: CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text NOT NULL ); \-- name: CreateAuthors :copyfrom INSERT INTO authors (name, bio) VALUES ($1, $2); type CreateAuthorsParams struct { Name string Bio string } func (q \*Queries) CreateAuthors(ctx context.Context, arg \[\]CreateAuthorsParams) (int64, error) { ... } The `:copyfrom` command requires either `pgx/v4` or `pgx/v5`. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" ### MySQL[](https://docs.sqlc.dev/en/v1.27.0/howto/insert.html#mysql "Link to this heading") MySQL supports a similar feature using [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) . Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use SHOW WARNINGS to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } The `:copyfrom` command requires setting the `sql_package` and `sql_driver` options. version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "database/sql" sql\_driver: "github.com/go-sql-driver/mysql" out: "db" --- # generate - Generating code — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * `generate` - Generating code * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/generate.md.txt) * * * `generate` - Generating code[](https://docs.sqlc.dev/en/stable/howto/generate.html#generate-generating-code "Link to this heading") ===================================================================================================================================== `sqlc generate` parses SQL, analyzes the results, and outputs code. Your schema and queries are stored in separate SQL files. The paths to these files live in a `sqlc.yaml` configuration file. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" We’ve written extensive docs on [retrieving](https://docs.sqlc.dev/en/stable/howto/select.html) , [inserting](https://docs.sqlc.dev/en/stable/howto/insert.html) , [updating](https://docs.sqlc.dev/en/stable/howto/update.html) , and [deleting](https://docs.sqlc.dev/en/stable/howto/delete.html) rows. By default, sqlc runs its analysis using a built-in query analysis engine. While fast, this engine can’t handle some complex queries and type-inference. You can configure sqlc to use a database connection for enhanced analysis using metadata from that database. The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. Enhanced analysis with managed databases[](https://docs.sqlc.dev/en/stable/howto/generate.html#enhanced-analysis-with-managed-databases "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------------- With [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html) configured, `generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with an up-to-date schema. Here’s a minimal working configuration: version: "2" servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: managed: true gen: go: out: "db" sql\_package: "pgx/v5" Enhanced analysis using your own database[](https://docs.sqlc.dev/en/stable/howto/generate.html#enhanced-analysis-using-your-own-database "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can opt-in to database-backed analysis using your own database, by providing a `uri` in your sqlc [database](https://docs.sqlc.dev/en/stable/reference/config.html#database) configuration. The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: uri: "postgres://postgres:${PG\_PASSWORD}@localhost:5432/postgres" gen: go: out: "db" sql\_package: "pgx/v5" Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc generate`. --- # Using plugins — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Using plugins * [View page source](https://docs.sqlc.dev/en/latest/_sources/guides/plugins.md.txt) * * * Using plugins[](https://docs.sqlc.dev/en/latest/guides/plugins.html#using-plugins "Link to this heading") =========================================================================================================== To use plugins, you must be using [Version 2](https://docs.sqlc.dev/en/latest/reference/config.html#version-2) of the configuration file. The top-level `plugins` array defines the available plugins. WASM plugins[](https://docs.sqlc.dev/en/latest/guides/plugins.html#wasm-plugins "Link to this heading") --------------------------------------------------------------------------------------------------------- > WASM plugins are fully sandboxed; they do not have access to the network, filesystem, or environment variables. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: greeter wasm: url: https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm sha256: afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07 sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: greeter options: lang: en-US For a complete working example see the following files: * [sqlc-gen-greeter](https://github.com/sqlc-dev/sqlc-gen-greeter) * A WASM plugin (written in Rust) that outputs a friendly message * [wasm\_plugin\_sqlc\_gen\_greeter](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter) * An example project showing how to use a WASM plugin Process plugins[](https://docs.sqlc.dev/en/latest/guides/plugins.html#process-plugins "Link to this heading") --------------------------------------------------------------------------------------------------------------- > Process-based plugins offer minimal security. Only use plugins that you trust. Better yet, only use plugins that you’ve written yourself. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: jsonb process: cmd: sqlc-gen-json sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: jsonb options: indent: " " filename: codegen.json For a complete working example see the following files: * [sqlc-gen-json](https://github.com/sqlc-dev/sqlc/tree/main/cmd/sqlc-gen-json) * A process-based plugin that serializes the CodeGenRequest to JSON * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json) * An example project showing how to use a process-based plugin * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_format_json/) * An example project showing how to use a process-based plugin using json Environment variables[](https://docs.sqlc.dev/en/latest/guides/plugins.html#environment-variables "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- By default, plugins do not inherit access to environment variables. Instead, you can configure access on a per-variable basis. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. --- # Installing sqlc — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Installing sqlc * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/overview/install.md.txt) * * * Installing sqlc[](https://docs.sqlc.dev/en/v1.31.0/overview/install.html#installing-sqlc "Link to this heading") ================================================================================================================== sqlc is distributed as a single binary with zero dependencies. macOS[](https://docs.sqlc.dev/en/v1.31.0/overview/install.html#macos "Link to this heading") ---------------------------------------------------------------------------------------------- brew install sqlc Ubuntu[](https://docs.sqlc.dev/en/v1.31.0/overview/install.html#ubuntu "Link to this heading") ------------------------------------------------------------------------------------------------ sudo snap install sqlc go install[](https://docs.sqlc.dev/en/v1.31.0/overview/install.html#go-install "Link to this heading") -------------------------------------------------------------------------------------------------------- Installing recent versions of sqlc requires Go 1.21+. go install github.com/sqlc\-dev/sqlc/cmd/sqlc@latest Docker[](https://docs.sqlc.dev/en/v1.31.0/overview/install.html#docker "Link to this heading") ------------------------------------------------------------------------------------------------ docker pull sqlc/sqlc Run `sqlc` using `docker run`: docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate Run `sqlc` using `docker run` in the Command Prompt on Windows (`cmd`): docker run \--rm \-v "%cd%:/src" \-w /src sqlc/sqlc generate Downloads[](https://docs.sqlc.dev/en/v1.31.0/overview/install.html#downloads "Link to this heading") ------------------------------------------------------------------------------------------------------ Get pre-built binaries for _v1.31.0_: * [Linux](https://downloads.sqlc.dev/sqlc_1.31.0_linux_amd64.tar.gz) * [macOS](https://downloads.sqlc.dev/sqlc_1.31.0_darwin_amd64.zip) * [Windows](https://downloads.sqlc.dev/sqlc_1.31.0_windows_amd64.zip) See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions. --- # Developing sqlc — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Developing sqlc * [View page source](https://docs.sqlc.dev/en/latest/_sources/guides/development.md.txt) * * * Developing sqlc[](https://docs.sqlc.dev/en/latest/guides/development.html#developing-sqlc "Link to this heading") =================================================================================================================== Building[](https://docs.sqlc.dev/en/latest/guides/development.html#building "Link to this heading") ----------------------------------------------------------------------------------------------------- For local development, install `sqlc` under an alias. We suggest `sqlc-dev`. go build \-o ~/go/bin/sqlc\-dev ./cmd/sqlc Install `sqlc-gen-json` to avoid test failure. go build \-o ~/go/bin/sqlc\-gen\-json ./cmd/sqlc\-gen\-json Running Tests[](https://docs.sqlc.dev/en/latest/guides/development.html#running-tests "Link to this heading") --------------------------------------------------------------------------------------------------------------- go test ./... To run the tests in the examples folder, use the `examples` tag. go test \--tags\=examples ./... These tests require locally-running database instances. Run these databases using [Docker Compose](https://docs.docker.com/compose/) . docker compose up \-d The tests use the following environment variables to connect to the database ### For PostgreSQL[](https://docs.sqlc.dev/en/latest/guides/development.html#for-postgresql "Link to this heading") Variable Default Value \------------------------- PG\_HOST 127.0.0.1 PG\_PORT 5432 PG\_USER postgres PG\_PASSWORD mysecretpassword PG\_DATABASE dinotest ### For MySQL[](https://docs.sqlc.dev/en/latest/guides/development.html#for-mysql "Link to this heading") Variable Default Value \------------------------- MYSQL\_HOST 127.0.0.1 MYSQL\_PORT 3306 MYSQL\_USER root MYSQL\_ROOT\_PASSWORD mysecretpassword MYSQL\_DATABASE dinotest --- # Installing sqlc — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Installing sqlc * [View page source](https://docs.sqlc.dev/en/stable/_sources/overview/install.md.txt) * * * Installing sqlc[](https://docs.sqlc.dev/en/stable/overview/install.html#installing-sqlc "Link to this heading") ================================================================================================================= sqlc is distributed as a single binary with zero dependencies. macOS[](https://docs.sqlc.dev/en/stable/overview/install.html#macos "Link to this heading") --------------------------------------------------------------------------------------------- brew install sqlc Ubuntu[](https://docs.sqlc.dev/en/stable/overview/install.html#ubuntu "Link to this heading") ----------------------------------------------------------------------------------------------- sudo snap install sqlc go install[](https://docs.sqlc.dev/en/stable/overview/install.html#go-install "Link to this heading") ------------------------------------------------------------------------------------------------------- Installing recent versions of sqlc requires Go 1.21+. go install github.com/sqlc\-dev/sqlc/cmd/sqlc@latest Docker[](https://docs.sqlc.dev/en/stable/overview/install.html#docker "Link to this heading") ----------------------------------------------------------------------------------------------- docker pull sqlc/sqlc Run `sqlc` using `docker run`: docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate Run `sqlc` using `docker run` in the Command Prompt on Windows (`cmd`): docker run \--rm \-v "%cd%:/src" \-w /src sqlc/sqlc generate Downloads[](https://docs.sqlc.dev/en/stable/overview/install.html#downloads "Link to this heading") ----------------------------------------------------------------------------------------------------- Get pre-built binaries for _v1.31.1_: * [Linux](https://downloads.sqlc.dev/sqlc_1.31.1_linux_amd64.tar.gz) * [macOS](https://downloads.sqlc.dev/sqlc_1.31.1_darwin_amd64.zip) * [Windows](https://downloads.sqlc.dev/sqlc_1.31.1_windows_amd64.zip) See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions. --- # Deleting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Deleting rows * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/delete.md.txt) * * * Deleting rows[](https://docs.sqlc.dev/en/stable/howto/delete.html#deleting-rows "Link to this heading") ========================================================================================================= CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; **MySQL and SQLite:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const deleteAuthor \= \`-- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $1 \` func (q \*Queries) DeleteAuthor(ctx context.Context, id int) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } --- # Using Go and pgx — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Using Go and pgx * [View page source](https://docs.sqlc.dev/en/stable/_sources/guides/using-go-and-pgx.rst.txt) * * * Using Go and pgx[](https://docs.sqlc.dev/en/stable/guides/using-go-and-pgx.html#using-go-and-pgx "Link to this heading") ========================================================================================================================== Note `pgx/v5` is supported starting from v1.18.0. pgx is a pure Go driver and toolkit for PostgreSQL. It’s become the default PostgreSQL package for many Gophers since lib/pq was put into maintenance mode. Getting started[](https://docs.sqlc.dev/en/stable/guides/using-go-and-pgx.html#getting-started "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ To start generating code that uses pgx, set the `sql_package` field in your `sqlc.yaml` configuration file. Valid options are `pgx/v4` or `pgx/v5` version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" If you don’t have an existing sqlc project on hand, create a directory with the configuration file above and the following `query.sql` file. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; Generating the code will now give you pgx-compatible database access methods. sqlc generate Generated code walkthrough[](https://docs.sqlc.dev/en/stable/guides/using-go-and-pgx.html#generated-code-walkthrough "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------- The generated code is very similar to the code generated when using `lib/pq`. However, instead of using `database/sql`, the code uses pgx types directly. package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v5" "example.com/sqlc-tutorial/db" ) func main() { // urlExample := "postgres://username:password@localhost:5432/database\_name" conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\\n", err) os.Exit(1) } defer conn.Close(context.Background()) q := db.New(conn) author, err := q.GetAuthor(context.Background(), 1) if err != nil { fmt.Fprintf(os.Stderr, "GetAuthor failed: %v\\n", err) os.Exit(1) } fmt.Println(author.Name) } Note For production applications, consider using pgxpool for connection pooling: import ( "github.com/jackc/pgx/v5/pgxpool" "example.com/sqlc-tutorial/db" ) func main() { pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\\n", err) os.Exit(1) } defer pool.Close() q := db.New(pool) // Use q the same way as with single connections } --- # Using plugins — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Using plugins * [View page source](https://docs.sqlc.dev/en/stable/_sources/guides/plugins.md.txt) * * * Using plugins[](https://docs.sqlc.dev/en/stable/guides/plugins.html#using-plugins "Link to this heading") =========================================================================================================== To use plugins, you must be using [Version 2](https://docs.sqlc.dev/en/stable/reference/config.html#version-2) of the configuration file. The top-level `plugins` array defines the available plugins. WASM plugins[](https://docs.sqlc.dev/en/stable/guides/plugins.html#wasm-plugins "Link to this heading") --------------------------------------------------------------------------------------------------------- > WASM plugins are fully sandboxed; they do not have access to the network, filesystem, or environment variables. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: greeter wasm: url: https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm sha256: afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07 sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: greeter options: lang: en-US For a complete working example see the following files: * [sqlc-gen-greeter](https://github.com/sqlc-dev/sqlc-gen-greeter) * A WASM plugin (written in Rust) that outputs a friendly message * [wasm\_plugin\_sqlc\_gen\_greeter](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter) * An example project showing how to use a WASM plugin Process plugins[](https://docs.sqlc.dev/en/stable/guides/plugins.html#process-plugins "Link to this heading") --------------------------------------------------------------------------------------------------------------- > Process-based plugins offer minimal security. Only use plugins that you trust. Better yet, only use plugins that you’ve written yourself. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: jsonb process: cmd: sqlc-gen-json sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: jsonb options: indent: " " filename: codegen.json For a complete working example see the following files: * [sqlc-gen-json](https://github.com/sqlc-dev/sqlc/tree/main/cmd/sqlc-gen-json) * A process-based plugin that serializes the CodeGenRequest to JSON * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json) * An example project showing how to use a process-based plugin * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_format_json/) * An example project showing how to use a process-based plugin using json Environment variables[](https://docs.sqlc.dev/en/stable/guides/plugins.html#environment-variables "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- By default, plugins do not inherit access to environment variables. Instead, you can configure access on a per-variable basis. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. --- # CLI — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * CLI * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/cli.md.txt) * * * CLI[](https://docs.sqlc.dev/en/stable/reference/cli.html#cli "Link to this heading") ====================================================================================== Usage: sqlc \[command\] Available Commands: compile Statically check SQL for syntax and type errors completion Generate the autocompletion script for the specified shell createdb Create an ephemeral database diff Compare the generated files to the existing files generate Generate source code from SQL help Help about any command init Create an empty sqlc.yaml settings file push Push the schema, queries, and configuration for this project verify Verify schema, queries, and configuration for this project version Print the sqlc version number vet Vet examines queries Flags: \-f, \--file string specify an alternate config file (default: sqlc.yaml) \-h, \--help help for sqlc \--no-database disable database connections (default: false) \--no-remote disable remote execution (default: false) Use "sqlc \[command\] --help" for more information about a command. --- # Developing sqlc — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Developing sqlc * [View page source](https://docs.sqlc.dev/en/stable/_sources/guides/development.md.txt) * * * Developing sqlc[](https://docs.sqlc.dev/en/stable/guides/development.html#developing-sqlc "Link to this heading") =================================================================================================================== Building[](https://docs.sqlc.dev/en/stable/guides/development.html#building "Link to this heading") ----------------------------------------------------------------------------------------------------- For local development, install `sqlc` under an alias. We suggest `sqlc-dev`. go build \-o ~/go/bin/sqlc\-dev ./cmd/sqlc Install `sqlc-gen-json` to avoid test failure. go build \-o ~/go/bin/sqlc\-gen\-json ./cmd/sqlc\-gen\-json Running Tests[](https://docs.sqlc.dev/en/stable/guides/development.html#running-tests "Link to this heading") --------------------------------------------------------------------------------------------------------------- go test ./... To run the tests in the examples folder, use the `examples` tag. go test \--tags\=examples ./... These tests require locally-running database instances. Run these databases using [Docker Compose](https://docs.docker.com/compose/) . docker compose up \-d The tests use the following environment variables to connect to the database ### For PostgreSQL[](https://docs.sqlc.dev/en/stable/guides/development.html#for-postgresql "Link to this heading") Variable Default Value \------------------------- PG\_HOST 127.0.0.1 PG\_PORT 5432 PG\_USER postgres PG\_PASSWORD mysecretpassword PG\_DATABASE dinotest ### For MySQL[](https://docs.sqlc.dev/en/stable/guides/development.html#for-mysql "Link to this heading") Variable Default Value \------------------------- MYSQL\_HOST 127.0.0.1 MYSQL\_PORT 3306 MYSQL\_USER root MYSQL\_ROOT\_PASSWORD mysecretpassword MYSQL\_DATABASE dinotest --- # Preparing queries — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Preparing queries * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/prepared_query.md.txt) * * * Preparing queries[](https://docs.sqlc.dev/en/v1.31.0/howto/prepared_query.html#preparing-queries "Link to this heading") ========================================================================================================================== If you’re using `pgx/v5` you get its [implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching) for prepared statements. No additional `sqlc` configuration is required. For other drivers, `sqlc` can give you the option to explicitly use prepared queries. These prepared queries also work with transactions. You’ll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration to generate code similar to the example below. CREATE TABLE records ( id SERIAL PRIMARY KEY ); \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; package db import ( "context" "database/sql" "fmt" ) type Record struct { ID int32 } type DBTX interface { PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } func Prepare(ctx context.Context, db DBTX) (\*Queries, error) { q := Queries{db: db} var err error if q.getRecordStmt, err \= db.PrepareContext(ctx, getRecord); err != nil { return nil, fmt.Errorf("error preparing query GetRecord: %w", err) } return &q, nil } func (q \*Queries) queryRow(ctx context.Context, stmt \*sql.Stmt, query string, args ...interface{}) \*sql.Row { switch { case stmt != nil && q.tx != nil: return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...) case stmt != nil: return stmt.QueryRowContext(ctx, args...) default: return q.db.QueryRowContext(ctx, query, args...) } } type Queries struct { db DBTX tx \*sql.Tx getRecordStmt \*sql.Stmt } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, tx: tx, getRecordStmt: q.getRecordStmt, } } const getRecord \= \`-- name: GetRecord :one SELECT id FROM records WHERE id = $1 \` func (q \*Queries) GetRecord(ctx context.Context, id int32) (int32, error) { row := q.queryRow(ctx, q.getRecordStmt, getRecord, id) err := row.Scan(&id) return id, err } --- # Deleting rows — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Deleting rows * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/delete.md.txt) * * * Deleting rows[](https://docs.sqlc.dev/en/v1.31.0/howto/delete.html#deleting-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; **MySQL and SQLite:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const deleteAuthor \= \`-- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $1 \` func (q \*Queries) DeleteAuthor(ctx context.Context, id int) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } --- # Using Go and pgx — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Using Go and pgx * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/guides/using-go-and-pgx.rst.txt) * * * Using Go and pgx[](https://docs.sqlc.dev/en/v1.31.0/guides/using-go-and-pgx.html#using-go-and-pgx "Link to this heading") =========================================================================================================================== Note `pgx/v5` is supported starting from v1.18.0. pgx is a pure Go driver and toolkit for PostgreSQL. It’s become the default PostgreSQL package for many Gophers since lib/pq was put into maintenance mode. Getting started[](https://docs.sqlc.dev/en/v1.31.0/guides/using-go-and-pgx.html#getting-started "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- To start generating code that uses pgx, set the `sql_package` field in your `sqlc.yaml` configuration file. Valid options are `pgx/v4` or `pgx/v5` version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" If you don’t have an existing sqlc project on hand, create a directory with the configuration file above and the following `query.sql` file. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; Generating the code will now give you pgx-compatible database access methods. sqlc generate Generated code walkthrough[](https://docs.sqlc.dev/en/v1.31.0/guides/using-go-and-pgx.html#generated-code-walkthrough "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------- The generated code is very similar to the code generated when using `lib/pq`. However, instead of using `database/sql`, the code uses pgx types directly. package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v5" "example.com/sqlc-tutorial/db" ) func main() { // urlExample := "postgres://username:password@localhost:5432/database\_name" conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\\n", err) os.Exit(1) } defer conn.Close(context.Background()) q := db.New(conn) author, err := q.GetAuthor(context.Background(), 1) if err != nil { fmt.Fprintf(os.Stderr, "GetAuthor failed: %v\\n", err) os.Exit(1) } fmt.Println(author.Name) } Note For production applications, consider using pgxpool for connection pooling: import ( "github.com/jackc/pgx/v5/pgxpool" "example.com/sqlc-tutorial/db" ) func main() { pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\\n", err) os.Exit(1) } defer pool.Close() q := db.New(pool) // Use q the same way as with single connections } --- # Using plugins — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Using plugins * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/guides/plugins.md.txt) * * * Using plugins[](https://docs.sqlc.dev/en/v1.31.0/guides/plugins.html#using-plugins "Link to this heading") ============================================================================================================ To use plugins, you must be using [Version 2](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#version-2) of the configuration file. The top-level `plugins` array defines the available plugins. WASM plugins[](https://docs.sqlc.dev/en/v1.31.0/guides/plugins.html#wasm-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------- > WASM plugins are fully sandboxed; they do not have access to the network, filesystem, or environment variables. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: greeter wasm: url: https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm sha256: afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07 sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: greeter options: lang: en-US For a complete working example see the following files: * [sqlc-gen-greeter](https://github.com/sqlc-dev/sqlc-gen-greeter) * A WASM plugin (written in Rust) that outputs a friendly message * [wasm\_plugin\_sqlc\_gen\_greeter](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter) * An example project showing how to use a WASM plugin Process plugins[](https://docs.sqlc.dev/en/v1.31.0/guides/plugins.html#process-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------------- > Process-based plugins offer minimal security. Only use plugins that you trust. Better yet, only use plugins that you’ve written yourself. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: jsonb process: cmd: sqlc-gen-json sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: jsonb options: indent: " " filename: codegen.json For a complete working example see the following files: * [sqlc-gen-json](https://github.com/sqlc-dev/sqlc/tree/main/cmd/sqlc-gen-json) * A process-based plugin that serializes the CodeGenRequest to JSON * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json) * An example project showing how to use a process-based plugin * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_format_json/) * An example project showing how to use a process-based plugin using json Environment variables[](https://docs.sqlc.dev/en/v1.31.0/guides/plugins.html#environment-variables "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- By default, plugins do not inherit access to environment variables. Instead, you can configure access on a per-variable basis. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. --- # CLI — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * CLI * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/cli.md.txt) * * * CLI[](https://docs.sqlc.dev/en/v1.31.0/reference/cli.html#cli "Link to this heading") ======================================================================================= Usage: sqlc \[command\] Available Commands: compile Statically check SQL for syntax and type errors completion Generate the autocompletion script for the specified shell createdb Create an ephemeral database diff Compare the generated files to the existing files generate Generate source code from SQL help Help about any command init Create an empty sqlc.yaml settings file push Push the schema, queries, and configuration for this project verify Verify schema, queries, and configuration for this project version Print the sqlc version number vet Vet examines queries Flags: \-f, \--file string specify an alternate config file (default: sqlc.yaml) \-h, \--help help for sqlc \--no-database disable database connections (default: false) \--no-remote disable remote execution (default: false) Use "sqlc \[command\] --help" for more information about a command. --- # Developing sqlc — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Developing sqlc * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/guides/development.md.txt) * * * Developing sqlc[](https://docs.sqlc.dev/en/v1.31.0/guides/development.html#developing-sqlc "Link to this heading") ==================================================================================================================== Building[](https://docs.sqlc.dev/en/v1.31.0/guides/development.html#building "Link to this heading") ------------------------------------------------------------------------------------------------------ For local development, install `sqlc` under an alias. We suggest `sqlc-dev`. go build \-o ~/go/bin/sqlc\-dev ./cmd/sqlc Install `sqlc-gen-json` to avoid test failure. go build \-o ~/go/bin/sqlc\-gen\-json ./cmd/sqlc\-gen\-json Running Tests[](https://docs.sqlc.dev/en/v1.31.0/guides/development.html#running-tests "Link to this heading") ---------------------------------------------------------------------------------------------------------------- go test ./... To run the tests in the examples folder, use the `examples` tag. go test \--tags\=examples ./... These tests require locally-running database instances. Run these databases using [Docker Compose](https://docs.docker.com/compose/) . docker compose up \-d The tests use the following environment variables to connect to the database ### For PostgreSQL[](https://docs.sqlc.dev/en/v1.31.0/guides/development.html#for-postgresql "Link to this heading") Variable Default Value \------------------------- PG\_HOST 127.0.0.1 PG\_PORT 5432 PG\_USER postgres PG\_PASSWORD mysecretpassword PG\_DATABASE dinotest ### For MySQL[](https://docs.sqlc.dev/en/v1.31.0/guides/development.html#for-mysql "Link to this heading") Variable Default Value \------------------------- MYSQL\_HOST 127.0.0.1 MYSQL\_PORT 3306 MYSQL\_USER root MYSQL\_ROOT\_PASSWORD mysecretpassword MYSQL\_DATABASE dinotest --- # Installing sqlc — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Installing sqlc * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/overview/install.md.txt) * * * Installing sqlc[](https://docs.sqlc.dev/en/v1.31.1/overview/install.html#installing-sqlc "Link to this heading") ================================================================================================================== sqlc is distributed as a single binary with zero dependencies. macOS[](https://docs.sqlc.dev/en/v1.31.1/overview/install.html#macos "Link to this heading") ---------------------------------------------------------------------------------------------- brew install sqlc Ubuntu[](https://docs.sqlc.dev/en/v1.31.1/overview/install.html#ubuntu "Link to this heading") ------------------------------------------------------------------------------------------------ sudo snap install sqlc go install[](https://docs.sqlc.dev/en/v1.31.1/overview/install.html#go-install "Link to this heading") -------------------------------------------------------------------------------------------------------- Installing recent versions of sqlc requires Go 1.21+. go install github.com/sqlc\-dev/sqlc/cmd/sqlc@latest Docker[](https://docs.sqlc.dev/en/v1.31.1/overview/install.html#docker "Link to this heading") ------------------------------------------------------------------------------------------------ docker pull sqlc/sqlc Run `sqlc` using `docker run`: docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate Run `sqlc` using `docker run` in the Command Prompt on Windows (`cmd`): docker run \--rm \-v "%cd%:/src" \-w /src sqlc/sqlc generate Downloads[](https://docs.sqlc.dev/en/v1.31.1/overview/install.html#downloads "Link to this heading") ------------------------------------------------------------------------------------------------------ Get pre-built binaries for _v1.31.1_: * [Linux](https://downloads.sqlc.dev/sqlc_1.31.1_linux_amd64.tar.gz) * [macOS](https://downloads.sqlc.dev/sqlc_1.31.1_darwin_amd64.zip) * [Windows](https://downloads.sqlc.dev/sqlc_1.31.1_windows_amd64.zip) See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions. --- # Deleting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Deleting rows * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/delete.md.txt) * * * Deleting rows[](https://docs.sqlc.dev/en/v1.31.1/howto/delete.html#deleting-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; **MySQL and SQLite:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const deleteAuthor \= \`-- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $1 \` func (q \*Queries) DeleteAuthor(ctx context.Context, id int) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } --- # Using Go and pgx — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Using Go and pgx * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/guides/using-go-and-pgx.rst.txt) * * * Using Go and pgx[](https://docs.sqlc.dev/en/v1.31.1/guides/using-go-and-pgx.html#using-go-and-pgx "Link to this heading") =========================================================================================================================== Note `pgx/v5` is supported starting from v1.18.0. pgx is a pure Go driver and toolkit for PostgreSQL. It’s become the default PostgreSQL package for many Gophers since lib/pq was put into maintenance mode. Getting started[](https://docs.sqlc.dev/en/v1.31.1/guides/using-go-and-pgx.html#getting-started "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- To start generating code that uses pgx, set the `sql_package` field in your `sqlc.yaml` configuration file. Valid options are `pgx/v4` or `pgx/v5` version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" If you don’t have an existing sqlc project on hand, create a directory with the configuration file above and the following `query.sql` file. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; Generating the code will now give you pgx-compatible database access methods. sqlc generate Generated code walkthrough[](https://docs.sqlc.dev/en/v1.31.1/guides/using-go-and-pgx.html#generated-code-walkthrough "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------- The generated code is very similar to the code generated when using `lib/pq`. However, instead of using `database/sql`, the code uses pgx types directly. package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v5" "example.com/sqlc-tutorial/db" ) func main() { // urlExample := "postgres://username:password@localhost:5432/database\_name" conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\\n", err) os.Exit(1) } defer conn.Close(context.Background()) q := db.New(conn) author, err := q.GetAuthor(context.Background(), 1) if err != nil { fmt.Fprintf(os.Stderr, "GetAuthor failed: %v\\n", err) os.Exit(1) } fmt.Println(author.Name) } Note For production applications, consider using pgxpool for connection pooling: import ( "github.com/jackc/pgx/v5/pgxpool" "example.com/sqlc-tutorial/db" ) func main() { pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\\n", err) os.Exit(1) } defer pool.Close() q := db.New(pool) // Use q the same way as with single connections } --- # Using plugins — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Using plugins * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/guides/plugins.md.txt) * * * Using plugins[](https://docs.sqlc.dev/en/v1.31.1/guides/plugins.html#using-plugins "Link to this heading") ============================================================================================================ To use plugins, you must be using [Version 2](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#version-2) of the configuration file. The top-level `plugins` array defines the available plugins. WASM plugins[](https://docs.sqlc.dev/en/v1.31.1/guides/plugins.html#wasm-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------- > WASM plugins are fully sandboxed; they do not have access to the network, filesystem, or environment variables. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: greeter wasm: url: https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm sha256: afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07 sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: greeter options: lang: en-US For a complete working example see the following files: * [sqlc-gen-greeter](https://github.com/sqlc-dev/sqlc-gen-greeter) * A WASM plugin (written in Rust) that outputs a friendly message * [wasm\_plugin\_sqlc\_gen\_greeter](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter) * An example project showing how to use a WASM plugin Process plugins[](https://docs.sqlc.dev/en/v1.31.1/guides/plugins.html#process-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------------- > Process-based plugins offer minimal security. Only use plugins that you trust. Better yet, only use plugins that you’ve written yourself. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: jsonb process: cmd: sqlc-gen-json sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: jsonb options: indent: " " filename: codegen.json For a complete working example see the following files: * [sqlc-gen-json](https://github.com/sqlc-dev/sqlc/tree/main/cmd/sqlc-gen-json) * A process-based plugin that serializes the CodeGenRequest to JSON * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json) * An example project showing how to use a process-based plugin * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_format_json/) * An example project showing how to use a process-based plugin using json Environment variables[](https://docs.sqlc.dev/en/v1.31.1/guides/plugins.html#environment-variables "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- By default, plugins do not inherit access to environment variables. Instead, you can configure access on a per-variable basis. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. --- # CLI — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * CLI * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/cli.md.txt) * * * CLI[](https://docs.sqlc.dev/en/v1.31.1/reference/cli.html#cli "Link to this heading") ======================================================================================= Usage: sqlc \[command\] Available Commands: compile Statically check SQL for syntax and type errors completion Generate the autocompletion script for the specified shell createdb Create an ephemeral database diff Compare the generated files to the existing files generate Generate source code from SQL help Help about any command init Create an empty sqlc.yaml settings file push Push the schema, queries, and configuration for this project verify Verify schema, queries, and configuration for this project version Print the sqlc version number vet Vet examines queries Flags: \-f, \--file string specify an alternate config file (default: sqlc.yaml) \-h, \--help help for sqlc \--no-database disable database connections (default: false) \--no-remote disable remote execution (default: false) Use "sqlc \[command\] --help" for more information about a command. --- # Developing sqlc — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Developing sqlc * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/guides/development.md.txt) * * * Developing sqlc[](https://docs.sqlc.dev/en/v1.31.1/guides/development.html#developing-sqlc "Link to this heading") ==================================================================================================================== Building[](https://docs.sqlc.dev/en/v1.31.1/guides/development.html#building "Link to this heading") ------------------------------------------------------------------------------------------------------ For local development, install `sqlc` under an alias. We suggest `sqlc-dev`. go build \-o ~/go/bin/sqlc\-dev ./cmd/sqlc Install `sqlc-gen-json` to avoid test failure. go build \-o ~/go/bin/sqlc\-gen\-json ./cmd/sqlc\-gen\-json Running Tests[](https://docs.sqlc.dev/en/v1.31.1/guides/development.html#running-tests "Link to this heading") ---------------------------------------------------------------------------------------------------------------- go test ./... To run the tests in the examples folder, use the `examples` tag. go test \--tags\=examples ./... These tests require locally-running database instances. Run these databases using [Docker Compose](https://docs.docker.com/compose/) . docker compose up \-d The tests use the following environment variables to connect to the database ### For PostgreSQL[](https://docs.sqlc.dev/en/v1.31.1/guides/development.html#for-postgresql "Link to this heading") Variable Default Value \------------------------- PG\_HOST 127.0.0.1 PG\_PORT 5432 PG\_USER postgres PG\_PASSWORD mysecretpassword PG\_DATABASE dinotest ### For MySQL[](https://docs.sqlc.dev/en/v1.31.1/guides/development.html#for-mysql "Link to this heading") Variable Default Value \------------------------- MYSQL\_HOST 127.0.0.1 MYSQL\_PORT 3306 MYSQL\_USER root MYSQL\_ROOT\_PASSWORD mysecretpassword MYSQL\_DATABASE dinotest --- # Managed databases — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Managed databases * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/managed-databases.md) * * * Managed databases[](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html#managed-databases "Link to this heading") ============================================================================================================================= _Added in v1.22.0_ `sqlc` can automatically create read-only databases to power query analysis, linting and verification. These databases are immediately useful for powering sqlc’s database-connected query analyzer, an opt-in feature that improves upon sqlc’s built-in query analysis engine. PostgreSQL support is available today, with MySQL on the way. Once configured, `sqlc` will also use managed databases when linting queries with [`sqlc vet`](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html) in cases where your lint rules require a connection to a running database. Managed databases are under active development, and we’re interested in supporting other use-cases. Configuring managed databases[](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html#configuring-managed-databases "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------- To configure `sqlc` to use managed databases, remove the `uri` key from your `database` configuration and replace it with the `managed` key set to `true`. Access to a running database server is required. Add a connection string to the `servers` mapping. version: '2' servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true An environment variable can also be used via the `${}` syntax. version: '2' servers: \- engine: postgresql uri: ${DATABASE\_URI} sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true Improving codegen[](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html#improving-codegen "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------- Without a database connection, sqlc does its best to parse, analyze and compile your queries just using the schema you pass it and what it knows about the various database engines it supports. In many cases this works just fine, but for more advanced queries sqlc might not have enough information to produce good code. With managed databases configured, `sqlc generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future codegen runs. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true gen: go: out: "db" Linting queries[](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html#linting-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- With managed databases configured, `sqlc vet` will automatically create a hosted ephemeral database with your schema and use that database when running lint rules that require a database connection, e.g. any [rule relying on `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#rules-using-explain-output) . If you don’t yet have any vet rules, the [built-in sqlc/db-prepare rule](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#sqlc-db-prepare) is a good place to start. It prepares each of your queries against the database to ensure the query is valid. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true rules: \- sqlc/db-prepare --- # Developing sqlc — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Developing sqlc * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/guides/development.md) * * * Developing sqlc[](https://docs.sqlc.dev/en/v1.27.0/guides/development.html#developing-sqlc "Link to this heading") ==================================================================================================================== Building[](https://docs.sqlc.dev/en/v1.27.0/guides/development.html#building "Link to this heading") ------------------------------------------------------------------------------------------------------ For local development, install `sqlc` under an alias. We suggest `sqlc-dev`. go build \-o ~/go/bin/sqlc\-dev ./cmd/sqlc Install `sqlc-gen-json` to avoid test failure. go build \-o ~/go/bin/sqlc\-gen\-json ./cmd/sqlc\-gen\-json Running Tests[](https://docs.sqlc.dev/en/v1.27.0/guides/development.html#running-tests "Link to this heading") ---------------------------------------------------------------------------------------------------------------- go test ./... To run the tests in the examples folder, use the `examples` tag. go test \--tags\=examples ./... These tests require locally-running database instances. Run these databases using [Docker Compose](https://docs.docker.com/compose/) . docker compose up \-d The tests use the following environment variables to connect to the database ### For PostgreSQL[](https://docs.sqlc.dev/en/v1.27.0/guides/development.html#for-postgresql "Link to this heading") Variable Default Value \------------------------- PG\_HOST 127.0.0.1 PG\_PORT 5432 PG\_USER postgres PG\_PASSWORD mysecretpassword PG\_DATABASE dinotest ### For MySQL[](https://docs.sqlc.dev/en/v1.27.0/guides/development.html#for-mysql "Link to this heading") Variable Default Value \------------------------- MYSQL\_HOST 127.0.0.1 MYSQL\_PORT 3306 MYSQL\_USER root MYSQL\_ROOT\_PASSWORD mysecretpassword MYSQL\_DATABASE dinotest --- # Privacy and data collection — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Privacy and data collection * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/guides/privacy.md) * * * Privacy and data collection[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#privacy-and-data-collection "Link to this heading") ======================================================================================================================================== These days, it feels like every piece of software is tracking you. From your browser, to your phone, to your terminal, programs collect as much data about you as possible and send it off to the cloud for analysis. We believe the best way to keep data safe is to never collect it in the first place. Our Privacy Pledge[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#our-privacy-pledge "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The `sqlc` command line tool does not collect any information. It does not send crash reports to a third-party. It does not gather anonymous aggregate user behaviour analytics. No analytics. No finger-printing. No tracking. Not now and not in the future. ### Distribution Channels[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#distribution-channels "Link to this heading") We distribute sqlc using popular package managers such as [Homebrew](https://brew.sh/) and [Snapcraft](https://snapcraft.io/) . These package managers and their associated command-line tools do collect usage metrics. We use these services to make it easy to for users to install sqlc. There will always be an option to download sqlc from a stable URL. Hosted Services[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#hosted-services "Link to this heading") ---------------------------------------------------------------------------------------------------------------- We provide a few hosted services in addition to the sqlc command line tool. ### sqlc.dev[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#sqlc-dev "Link to this heading") * Hosted on [GitHub Pages](https://pages.github.com/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### docs.sqlc.dev[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#docs-sqlc-dev "Link to this heading") * Hosted on [Read the Docs](https://readthedocs.org/) * Analytics with [Plausible](https://plausible.io/privacy-focused-web-analytics) ### play.sqlc.dev[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#play-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Playground data stored in [Google Cloud Storage](https://cloud.google.com/storage) * Automatically deleted after 30 days ### app.sqlc.dev / api.sqlc.dev[](https://docs.sqlc.dev/en/v1.27.0/guides/privacy.html#app-sqlc-dev-api-sqlc-dev "Link to this heading") * Hosted on [Heroku](https://heroku.com/) * Error tracking and tracing with [Sentry](https://sentry.io/) --- # Getting started with SQLite — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Getting started with SQLite * [View page source](https://docs.sqlc.dev/en/stable/_sources/tutorials/getting-started-sqlite.md.txt) * * * Getting started with SQLite[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-sqlite.html#getting-started-with-sqlite "Link to this heading") ========================================================================================================================================================= This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/stable/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/stable/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. Setting up[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-sqlite.html#setting-up "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "sqlite" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-sqlite.html#schema-and-queries "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id INTEGER PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= ?, bio \= ? WHERE id \= ?; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= ?, bio \= ? WHERE id \= ? RETURNING \*; Generating code[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-sqlite.html#generating-code "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-sqlite.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" \_ "embed" "log" "reflect" \_ "modernc.org/sqlite" "tutorial.sqlc.dev/app/tutorial" ) //go:embed schema.sql var ddl string func run() error { ctx := context.Background() db, err := sql.Open("sqlite", ":memory:") if err != nil { return err } // create tables if \_, err := db.ExecContext(ctx, ddl); err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant SQLite driver: go get modernc.org/sqlite go build ./... The program should compile without errors, and run successfully. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. --- # Macros — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Macros * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/macros.md.txt) * * * Macros[](https://docs.sqlc.dev/en/latest/reference/macros.html#macros "Link to this heading") =============================================================================================== `sqlc.arg`[](https://docs.sqlc.dev/en/latest/reference/macros.html#sqlc-arg "Link to this heading") ----------------------------------------------------------------------------------------------------- Attach a name to a parameter in a SQL query. This macro expands to an engine-specific parameter placeholder. The name of the parameter is noted and used during code generation. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.arg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/latest/howto/named_parameters.html) . `sqlc.embed`[](https://docs.sqlc.dev/en/latest/reference/macros.html#sqlc-embed "Link to this heading") --------------------------------------------------------------------------------------------------------- Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ); CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ); \-- name: GetStudentAndScore :one SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; \-- >>> EXPANDS TO >>> \-- name: GetStudentAndScore :one SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; The Go method will return a struct with a field for the `Student` and field for the test `TestScore` instead of each column existing on the struct. type GetStudentAndScoreRow struct { Student Student TestScore TestScore } func (q \*Queries) GetStudentAndScore(ctx context.Context, id int64) (GetStudentAndScoreRow, error) { // ... } See a full example in [Embedding structs](https://docs.sqlc.dev/en/latest/howto/embedding.html) . `sqlc.narg`[](https://docs.sqlc.dev/en/latest/reference/macros.html#sqlc-narg "Link to this heading") ------------------------------------------------------------------------------------------------------- The same as `sqlc.arg`, but always marks the parameter as nullable. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.narg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE LOWER(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/latest/howto/named_parameters.html) . `sqlc.slice`[](https://docs.sqlc.dev/en/latest/reference/macros.html#sqlc-slice "Link to this heading") --------------------------------------------------------------------------------------------------------- For drivers that do not support passing slices to the IN operator, the `sqlc.slice` macro generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) \-- >>> EXPANDS TO >>> /\* name: SelectStudents :many \*/ SELECT id, name, age FROM authors WHERE age IN (/\*SLICE:ages\*/?) Since the `/*SLICE:ages*/` placeholder is dynamically replaced on a per-query basis, this macro can’t be used with prepared statements. See a full example in [Passing a slice as a parameter to a query](https://docs.sqlc.dev/en/latest/howto/select.html#mysql-and-sqlite) . --- # verify - Verifying schema changes — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * `verify` - Verifying schema changes * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/verify.md.txt) * * * `verify` - Verifying schema changes[](https://docs.sqlc.dev/en/stable/howto/verify.html#verify-verifying-schema-changes "Link to this heading") ================================================================================================================================================= _Added in v1.24.0_ Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. Using `verify` requires that you push your queries and schema when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. Authentication[](https://docs.sqlc.dev/en/stable/howto/verify.html#authentication "Link to this heading") ----------------------------------------------------------------------------------------------------------- `sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Expected workflow[](https://docs.sqlc.dev/en/stable/howto/verify.html#expected-workflow "Link to this heading") ----------------------------------------------------------------------------------------------------------------- Using `sqlc verify` requires pushing your queries and schema to sqlc Cloud. When you release a new version of your application, you should push your schema and queries as well. For example, we run `sqlc push` after any change has been merged into our `main` branch on Github, as we deploy every commit to production. $ sqlc push \--tag main Locally or in pull requests, run `sqlc verify` to check that existing queries continue to work with your current database schema. $ sqlc verify \--against main Picking a tag[](https://docs.sqlc.dev/en/stable/howto/verify.html#picking-a-tag "Link to this heading") --------------------------------------------------------------------------------------------------------- Without an `against` argument, `verify` will run its analysis of the provided schema using your most-recently pushed queries. We suggest using the `against` argument to explicitly select a set of queries for comparison. $ sqlc verify \--against \[tag\] --- # Using sqlc in CI/CD — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Using sqlc in CI/CD * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/ci-cd.md.txt) * * * Using sqlc in CI/CD[](https://docs.sqlc.dev/en/latest/howto/ci-cd.html#using-sqlc-in-ci-cd "Link to this heading") ==================================================================================================================== If your project has more than a single developer, we suggest running `sqlc` as part of your CI/CD pipeline. The four subcommands you’ll want to run are `diff`, `vet`, `verify` and `push` `sqlc diff` ensures that your generated code is up to date. New developers to a project may forget to run `sqlc generate` after adding a query or updating a schema. They also might edit generated code. `sqlc diff` will catch both errors by comparing the expected output from `sqlc generate` to what’s on disk. % sqlc diff \--- a/postgresql/query.sql.go +++ b/postgresql/query.sql.go @@ -55,7 +55,7 @@ const listAuthors = \`-- name: ListAuthors :many SELECT id, name, bio FROM authors \-ORDER BY name +ORDER BY bio \` `sqlc vet` runs a set of lint rules against your SQL queries. These rules are helpful in catching anti-patterns before they make it into production. Please see the [vet](https://docs.sqlc.dev/en/latest/howto/vet.html) documentation for a complete guide to adding lint rules for your project. `sqlc verify` ensures that schema changes do not break production. Existing queries are checked against new schema changes for correctness. Please see the [verify](https://docs.sqlc.dev/en/latest/howto/verify.html) documentation for a complete guide. `sqlc push` pushes your database schema, queries and configuration to sqlc Cloud. These archives are used by `verify` to catch breaking changes to your database schema. Learn more about uploading projects [here](https://docs.sqlc.dev/en/latest/howto/push.html) General setup[](https://docs.sqlc.dev/en/latest/howto/ci-cd.html#general-setup "Link to this heading") -------------------------------------------------------------------------------------------------------- Install `sqlc` using the [suggested instructions](https://docs.sqlc.dev/en/latest/overview/install.html) . Create three steps in your pipeline for `sqlc diff`, `sqlc vet`, and `sqlc verify`. Run `sqlc push` after merge on your `main` branch. GitHub Actions[](https://docs.sqlc.dev/en/latest/howto/ci-cd.html#github-actions "Link to this heading") ---------------------------------------------------------------------------------------------------------- We provide the [setup-sqlc](https://github.com/marketplace/actions/setup-sqlc) GitHub Action to install `sqlc`. The action uses the built-in [tool-cache](https://github.com/actions/toolkit/blob/main/packages/tool-cache/README.md) to speed up the installation process. ### diff[](https://docs.sqlc.dev/en/latest/howto/ci-cd.html#diff "Link to this heading") The following GitHub Workflow configuration runs `sqlc diff` on every push. name: sqlc on: \[push\] jobs: diff: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc diff ### vet[](https://docs.sqlc.dev/en/latest/howto/ci-cd.html#vet "Link to this heading") The following GitHub Workflow configuration runs [sqlc vet](https://docs.sqlc.dev/en/latest/howto/vet.html) on every push. You can use `sqlc vet` without a database connection, but you’ll need one if your `sqlc` configuration references the built-in `sqlc/db-prepare` lint rule. name: sqlc on: \[push\] jobs: vet: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \# Start a PostgreSQL server \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc vet env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable ### push[](https://docs.sqlc.dev/en/latest/howto/ci-cd.html#push "Link to this heading") Note Pushing a project is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. The following GitHub Workflow configuration runs [sqlc push](https://docs.sqlc.dev/en/latest/howto/push.html) on every push to `main`. Create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . name: sqlc on: \[push\] jobs: push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} ### verify[](https://docs.sqlc.dev/en/latest/howto/ci-cd.html#verify "Link to this heading") Note Verify database migrations is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. name: sqlc on: \[push\] jobs: verify: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc verify env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} --- # Renaming fields — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Renaming fields * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/rename.md.txt) * * * Renaming fields[](https://docs.sqlc.dev/en/stable/howto/rename.html#renaming-fields "Link to this heading") ============================================================================================================= Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" rename: spotify\_url: "SpotifyURL" Tables[](https://docs.sqlc.dev/en/stable/howto/rename.html#tables "Link to this heading") ------------------------------------------------------------------------------------------- The output structs associated with tables can also be renamed. By default, the struct name will be the singular version of the table name. For example, the `authors` table will generate an `Author` struct and the `book_publishers` table will generate a `BookPublisher` struct. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); CREATE TABLE book\_publishers ( id BIGSERIAL PRIMARY KEY, name text NOT NULL ); package db import ( "database/sql" ) type Author struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } To rename these structs, you must use the generated struct name. In this example, that would be `author` and `book_publisher`. Use the `rename` map to change the name of these struct to `Writer` and `BookPublisher` (note the camel-casing and the underscore for multi-worded tables). version: '1' packages: \- path: db engine: postgresql schema: query.sql queries: query.sql rename: author: Writer book\_publisher: Publisher version: "2" sql: \- engine: postgresql queries: query.sql schema: query.sql overrides: go: rename: author: Writer book\_publisher: Publisher package db import ( "database/sql" ) type Writer struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } Limitations[](https://docs.sqlc.dev/en/stable/howto/rename.html#limitations "Link to this heading") ----------------------------------------------------------------------------------------------------- Rename mappings apply to an entire package. Therefore, a column named `foo` and a table name `foo` can’t map to different rename values. --- # Preparing queries — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Preparing queries * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/prepared_query.md.txt) * * * Preparing queries[](https://docs.sqlc.dev/en/stable/howto/prepared_query.html#preparing-queries "Link to this heading") ========================================================================================================================= If you’re using `pgx/v5` you get its [implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching) for prepared statements. No additional `sqlc` configuration is required. For other drivers, `sqlc` can give you the option to explicitly use prepared queries. These prepared queries also work with transactions. You’ll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration to generate code similar to the example below. CREATE TABLE records ( id SERIAL PRIMARY KEY ); \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; package db import ( "context" "database/sql" "fmt" ) type Record struct { ID int32 } type DBTX interface { PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } func Prepare(ctx context.Context, db DBTX) (\*Queries, error) { q := Queries{db: db} var err error if q.getRecordStmt, err \= db.PrepareContext(ctx, getRecord); err != nil { return nil, fmt.Errorf("error preparing query GetRecord: %w", err) } return &q, nil } func (q \*Queries) queryRow(ctx context.Context, stmt \*sql.Stmt, query string, args ...interface{}) \*sql.Row { switch { case stmt != nil && q.tx != nil: return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...) case stmt != nil: return stmt.QueryRowContext(ctx, args...) default: return q.db.QueryRowContext(ctx, query, args...) } } type Queries struct { db DBTX tx \*sql.Tx getRecordStmt \*sql.Stmt } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, tx: tx, getRecordStmt: q.getRecordStmt, } } const getRecord \= \`-- name: GetRecord :one SELECT id FROM records WHERE id = $1 \` func (q \*Queries) GetRecord(ctx context.Context, id int32) (int32, error) { row := q.queryRow(ctx, q.getRecordStmt, getRecord, id) err := row.Scan(&id) return id, err } --- # Using sqlc in CI/CD — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Using sqlc in CI/CD * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/ci-cd.md.txt) * * * Using sqlc in CI/CD[](https://docs.sqlc.dev/en/stable/howto/ci-cd.html#using-sqlc-in-ci-cd "Link to this heading") ==================================================================================================================== If your project has more than a single developer, we suggest running `sqlc` as part of your CI/CD pipeline. The four subcommands you’ll want to run are `diff`, `vet`, `verify` and `push` `sqlc diff` ensures that your generated code is up to date. New developers to a project may forget to run `sqlc generate` after adding a query or updating a schema. They also might edit generated code. `sqlc diff` will catch both errors by comparing the expected output from `sqlc generate` to what’s on disk. % sqlc diff \--- a/postgresql/query.sql.go +++ b/postgresql/query.sql.go @@ -55,7 +55,7 @@ const listAuthors = \`-- name: ListAuthors :many SELECT id, name, bio FROM authors \-ORDER BY name +ORDER BY bio \` `sqlc vet` runs a set of lint rules against your SQL queries. These rules are helpful in catching anti-patterns before they make it into production. Please see the [vet](https://docs.sqlc.dev/en/stable/howto/vet.html) documentation for a complete guide to adding lint rules for your project. `sqlc verify` ensures that schema changes do not break production. Existing queries are checked against new schema changes for correctness. Please see the [verify](https://docs.sqlc.dev/en/stable/howto/verify.html) documentation for a complete guide. `sqlc push` pushes your database schema, queries and configuration to sqlc Cloud. These archives are used by `verify` to catch breaking changes to your database schema. Learn more about uploading projects [here](https://docs.sqlc.dev/en/stable/howto/push.html) General setup[](https://docs.sqlc.dev/en/stable/howto/ci-cd.html#general-setup "Link to this heading") -------------------------------------------------------------------------------------------------------- Install `sqlc` using the [suggested instructions](https://docs.sqlc.dev/en/stable/overview/install.html) . Create three steps in your pipeline for `sqlc diff`, `sqlc vet`, and `sqlc verify`. Run `sqlc push` after merge on your `main` branch. GitHub Actions[](https://docs.sqlc.dev/en/stable/howto/ci-cd.html#github-actions "Link to this heading") ---------------------------------------------------------------------------------------------------------- We provide the [setup-sqlc](https://github.com/marketplace/actions/setup-sqlc) GitHub Action to install `sqlc`. The action uses the built-in [tool-cache](https://github.com/actions/toolkit/blob/main/packages/tool-cache/README.md) to speed up the installation process. ### diff[](https://docs.sqlc.dev/en/stable/howto/ci-cd.html#diff "Link to this heading") The following GitHub Workflow configuration runs `sqlc diff` on every push. name: sqlc on: \[push\] jobs: diff: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc diff ### vet[](https://docs.sqlc.dev/en/stable/howto/ci-cd.html#vet "Link to this heading") The following GitHub Workflow configuration runs [sqlc vet](https://docs.sqlc.dev/en/stable/howto/vet.html) on every push. You can use `sqlc vet` without a database connection, but you’ll need one if your `sqlc` configuration references the built-in `sqlc/db-prepare` lint rule. name: sqlc on: \[push\] jobs: vet: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \# Start a PostgreSQL server \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc vet env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable ### push[](https://docs.sqlc.dev/en/stable/howto/ci-cd.html#push "Link to this heading") Note Pushing a project is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. The following GitHub Workflow configuration runs [sqlc push](https://docs.sqlc.dev/en/stable/howto/push.html) on every push to `main`. Create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . name: sqlc on: \[push\] jobs: push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} ### verify[](https://docs.sqlc.dev/en/stable/howto/ci-cd.html#verify "Link to this heading") Note Verify database migrations is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. name: sqlc on: \[push\] jobs: verify: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc verify env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} --- # generate - Generating code — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * `generate` - Generating code * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/generate.md.txt) * * * `generate` - Generating code[](https://docs.sqlc.dev/en/v1.31.0/howto/generate.html#generate-generating-code "Link to this heading") ====================================================================================================================================== `sqlc generate` parses SQL, analyzes the results, and outputs code. Your schema and queries are stored in separate SQL files. The paths to these files live in a `sqlc.yaml` configuration file. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" We’ve written extensive docs on [retrieving](https://docs.sqlc.dev/en/v1.31.0/howto/select.html) , [inserting](https://docs.sqlc.dev/en/v1.31.0/howto/insert.html) , [updating](https://docs.sqlc.dev/en/v1.31.0/howto/update.html) , and [deleting](https://docs.sqlc.dev/en/v1.31.0/howto/delete.html) rows. By default, sqlc runs its analysis using a built-in query analysis engine. While fast, this engine can’t handle some complex queries and type-inference. You can configure sqlc to use a database connection for enhanced analysis using metadata from that database. The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. Enhanced analysis with managed databases[](https://docs.sqlc.dev/en/v1.31.0/howto/generate.html#enhanced-analysis-with-managed-databases "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ With [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html) configured, `generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with an up-to-date schema. Here’s a minimal working configuration: version: "2" servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: managed: true gen: go: out: "db" sql\_package: "pgx/v5" Enhanced analysis using your own database[](https://docs.sqlc.dev/en/v1.31.0/howto/generate.html#enhanced-analysis-using-your-own-database "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can opt-in to database-backed analysis using your own database, by providing a `uri` in your sqlc [database](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database) configuration. The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: uri: "postgres://postgres:${PG\_PASSWORD}@localhost:5432/postgres" gen: go: out: "db" sql\_package: "pgx/v5" Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc generate`. --- # Modifying the database schema — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Modifying the database schema * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/ddl.md.txt) * * * Modifying the database schema[](https://docs.sqlc.dev/en/stable/howto/ddl.html#modifying-the-database-schema "Link to this heading") ====================================================================================================================================== sqlc parses `CREATE TABLE` and `ALTER TABLE` statements in order to generate the necessary code. CREATE TABLE authors ( id SERIAL PRIMARY KEY, birth\_year int NOT NULL ); ALTER TABLE authors ADD COLUMN bio text NOT NULL; ALTER TABLE authors DROP COLUMN birth\_year; ALTER TABLE authors RENAME TO writers; package db type Writer struct { ID int Bio string } Handling SQL migrations[](https://docs.sqlc.dev/en/stable/howto/ddl.html#handling-sql-migrations "Link to this heading") -------------------------------------------------------------------------------------------------------------------------- sqlc does not perform database migrations for you. However, sqlc is able to differentiate between up and down migrations. sqlc ignores down migrations when parsing SQL files. sqlc supports parsing migrations from the following tools: * [atlas](https://github.com/ariga/atlas) * [dbmate](https://github.com/amacneil/dbmate) * [golang-migrate](https://github.com/golang-migrate/migrate) * [goose](https://github.com/pressly/goose) * [sql-migrate](https://github.com/rubenv/sql-migrate) * [tern](https://github.com/jackc/tern) To enable migration parsing, specify the migration directory instead of a schema file: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "db/migrations" gen: go: package: "tutorial" out: "tutorial" ### atlas[](https://docs.sqlc.dev/en/stable/howto/ddl.html#atlas "Link to this heading") \-- Create "post" table CREATE TABLE "public"."post" ("id" integer NOT NULL, "title" text NULL, "body" text NULL, PRIMARY KEY ("id")); package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### dbmate[](https://docs.sqlc.dev/en/stable/howto/ddl.html#dbmate "Link to this heading") \-- migrate:up CREATE TABLE foo (bar INT NOT NULL); \-- migrate:down DROP TABLE foo; package db type Foo struct { Bar int32 } ### golang-migrate[](https://docs.sqlc.dev/en/stable/howto/ddl.html#golang-migrate "Link to this heading") **Warning:** [golang-migrate interprets](https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md#migration-filename-format) migration filenames numerically. However, sqlc parses migration files in lexicographic order. If you choose to have sqlc enumerate your migration files, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.up.sql ... 9\_foo.up.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.up.sql This worked as intended. 001\_initial.up.sql ... 009\_foo.up.sql 010\_bar.up.sql In `20060102.up.sql`: CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); In `20060102.down.sql`: DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### goose[](https://docs.sqlc.dev/en/stable/howto/ddl.html#goose "Link to this heading") **Warning:** sqlc parses migration files in lexicographic order. **If you are using numeric filenames for migrations in Goose and you choose to have sqlc enumerate your migration files**, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.sql ... 9\_foo.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.sql This worked as intended. 001\_initial.sql ... 009\_foo.sql 010\_bar.sql \-- +goose Up CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); \-- +goose Down DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### sql-migrate[](https://docs.sqlc.dev/en/stable/howto/ddl.html#sql-migrate "Link to this heading") \-- +migrate Up \-- SQL in section 'Up' is executed when this migration is applied CREATE TABLE people (id int); \-- +migrate Down \-- SQL section 'Down' is executed when this migration is rolled back DROP TABLE people; package db type People struct { ID int32 } ### tern[](https://docs.sqlc.dev/en/stable/howto/ddl.html#tern "Link to this heading") CREATE TABLE comment (id int NOT NULL, text text NOT NULL); \---- create above / drop below ---- DROP TABLE comment; package db type Comment struct { ID int32 Text string } --- # Getting started with SQLite — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Getting started with SQLite * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/tutorials/getting-started-sqlite.md.txt) * * * Getting started with SQLite[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-sqlite.html#getting-started-with-sqlite "Link to this heading") ========================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.31.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.31.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. Setting up[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-sqlite.html#setting-up "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "sqlite" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-sqlite.html#schema-and-queries "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id INTEGER PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= ?, bio \= ? WHERE id \= ?; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= ?, bio \= ? WHERE id \= ? RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-sqlite.html#generating-code "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-sqlite.html#using-generated-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" \_ "embed" "log" "reflect" \_ "modernc.org/sqlite" "tutorial.sqlc.dev/app/tutorial" ) //go:embed schema.sql var ddl string func run() error { ctx := context.Background() db, err := sql.Open("sqlite", ":memory:") if err != nil { return err } // create tables if \_, err := db.ExecContext(ctx, ddl); err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant SQLite driver: go get modernc.org/sqlite go build ./... The program should compile without errors, and run successfully. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. --- # verify - Verifying schema changes — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * `verify` - Verifying schema changes * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/verify.md.txt) * * * `verify` - Verifying schema changes[](https://docs.sqlc.dev/en/v1.31.0/howto/verify.html#verify-verifying-schema-changes "Link to this heading") ================================================================================================================================================== _Added in v1.24.0_ Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. Using `verify` requires that you push your queries and schema when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. Authentication[](https://docs.sqlc.dev/en/v1.31.0/howto/verify.html#authentication "Link to this heading") ------------------------------------------------------------------------------------------------------------ `sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Expected workflow[](https://docs.sqlc.dev/en/v1.31.0/howto/verify.html#expected-workflow "Link to this heading") ------------------------------------------------------------------------------------------------------------------ Using `sqlc verify` requires pushing your queries and schema to sqlc Cloud. When you release a new version of your application, you should push your schema and queries as well. For example, we run `sqlc push` after any change has been merged into our `main` branch on Github, as we deploy every commit to production. $ sqlc push \--tag main Locally or in pull requests, run `sqlc verify` to check that existing queries continue to work with your current database schema. $ sqlc verify \--against main Picking a tag[](https://docs.sqlc.dev/en/v1.31.0/howto/verify.html#picking-a-tag "Link to this heading") ---------------------------------------------------------------------------------------------------------- Without an `against` argument, `verify` will run its analysis of the provided schema using your most-recently pushed queries. We suggest using the `against` argument to explicitly select a set of queries for comparison. $ sqlc verify \--against \[tag\] --- # Renaming fields — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Renaming fields * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/rename.md.txt) * * * Renaming fields[](https://docs.sqlc.dev/en/v1.31.0/howto/rename.html#renaming-fields "Link to this heading") ============================================================================================================== Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" rename: spotify\_url: "SpotifyURL" Tables[](https://docs.sqlc.dev/en/v1.31.0/howto/rename.html#tables "Link to this heading") -------------------------------------------------------------------------------------------- The output structs associated with tables can also be renamed. By default, the struct name will be the singular version of the table name. For example, the `authors` table will generate an `Author` struct and the `book_publishers` table will generate a `BookPublisher` struct. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); CREATE TABLE book\_publishers ( id BIGSERIAL PRIMARY KEY, name text NOT NULL ); package db import ( "database/sql" ) type Author struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } To rename these structs, you must use the generated struct name. In this example, that would be `author` and `book_publisher`. Use the `rename` map to change the name of these struct to `Writer` and `BookPublisher` (note the camel-casing and the underscore for multi-worded tables). version: '1' packages: \- path: db engine: postgresql schema: query.sql queries: query.sql rename: author: Writer book\_publisher: Publisher version: "2" sql: \- engine: postgresql queries: query.sql schema: query.sql overrides: go: rename: author: Writer book\_publisher: Publisher package db import ( "database/sql" ) type Writer struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } Limitations[](https://docs.sqlc.dev/en/v1.31.0/howto/rename.html#limitations "Link to this heading") ------------------------------------------------------------------------------------------------------ Rename mappings apply to an entire package. Therefore, a column named `foo` and a table name `foo` can’t map to different rename values. --- # Modifying the database schema — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Modifying the database schema * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/ddl.md.txt) * * * Modifying the database schema[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#modifying-the-database-schema "Link to this heading") ======================================================================================================================================= sqlc parses `CREATE TABLE` and `ALTER TABLE` statements in order to generate the necessary code. CREATE TABLE authors ( id SERIAL PRIMARY KEY, birth\_year int NOT NULL ); ALTER TABLE authors ADD COLUMN bio text NOT NULL; ALTER TABLE authors DROP COLUMN birth\_year; ALTER TABLE authors RENAME TO writers; package db type Writer struct { ID int Bio string } Handling SQL migrations[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#handling-sql-migrations "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- sqlc does not perform database migrations for you. However, sqlc is able to differentiate between up and down migrations. sqlc ignores down migrations when parsing SQL files. sqlc supports parsing migrations from the following tools: * [atlas](https://github.com/ariga/atlas) * [dbmate](https://github.com/amacneil/dbmate) * [golang-migrate](https://github.com/golang-migrate/migrate) * [goose](https://github.com/pressly/goose) * [sql-migrate](https://github.com/rubenv/sql-migrate) * [tern](https://github.com/jackc/tern) To enable migration parsing, specify the migration directory instead of a schema file: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "db/migrations" gen: go: package: "tutorial" out: "tutorial" ### atlas[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#atlas "Link to this heading") \-- Create "post" table CREATE TABLE "public"."post" ("id" integer NOT NULL, "title" text NULL, "body" text NULL, PRIMARY KEY ("id")); package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### dbmate[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#dbmate "Link to this heading") \-- migrate:up CREATE TABLE foo (bar INT NOT NULL); \-- migrate:down DROP TABLE foo; package db type Foo struct { Bar int32 } ### golang-migrate[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#golang-migrate "Link to this heading") **Warning:** [golang-migrate interprets](https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md#migration-filename-format) migration filenames numerically. However, sqlc parses migration files in lexicographic order. If you choose to have sqlc enumerate your migration files, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.up.sql ... 9\_foo.up.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.up.sql This worked as intended. 001\_initial.up.sql ... 009\_foo.up.sql 010\_bar.up.sql In `20060102.up.sql`: CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); In `20060102.down.sql`: DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### goose[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#goose "Link to this heading") **Warning:** sqlc parses migration files in lexicographic order. **If you are using numeric filenames for migrations in Goose and you choose to have sqlc enumerate your migration files**, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.sql ... 9\_foo.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.sql This worked as intended. 001\_initial.sql ... 009\_foo.sql 010\_bar.sql \-- +goose Up CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); \-- +goose Down DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### sql-migrate[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#sql-migrate "Link to this heading") \-- +migrate Up \-- SQL in section 'Up' is executed when this migration is applied CREATE TABLE people (id int); \-- +migrate Down \-- SQL section 'Down' is executed when this migration is rolled back DROP TABLE people; package db type People struct { ID int32 } ### tern[](https://docs.sqlc.dev/en/v1.31.0/howto/ddl.html#tern "Link to this heading") CREATE TABLE comment (id int NOT NULL, text text NOT NULL); \---- create above / drop below ---- DROP TABLE comment; package db type Comment struct { ID int32 Text string } --- # Macros — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Macros * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/macros.md.txt) * * * Macros[](https://docs.sqlc.dev/en/v1.31.0/reference/macros.html#macros "Link to this heading") ================================================================================================ `sqlc.arg`[](https://docs.sqlc.dev/en/v1.31.0/reference/macros.html#sqlc-arg "Link to this heading") ------------------------------------------------------------------------------------------------------ Attach a name to a parameter in a SQL query. This macro expands to an engine-specific parameter placeholder. The name of the parameter is noted and used during code generation. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.arg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.31.0/howto/named_parameters.html) . `sqlc.embed`[](https://docs.sqlc.dev/en/v1.31.0/reference/macros.html#sqlc-embed "Link to this heading") ---------------------------------------------------------------------------------------------------------- Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ); CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ); \-- name: GetStudentAndScore :one SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; \-- >>> EXPANDS TO >>> \-- name: GetStudentAndScore :one SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; The Go method will return a struct with a field for the `Student` and field for the test `TestScore` instead of each column existing on the struct. type GetStudentAndScoreRow struct { Student Student TestScore TestScore } func (q \*Queries) GetStudentAndScore(ctx context.Context, id int64) (GetStudentAndScoreRow, error) { // ... } See a full example in [Embedding structs](https://docs.sqlc.dev/en/v1.31.0/howto/embedding.html) . `sqlc.narg`[](https://docs.sqlc.dev/en/v1.31.0/reference/macros.html#sqlc-narg "Link to this heading") -------------------------------------------------------------------------------------------------------- The same as `sqlc.arg`, but always marks the parameter as nullable. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.narg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE LOWER(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.31.0/howto/named_parameters.html) . `sqlc.slice`[](https://docs.sqlc.dev/en/v1.31.0/reference/macros.html#sqlc-slice "Link to this heading") ---------------------------------------------------------------------------------------------------------- For drivers that do not support passing slices to the IN operator, the `sqlc.slice` macro generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) \-- >>> EXPANDS TO >>> /\* name: SelectStudents :many \*/ SELECT id, name, age FROM authors WHERE age IN (/\*SLICE:ages\*/?) Since the `/*SLICE:ages*/` placeholder is dynamically replaced on a per-query basis, this macro can’t be used with prepared statements. See a full example in [Passing a slice as a parameter to a query](https://docs.sqlc.dev/en/v1.31.0/howto/select.html#mysql-and-sqlite) . --- # verify - Verifying schema changes — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * `verify` - Verifying schema changes * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/verify.md.txt) * * * `verify` - Verifying schema changes[](https://docs.sqlc.dev/en/v1.31.1/howto/verify.html#verify-verifying-schema-changes "Link to this heading") ================================================================================================================================================== _Added in v1.24.0_ Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. Using `verify` requires that you push your queries and schema when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. Authentication[](https://docs.sqlc.dev/en/v1.31.1/howto/verify.html#authentication "Link to this heading") ------------------------------------------------------------------------------------------------------------ `sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Expected workflow[](https://docs.sqlc.dev/en/v1.31.1/howto/verify.html#expected-workflow "Link to this heading") ------------------------------------------------------------------------------------------------------------------ Using `sqlc verify` requires pushing your queries and schema to sqlc Cloud. When you release a new version of your application, you should push your schema and queries as well. For example, we run `sqlc push` after any change has been merged into our `main` branch on Github, as we deploy every commit to production. $ sqlc push \--tag main Locally or in pull requests, run `sqlc verify` to check that existing queries continue to work with your current database schema. $ sqlc verify \--against main Picking a tag[](https://docs.sqlc.dev/en/v1.31.1/howto/verify.html#picking-a-tag "Link to this heading") ---------------------------------------------------------------------------------------------------------- Without an `against` argument, `verify` will run its analysis of the provided schema using your most-recently pushed queries. We suggest using the `against` argument to explicitly select a set of queries for comparison. $ sqlc verify \--against \[tag\] --- # generate - Generating code — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * `generate` - Generating code * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/generate.md.txt) * * * `generate` - Generating code[](https://docs.sqlc.dev/en/v1.31.1/howto/generate.html#generate-generating-code "Link to this heading") ====================================================================================================================================== `sqlc generate` parses SQL, analyzes the results, and outputs code. Your schema and queries are stored in separate SQL files. The paths to these files live in a `sqlc.yaml` configuration file. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" We’ve written extensive docs on [retrieving](https://docs.sqlc.dev/en/v1.31.1/howto/select.html) , [inserting](https://docs.sqlc.dev/en/v1.31.1/howto/insert.html) , [updating](https://docs.sqlc.dev/en/v1.31.1/howto/update.html) , and [deleting](https://docs.sqlc.dev/en/v1.31.1/howto/delete.html) rows. By default, sqlc runs its analysis using a built-in query analysis engine. While fast, this engine can’t handle some complex queries and type-inference. You can configure sqlc to use a database connection for enhanced analysis using metadata from that database. The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. Enhanced analysis with managed databases[](https://docs.sqlc.dev/en/v1.31.1/howto/generate.html#enhanced-analysis-with-managed-databases "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ With [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html) configured, `generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with an up-to-date schema. Here’s a minimal working configuration: version: "2" servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: managed: true gen: go: out: "db" sql\_package: "pgx/v5" Enhanced analysis using your own database[](https://docs.sqlc.dev/en/v1.31.1/howto/generate.html#enhanced-analysis-using-your-own-database "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can opt-in to database-backed analysis using your own database, by providing a `uri` in your sqlc [database](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database) configuration. The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: uri: "postgres://postgres:${PG\_PASSWORD}@localhost:5432/postgres" gen: go: out: "db" sql\_package: "pgx/v5" Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc generate`. --- # Preparing queries — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Preparing queries * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/prepared_query.md.txt) * * * Preparing queries[](https://docs.sqlc.dev/en/v1.31.1/howto/prepared_query.html#preparing-queries "Link to this heading") ========================================================================================================================== If you’re using `pgx/v5` you get its [implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching) for prepared statements. No additional `sqlc` configuration is required. For other drivers, `sqlc` can give you the option to explicitly use prepared queries. These prepared queries also work with transactions. You’ll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration to generate code similar to the example below. CREATE TABLE records ( id SERIAL PRIMARY KEY ); \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; package db import ( "context" "database/sql" "fmt" ) type Record struct { ID int32 } type DBTX interface { PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } func Prepare(ctx context.Context, db DBTX) (\*Queries, error) { q := Queries{db: db} var err error if q.getRecordStmt, err \= db.PrepareContext(ctx, getRecord); err != nil { return nil, fmt.Errorf("error preparing query GetRecord: %w", err) } return &q, nil } func (q \*Queries) queryRow(ctx context.Context, stmt \*sql.Stmt, query string, args ...interface{}) \*sql.Row { switch { case stmt != nil && q.tx != nil: return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...) case stmt != nil: return stmt.QueryRowContext(ctx, args...) default: return q.db.QueryRowContext(ctx, query, args...) } } type Queries struct { db DBTX tx \*sql.Tx getRecordStmt \*sql.Stmt } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, tx: tx, getRecordStmt: q.getRecordStmt, } } const getRecord \= \`-- name: GetRecord :one SELECT id FROM records WHERE id = $1 \` func (q \*Queries) GetRecord(ctx context.Context, id int32) (int32, error) { row := q.queryRow(ctx, q.getRecordStmt, getRecord, id) err := row.Scan(&id) return id, err } --- # Managed databases — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Managed databases * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/managed-databases.md.txt) * * * Managed databases[](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html#managed-databases "Link to this heading") ============================================================================================================================= _Added in v1.22.0_ `sqlc` can automatically create read-only databases to power query analysis, linting and verification. These databases are immediately useful for powering sqlc’s database-connected query analyzer, an opt-in feature that improves upon sqlc’s built-in query analysis engine. PostgreSQL support is available today, with MySQL on the way. Once configured, `sqlc` will also use managed databases when linting queries with [`sqlc vet`](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html) in cases where your lint rules require a connection to a running database. Managed databases are under active development, and we’re interested in supporting other use-cases. Configuring managed databases[](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html#configuring-managed-databases "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------- To configure `sqlc` to use managed databases, remove the `uri` key from your `database` configuration and replace it with the `managed` key set to `true`. Access to a running database server is required. Add a connection string to the `servers` mapping. version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true An environment variable can also be used via the `${}` syntax. version: '2' servers: \- engine: postgresql uri: ${DATABASE\_URI} sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true Improving codegen[](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html#improving-codegen "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------- Without a database connection, sqlc does its best to parse, analyze and compile your queries just using the schema you pass it and what it knows about the various database engines it supports. In many cases this works just fine, but for more advanced queries sqlc might not have enough information to produce good code. With managed databases configured, `sqlc generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future codegen runs. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true gen: go: out: "db" Linting queries[](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html#linting-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- With managed databases configured, `sqlc vet` will automatically create a hosted ephemeral database with your schema and use that database when running lint rules that require a database connection, e.g. any [rule relying on `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#rules-using-explain-output) . If you don’t yet have any vet rules, the [built-in sqlc/db-prepare rule](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#sqlc-db-prepare) is a good place to start. It prepares each of your queries against the database to ensure the query is valid. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true rules: \- sqlc/db-prepare --- # Getting started with SQLite — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Getting started with SQLite * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/tutorials/getting-started-sqlite.md.txt) * * * Getting started with SQLite[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-sqlite.html#getting-started-with-sqlite "Link to this heading") ========================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.31.1/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.31.1/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. Setting up[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-sqlite.html#setting-up "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "sqlite" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-sqlite.html#schema-and-queries "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id INTEGER PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= ?, bio \= ? WHERE id \= ?; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= ?, bio \= ? WHERE id \= ? RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-sqlite.html#generating-code "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-sqlite.html#using-generated-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" \_ "embed" "log" "reflect" \_ "modernc.org/sqlite" "tutorial.sqlc.dev/app/tutorial" ) //go:embed schema.sql var ddl string func run() error { ctx := context.Background() db, err := sql.Open("sqlite", ":memory:") if err != nil { return err } // create tables if \_, err := db.ExecContext(ctx, ddl); err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant SQLite driver: go get modernc.org/sqlite go build ./... The program should compile without errors, and run successfully. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. --- # Embedding structs — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Embedding structs * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/embedding.md.txt) * * * Embedding structs[](https://docs.sqlc.dev/en/v1.31.1/howto/embedding.html#embedding-structs "Link to this heading") ===================================================================================================================== Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text NOT NULL, age integer NOT NULL ); CREATE TABLE test\_scores ( student\_id bigint NOT NULL, score integer NOT NULL, grade text NOT NULL ); We want to select the student record and the scores they got on a test. Here’s how we’d usually do that: \-- name: ScoreAndTests :many SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; When using Go, sqlc will produce a struct like this: type ScoreAndTestsRow struct { ID int64 Name string Age int32 StudentID int64 Score int32 Grade string } With embedding, the struct will contain a model for both tables instead of a flattened list of columns. \-- name: ScoreAndTests :many SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; type ScoreAndTestsRow struct { Student Student TestScore TestScore } --- # Macros — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Macros * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/macros.md.txt) * * * Macros[](https://docs.sqlc.dev/en/v1.31.1/reference/macros.html#macros "Link to this heading") ================================================================================================ `sqlc.arg`[](https://docs.sqlc.dev/en/v1.31.1/reference/macros.html#sqlc-arg "Link to this heading") ------------------------------------------------------------------------------------------------------ Attach a name to a parameter in a SQL query. This macro expands to an engine-specific parameter placeholder. The name of the parameter is noted and used during code generation. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.arg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.31.1/howto/named_parameters.html) . `sqlc.embed`[](https://docs.sqlc.dev/en/v1.31.1/reference/macros.html#sqlc-embed "Link to this heading") ---------------------------------------------------------------------------------------------------------- Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ); CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ); \-- name: GetStudentAndScore :one SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; \-- >>> EXPANDS TO >>> \-- name: GetStudentAndScore :one SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; The Go method will return a struct with a field for the `Student` and field for the test `TestScore` instead of each column existing on the struct. type GetStudentAndScoreRow struct { Student Student TestScore TestScore } func (q \*Queries) GetStudentAndScore(ctx context.Context, id int64) (GetStudentAndScoreRow, error) { // ... } See a full example in [Embedding structs](https://docs.sqlc.dev/en/v1.31.1/howto/embedding.html) . `sqlc.narg`[](https://docs.sqlc.dev/en/v1.31.1/reference/macros.html#sqlc-narg "Link to this heading") -------------------------------------------------------------------------------------------------------- The same as `sqlc.arg`, but always marks the parameter as nullable. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.narg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE LOWER(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.31.1/howto/named_parameters.html) . `sqlc.slice`[](https://docs.sqlc.dev/en/v1.31.1/reference/macros.html#sqlc-slice "Link to this heading") ---------------------------------------------------------------------------------------------------------- For drivers that do not support passing slices to the IN operator, the `sqlc.slice` macro generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) \-- >>> EXPANDS TO >>> /\* name: SelectStudents :many \*/ SELECT id, name, age FROM authors WHERE age IN (/\*SLICE:ages\*/?) Since the `/*SLICE:ages*/` placeholder is dynamically replaced on a per-query basis, this macro can’t be used with prepared statements. See a full example in [Passing a slice as a parameter to a query](https://docs.sqlc.dev/en/v1.31.1/howto/select.html#mysql-and-sqlite) . --- # generate - Generating code — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * `generate` - Generating code * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/generate.md.txt) * * * `generate` - Generating code[](https://docs.sqlc.dev/en/v1.30.0/howto/generate.html#generate-generating-code "Link to this heading") ====================================================================================================================================== `sqlc generate` parses SQL, analyzes the results, and outputs code. Your schema and queries are stored in separate SQL files. The paths to these files live in a `sqlc.yaml` configuration file. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" We’ve written extensive docs on [retrieving](https://docs.sqlc.dev/en/v1.30.0/howto/select.html) , [inserting](https://docs.sqlc.dev/en/v1.30.0/howto/insert.html) , [updating](https://docs.sqlc.dev/en/v1.30.0/howto/update.html) , and [deleting](https://docs.sqlc.dev/en/v1.30.0/howto/delete.html) rows. By default, sqlc runs its analysis using a built-in query analysis engine. While fast, this engine can’t handle some complex queries and type-inference. You can configure sqlc to use a database connection for enhanced analysis using metadata from that database. The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. Enhanced analysis with managed databases[](https://docs.sqlc.dev/en/v1.30.0/howto/generate.html#enhanced-analysis-with-managed-databases "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ With [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html) configured, `generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with an up-to-date schema. Here’s a minimal working configuration: version: "2" servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: managed: true gen: go: out: "db" sql\_package: "pgx/v5" Enhanced analysis using your own database[](https://docs.sqlc.dev/en/v1.30.0/howto/generate.html#enhanced-analysis-using-your-own-database "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can opt-in to database-backed analysis using your own database, by providing a `uri` in your sqlc [database](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database) configuration. The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: uri: "postgres://postgres:${PG\_PASSWORD}@localhost:5432/postgres" gen: go: out: "db" sql\_package: "pgx/v5" Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc generate`. --- # Getting started with SQLite — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Getting started with SQLite * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/tutorials/getting-started-sqlite.md.txt) * * * Getting started with SQLite[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-sqlite.html#getting-started-with-sqlite "Link to this heading") ========================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.30.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.30.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. Setting up[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-sqlite.html#setting-up "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "sqlite" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-sqlite.html#schema-and-queries "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id INTEGER PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= ?, bio \= ? WHERE id \= ?; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= ?, bio \= ? WHERE id \= ? RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-sqlite.html#generating-code "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-sqlite.html#using-generated-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" \_ "embed" "log" "reflect" \_ "modernc.org/sqlite" "tutorial.sqlc.dev/app/tutorial" ) //go:embed schema.sql var ddl string func run() error { ctx := context.Background() db, err := sql.Open("sqlite", ":memory:") if err != nil { return err } // create tables if \_, err := db.ExecContext(ctx, ddl); err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant SQLite driver: go get modernc.org/sqlite go build ./... The program should compile without errors, and run successfully. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. --- # verify - Verifying schema changes — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * `verify` - Verifying schema changes * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/verify.md.txt) * * * `verify` - Verifying schema changes[](https://docs.sqlc.dev/en/v1.30.0/howto/verify.html#verify-verifying-schema-changes "Link to this heading") ================================================================================================================================================== _Added in v1.24.0_ Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. Using `verify` requires that you push your queries and schema when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. Authentication[](https://docs.sqlc.dev/en/v1.30.0/howto/verify.html#authentication "Link to this heading") ------------------------------------------------------------------------------------------------------------ `sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Expected workflow[](https://docs.sqlc.dev/en/v1.30.0/howto/verify.html#expected-workflow "Link to this heading") ------------------------------------------------------------------------------------------------------------------ Using `sqlc verify` requires pushing your queries and schema to sqlc Cloud. When you release a new version of your application, you should push your schema and queries as well. For example, we run `sqlc push` after any change has been merged into our `main` branch on Github, as we deploy every commit to production. $ sqlc push \--tag main Locally or in pull requests, run `sqlc verify` to check that existing queries continue to work with your current database schema. $ sqlc verify \--against main Picking a tag[](https://docs.sqlc.dev/en/v1.30.0/howto/verify.html#picking-a-tag "Link to this heading") ---------------------------------------------------------------------------------------------------------- Without an `against` argument, `verify` will run its analysis of the provided schema using your most-recently pushed queries. We suggest using the `against` argument to explicitly select a set of queries for comparison. $ sqlc verify \--against \[tag\] --- # push - Uploading projects — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/index.html) * `push` - Uploading projects * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/howto/push.md.txt) * * * `push` - Uploading projects[](https://docs.sqlc.dev/en/v1.29.0/howto/push.html#push-uploading-projects "Link to this heading") ================================================================================================================================ Note `push` is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. _Added in v1.24.0_ We’ve renamed the `upload` sub-command to `push`. We’ve also changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. Add configuration[](https://docs.sqlc.dev/en/v1.29.0/howto/push.html#add-configuration "Link to this heading") ---------------------------------------------------------------------------------------------------------------- After creating a project, add the project ID to your sqlc configuration file. version: "2" cloud: project: "" You’ll also need to create an auth token and make it available via the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Dry run[](https://docs.sqlc.dev/en/v1.29.0/howto/push.html#dry-run "Link to this heading") -------------------------------------------------------------------------------------------- You can see what’s included when uploading your project by using using the `--dry-run` flag: $ sqlc push \--dry-run 2023/11/21 10:39:51 INFO config file\=sqlc.yaml bytes\=912 2023/11/21 10:39:51 INFO codegen\_request queryset\=app file\=codegen\_request.pb 2023/11/21 10:39:51 INFO schema queryset\=app file\=migrations/00001\_initial.sql bytes\=3033 2023/11/21 10:39:51 INFO query queryset\=app file\=queries/app.sql bytes\=1150 The output is the files `sqlc` would have sent without the `--dry-run` flag. Push[](https://docs.sqlc.dev/en/v1.29.0/howto/push.html#push "Link to this heading") -------------------------------------------------------------------------------------- Once you’re ready to push, remove the `--dry-run` flag. $ sqlc push ### Tags[](https://docs.sqlc.dev/en/v1.29.0/howto/push.html#tags "Link to this heading") You can provide tags to associate with a push, primarily as a convenient reference when using `sqlc verify` with the `against` argument. Tags only refer to a single push, so if you pass an existing tag to `push` it will overwrite the previous reference. $ sqlc push \--tag main ### Annotations[](https://docs.sqlc.dev/en/v1.29.0/howto/push.html#annotations "Link to this heading") Annotations are added to each push request. By default, we include these environment variables (if they are present). GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA --- # Embedding structs — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Embedding structs * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/embedding.md.txt) * * * Embedding structs[](https://docs.sqlc.dev/en/v1.30.0/howto/embedding.html#embedding-structs "Link to this heading") ===================================================================================================================== Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text NOT NULL, age integer NOT NULL ); CREATE TABLE test\_scores ( student\_id bigint NOT NULL, score integer NOT NULL, grade text NOT NULL ); We want to select the student record and the scores they got on a test. Here’s how we’d usually do that: \-- name: ScoreAndTests :many SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; When using Go, sqlc will produce a struct like this: type ScoreAndTestsRow struct { ID int64 Name string Age int32 StudentID int64 Score int32 Grade string } With embedding, the struct will contain a model for both tables instead of a flattened list of columns. \-- name: ScoreAndTests :many SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; type ScoreAndTestsRow struct { Student Student TestScore TestScore } --- # Modifying the database schema — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Modifying the database schema * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/ddl.md.txt) * * * Modifying the database schema[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#modifying-the-database-schema "Link to this heading") ======================================================================================================================================= sqlc parses `CREATE TABLE` and `ALTER TABLE` statements in order to generate the necessary code. CREATE TABLE authors ( id SERIAL PRIMARY KEY, birth\_year int NOT NULL ); ALTER TABLE authors ADD COLUMN bio text NOT NULL; ALTER TABLE authors DROP COLUMN birth\_year; ALTER TABLE authors RENAME TO writers; package db type Writer struct { ID int Bio string } Handling SQL migrations[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#handling-sql-migrations "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- sqlc does not perform database migrations for you. However, sqlc is able to differentiate between up and down migrations. sqlc ignores down migrations when parsing SQL files. sqlc supports parsing migrations from the following tools: * [atlas](https://github.com/ariga/atlas) * [dbmate](https://github.com/amacneil/dbmate) * [golang-migrate](https://github.com/golang-migrate/migrate) * [goose](https://github.com/pressly/goose) * [sql-migrate](https://github.com/rubenv/sql-migrate) * [tern](https://github.com/jackc/tern) To enable migration parsing, specify the migration directory instead of a schema file: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "db/migrations" gen: go: package: "tutorial" out: "tutorial" ### atlas[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#atlas "Link to this heading") \-- Create "post" table CREATE TABLE "public"."post" ("id" integer NOT NULL, "title" text NULL, "body" text NULL, PRIMARY KEY ("id")); package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### dbmate[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#dbmate "Link to this heading") \-- migrate:up CREATE TABLE foo (bar INT NOT NULL); \-- migrate:down DROP TABLE foo; package db type Foo struct { Bar int32 } ### golang-migrate[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#golang-migrate "Link to this heading") **Warning:** [golang-migrate interprets](https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md#migration-filename-format) migration filenames numerically. However, sqlc parses migration files in lexicographic order. If you choose to have sqlc enumerate your migration files, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.up.sql ... 9\_foo.up.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.up.sql This worked as intended. 001\_initial.up.sql ... 009\_foo.up.sql 010\_bar.up.sql In `20060102.up.sql`: CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); In `20060102.down.sql`: DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### goose[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#goose "Link to this heading") **Warning:** sqlc parses migration files in lexicographic order. **If you are using numeric filenames for migrations in Goose and you choose to have sqlc enumerate your migration files**, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.sql ... 9\_foo.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.sql This worked as intended. 001\_initial.sql ... 009\_foo.sql 010\_bar.sql \-- +goose Up CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); \-- +goose Down DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### sql-migrate[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#sql-migrate "Link to this heading") \-- +migrate Up \-- SQL in section 'Up' is executed when this migration is applied CREATE TABLE people (id int); \-- +migrate Down \-- SQL section 'Down' is executed when this migration is rolled back DROP TABLE people; package db type People struct { ID int32 } ### tern[](https://docs.sqlc.dev/en/v1.30.0/howto/ddl.html#tern "Link to this heading") CREATE TABLE comment (id int NOT NULL, text text NOT NULL); \---- create above / drop below ---- DROP TABLE comment; package db type Comment struct { ID int32 Text string } --- # Macros — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Macros * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/macros.md.txt) * * * Macros[](https://docs.sqlc.dev/en/stable/reference/macros.html#macros "Link to this heading") =============================================================================================== `sqlc.arg`[](https://docs.sqlc.dev/en/stable/reference/macros.html#sqlc-arg "Link to this heading") ----------------------------------------------------------------------------------------------------- Attach a name to a parameter in a SQL query. This macro expands to an engine-specific parameter placeholder. The name of the parameter is noted and used during code generation. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.arg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/stable/howto/named_parameters.html) . `sqlc.embed`[](https://docs.sqlc.dev/en/stable/reference/macros.html#sqlc-embed "Link to this heading") --------------------------------------------------------------------------------------------------------- Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ); CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ); \-- name: GetStudentAndScore :one SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; \-- >>> EXPANDS TO >>> \-- name: GetStudentAndScore :one SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; The Go method will return a struct with a field for the `Student` and field for the test `TestScore` instead of each column existing on the struct. type GetStudentAndScoreRow struct { Student Student TestScore TestScore } func (q \*Queries) GetStudentAndScore(ctx context.Context, id int64) (GetStudentAndScoreRow, error) { // ... } See a full example in [Embedding structs](https://docs.sqlc.dev/en/stable/howto/embedding.html) . `sqlc.narg`[](https://docs.sqlc.dev/en/stable/reference/macros.html#sqlc-narg "Link to this heading") ------------------------------------------------------------------------------------------------------- The same as `sqlc.arg`, but always marks the parameter as nullable. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.narg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE LOWER(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/stable/howto/named_parameters.html) . `sqlc.slice`[](https://docs.sqlc.dev/en/stable/reference/macros.html#sqlc-slice "Link to this heading") --------------------------------------------------------------------------------------------------------- For drivers that do not support passing slices to the IN operator, the `sqlc.slice` macro generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) \-- >>> EXPANDS TO >>> /\* name: SelectStudents :many \*/ SELECT id, name, age FROM authors WHERE age IN (/\*SLICE:ages\*/?) Since the `/*SLICE:ages*/` placeholder is dynamically replaced on a per-query basis, this macro can’t be used with prepared statements. See a full example in [Passing a slice as a parameter to a query](https://docs.sqlc.dev/en/stable/howto/select.html#mysql-and-sqlite) . --- # vet - Linting queries — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * `vet` - Linting queries * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/vet.md.txt) * * * `vet` - Linting queries[](https://docs.sqlc.dev/en/stable/howto/vet.html#vet-linting-queries "Link to this heading") ====================================================================================================================== _Added in v1.19.0_ `sqlc vet` runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/stable/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, `sqlc vet` will report an error using the given message. Defining lint rules[](https://docs.sqlc.dev/en/stable/howto/vet.html#defining-lint-rules "Link to this heading") ------------------------------------------------------------------------------------------------------------------ Each lint rule’s CEL expression has access to information from your sqlc configuration and queries via variables defined in the following proto messages. message Config { string version \= 1; string engine \= 2 ; repeated string schema \= 3; repeated string queries \= 4; } message Query { // SQL body string sql \= 1; // Name of the query string name \= 2; // One of "many", "one", "exec", etc. string cmd \= 3; // Query parameters, if any repeated Parameter params \= 4; } message Parameter { int32 number \= 1; } In addition to this basic information, when you have a PostgreSQL or MySQL [database connection configured](https://docs.sqlc.dev/en/stable/reference/config.html#database) each CEL expression has access to the output from running `EXPLAIN ...` on your query via the `postgresql.explain` and `mysql.explain` variables. This output is quite complex and depends on the structure of your query but sqlc attempts to parse and provide as much information as it can. See [Rules using `EXPLAIN ...` output](https://docs.sqlc.dev/en/stable/howto/vet.html#rules-using-explain-output) for more information. Here are a few example rules just using the basic configuration and query information available to the CEL expression environment. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Rules using `EXPLAIN ...` output[](https://docs.sqlc.dev/en/stable/howto/vet.html#rules-using-explain-output "Link to this heading") _Added in v1.20.0_ The CEL expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/stable/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- debug rules: \- name: debug rule: "!has(postgresql.explain)" \# A dummy rule to trigger explain Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with rules that depend on `EXPLAIN ...` output. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. Built-in rules[](https://docs.sqlc.dev/en/stable/howto/vet.html#built-in-rules "Link to this heading") -------------------------------------------------------------------------------------------------------- ### sqlc/db-prepare[](https://docs.sqlc.dev/en/stable/howto/vet.html#sqlc-db-prepare "Link to this heading") When a [database](https://docs.sqlc.dev/en/stable/reference/config.html#database) connection is configured, you can run the built-in `sqlc/db-prepare` rule. This rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with the `sqlc/db-prepare` rule. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. version: 2 cloud: project: "" sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: managed: true rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Running lint rules[](https://docs.sqlc.dev/en/stable/howto/vet.html#running-lint-rules "Link to this heading") ---------------------------------------------------------------------------------------------------------------- When you add the name of a defined rule to the rules list for a [sql package](https://docs.sqlc.dev/en/stable/reference/config.html#sql) , `sqlc vet` will evaluate that rule against every query in the package. In the example below, two rules are defined but only one is enabled. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-delete rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") ### Opting-out of lint rules[](https://docs.sqlc.dev/en/stable/howto/vet.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. The annotation accepts a list of rules to ignore. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; The rules can also be split across lines. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare \*/ /\* @sqlc-vet-disable no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; To skip all rules for a query, you can provide the `@sqlc-vet-disable` annotation without any parameters. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; --- # Overriding types — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Overriding types * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/overrides.md.txt) * * * Overriding types[](https://docs.sqlc.dev/en/stable/howto/overrides.html#overriding-types "Link to this heading") ================================================================================================================== Note Type overrides and field renaming are only fully-supported for Go. In many cases it’s useful to tell `sqlc` explicitly what Go type you want it to use for a query input or output. For instance, by default when you use `pgx/v5`, `sqlc` will map a PostgreSQL UUID type to `UUID` from `github.com/jackc/pgx/pgtype`. But you may want `sqlc` to use `UUID` from `github.com/google/uuid` instead. To tell `sqlc` to use a different Go type, add an entry to the `overrides` list in your configuration. `sqlc` offers two kinds of Go type overrides: * `db_type` overrides, which override the Go type for a specific database type. * `column` overrides, which override the Go type for a column or columns by name. Here’s an example including one of each kind: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" nullable: true go\_type: import: "github.com/google/uuid" type: "UUID" \- column: "users.birthday" go\_type: "time.Time" Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. The `overrides` list[](https://docs.sqlc.dev/en/stable/howto/overrides.html#the-overrides-list "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ Each element in the `overrides` list has the following keys: * `db_type`: * A database type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use pg\_catalog-prefixed names where available. `db_type` and `column` are mutually exclusive. * `column`: * A column name to override. The value should be of the form `table.column` but you can also specify `schema.table.column` or `catalog.schema.table.column`. `column` and `db_type` are mutually exclusive. * `go_type`: * The fully-qualified name of a Go type to use in generated code. This is usually a string but can also be [a map](https://docs.sqlc.dev/en/stable/howto/overrides.html#the-go-type-map) for more complex configurations. * `go_struct_tag`: * A reflect-style struct tag to use in generated code, e.g. `a:"b" x:"y,z"`. If you want `json` or `db` tags for all fields, configure `emit_json_tags` or `emit_db_tags` instead. * `unsigned`: * If `true`, sqlc will apply this override when a numeric column is unsigned. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. * `nullable`: * If `true`, sqlc will apply this override when a column is nullable. Otherwise `sqlc` will apply this override when a column is non-nullable. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. Note When generating code, `column` override configurations take precedence over `db_type` configurations. ### The `go_type` map[](https://docs.sqlc.dev/en/stable/howto/overrides.html#the-go-type-map "Link to this heading") Some overrides may require more detailed configuration. If necessary, `go_type` can be a map with the following keys: * `import`: * The import path for the package where the type is defined. * `package`: * The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name. * `type`: * The type name itself, without any package prefix. * `pointer`: * If `true`, generated code will use a pointer to the type rather than the type itself. * `slice`: * If `true`, generated code will use a slice of the type rather than the type itself. An example: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" go\_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true Global overrides[](https://docs.sqlc.dev/en/stable/howto/overrides.html#global-overrides "Link to this heading") ------------------------------------------------------------------------------------------------------------------ To override types in all packages that `sqlc` generates, add an override configuration to the top-level `overrides` section of your `sqlc` config: version: "2" overrides: go: overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "service1/schema.sql" queries: "service1/query.sql" engine: "postgresql" gen: go: package: "service1" out: "service1" \- schema: "service2/schema.sql" queries: "service2/query.sql" engine: "postgresql" gen: go: package: "service2" out: "service2" Using this configuration, whenever there is a nullable `timestamp with time zone` column in a Postgres table, `sqlc` will generate Go code using `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in per-package type overrides. This field is only used when there are multiple `sql` sections using different engines. If you’re only generating code for a single database engine you can omit it. ### Version 1 configuration[](https://docs.sqlc.dev/en/stable/howto/overrides.html#version-1-configuration "Link to this heading") If you are using the older version 1 of the `sqlc` configuration format, override configurations themselves are unchanged but are nested differently. Per-package configurations are nested under the `overrides` key within an item in the `packages` list: version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" overrides: \[...\] And global configurations are nested under the top-level `overrides` key: version: "1" packages: \[...\] overrides: \- db\_type: "uuid" go\_type: "github.com/gofrs/uuid.UUID" --- # Query annotations — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Query annotations * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/query-annotations.md.txt) * * * Query annotations[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#query-annotations "Link to this heading") ================================================================================================================================ sqlc requires each query to have a small comment indicating the name and command. The format of this comment is as follows: \-- name: `:exec`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#exec "Link to this heading") --------------------------------------------------------------------------------------------------------- The generated method will return the error from [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; func (q \*Queries) DeleteAuthor(ctx context.Context, id int64) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } `:execresult`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#execresult "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The generated method will return the [sql.Result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execresult DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (sql.Result, error) { return q.db.ExecContext(ctx, deleteAllAuthors) } `:execrows`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#execrows "Link to this heading") ----------------------------------------------------------------------------------------------------------------- The generated method will return the number of affected rows from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execrows DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (int64, error) { \_, err := q.db.ExecContext(ctx, deleteAllAuthors) // ... } `:execlastid`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#execlastid "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The generated method will return the number generated by the database from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: InsertAuthor :execlastid INSERT INTO authors (name) VALUES (?); func (q \*Queries) InsertAuthor(ctx context.Context, name string) (int64, error) { \_, err := q.db.ExecContext(ctx, insertAuthor, name) // ... } `:many`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#many "Link to this heading") --------------------------------------------------------------------------------------------------------- The generated method will return a slice of records via [QueryContext](https://golang.org/pkg/database/sql/#DB.QueryContext) . \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) // ... } `:one`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#one "Link to this heading") ------------------------------------------------------------------------------------------------------- The generated method will return a single record via [QueryRowContext](https://golang.org/pkg/database/sql/#DB.QueryRowContext) . \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; func (q \*Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) // ... } `:batchexec`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#batchexec "Link to this heading") ------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Exec`, that takes a `func(int, error)` parameter, * `Close`, to close the batch operation early. \-- name: DeleteBook :batchexec DELETE FROM books WHERE book\_id \= $1; type DeleteBookBatchResults struct { br pgx.BatchResults ind int } func (q \*Queries) DeleteBook(ctx context.Context, bookID \[\]int32) \*DeleteBookBatchResults { //... } func (b \*DeleteBookBatchResults) Exec(f func(int, error)) { //... } func (b \*DeleteBookBatchResults) Close() error { //... } `:batchmany`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#batchmany "Link to this heading") ------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Query`, that takes a `func(int, []T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: BooksByTitleYear :batchmany SELECT \* FROM books WHERE title \= $1 AND year \= $2; type BooksByTitleYearBatchResults struct { br pgx.BatchResults ind int } type BooksByTitleYearParams struct { Title string \`json:"title"\` Year int32 \`json:"year"\` } func (q \*Queries) BooksByTitleYear(ctx context.Context, arg \[\]BooksByTitleYearParams) \*BooksByTitleYearBatchResults { //... } func (b \*BooksByTitleYearBatchResults) Query(f func(int, \[\]Book, error)) { //... } func (b \*BooksByTitleYearBatchResults) Close() error { //... } `:batchone`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#batchone "Link to this heading") ----------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `QueryRow`, that takes a `func(int, T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: CreateBook :batchone INSERT INTO books ( author\_id, isbn ) VALUES ( $1, $2 ) RETURNING book\_id, author\_id, isbn type CreateBookBatchResults struct { br pgx.BatchResults ind int } type CreateBookParams struct { AuthorID int32 \`json:"author\_id"\` Isbn string \`json:"isbn"\` } func (q \*Queries) CreateBook(ctx context.Context, arg \[\]CreateBookParams) \*CreateBookBatchResults { //... } func (b \*CreateBookBatchResults) QueryRow(f func(int, Book, error)) { //... } func (b \*CreateBookBatchResults) Close() error { //... } `:copyfrom`[](https://docs.sqlc.dev/en/stable/reference/query-annotations.html#copyfrom "Link to this heading") ----------------------------------------------------------------------------------------------------------------- \_\_NOTE: This command is driver and package specific, see [how to insert](https://docs.sqlc.dev/en/stable/howto/insert.html#using-copyfrom) This command is used to insert rows a lot faster than sequential inserts. --- # Inserting rows — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Inserting rows * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/insert.md.txt) * * * Inserting rows[](https://docs.sqlc.dev/en/v1.31.0/howto/insert.html#inserting-rows "Link to this heading") ============================================================================================================ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1); **MySQL and SQLite:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES (?); package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const createAuthor \= \`-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1) \` func (q \*Queries) CreateAuthor(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, createAuthor, bio) return err } Returning columns from inserted rows[](https://docs.sqlc.dev/en/v1.31.0/howto/insert.html#returning-columns-from-inserted-rows "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------- sqlc has full support for the `RETURNING` statement. \-- Example queries for sqlc CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); **PostgreSQL:** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id; **SQLite (with RETURNING support):** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING id; Note: MySQL does not support the `RETURNING` clause. Use `:execresult` instead to get the last insert ID. package db import ( "context" "database/sql" ) const createAuthor \= \`-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id, name, bio \` type CreateAuthorParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) var i Author err := row.Scan(&i.ID, &i.Name, &i.Bio) return i, err } const createAuthorAndReturnId \= \`-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id \` type CreateAuthorAndReturnIdParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthorAndReturnId(ctx context.Context, arg CreateAuthorAndReturnIdParams) (int64, error) { row := q.db.QueryRowContext(ctx, createAuthorAndReturnId, arg.Name, arg.Bio) var id int64 err := row.Scan(&id) return id, err } Using CopyFrom[](https://docs.sqlc.dev/en/v1.31.0/howto/insert.html#using-copyfrom "Link to this heading") ------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.31.0/howto/insert.html#postgresql "Link to this heading") PostgreSQL supports the [COPY protocol](https://www.postgresql.org/docs/current/sql-copy.html) that can insert rows a lot faster than sequential inserts. You can use this easily with sqlc: CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text NOT NULL ); \-- name: CreateAuthors :copyfrom INSERT INTO authors (name, bio) VALUES ($1, $2); type CreateAuthorsParams struct { Name string Bio string } func (q \*Queries) CreateAuthors(ctx context.Context, arg \[\]CreateAuthorsParams) (int64, error) { ... } The `:copyfrom` command requires either `pgx/v4` or `pgx/v5`. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" ### MySQL[](https://docs.sqlc.dev/en/v1.31.0/howto/insert.html#mysql "Link to this heading") MySQL supports a similar feature using [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) . Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use SHOW WARNINGS to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } The `:copyfrom` command requires setting the `sql_package` and `sql_driver` options. version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "database/sql" sql\_driver: "github.com/go-sql-driver/mysql" out: "db" --- # Overriding types — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Overriding types * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/overrides.md.txt) * * * Overriding types[](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html#overriding-types "Link to this heading") =================================================================================================================== Note Type overrides and field renaming are only fully-supported for Go. In many cases it’s useful to tell `sqlc` explicitly what Go type you want it to use for a query input or output. For instance, by default when you use `pgx/v5`, `sqlc` will map a PostgreSQL UUID type to `UUID` from `github.com/jackc/pgx/pgtype`. But you may want `sqlc` to use `UUID` from `github.com/google/uuid` instead. To tell `sqlc` to use a different Go type, add an entry to the `overrides` list in your configuration. `sqlc` offers two kinds of Go type overrides: * `db_type` overrides, which override the Go type for a specific database type. * `column` overrides, which override the Go type for a column or columns by name. Here’s an example including one of each kind: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" nullable: true go\_type: import: "github.com/google/uuid" type: "UUID" \- column: "users.birthday" go\_type: "time.Time" Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. The `overrides` list[](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html#the-overrides-list "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- Each element in the `overrides` list has the following keys: * `db_type`: * A database type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use pg\_catalog-prefixed names where available. `db_type` and `column` are mutually exclusive. * `column`: * A column name to override. The value should be of the form `table.column` but you can also specify `schema.table.column` or `catalog.schema.table.column`. `column` and `db_type` are mutually exclusive. * `go_type`: * The fully-qualified name of a Go type to use in generated code. This is usually a string but can also be [a map](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html#the-go-type-map) for more complex configurations. * `go_struct_tag`: * A reflect-style struct tag to use in generated code, e.g. `a:"b" x:"y,z"`. If you want `json` or `db` tags for all fields, configure `emit_json_tags` or `emit_db_tags` instead. * `unsigned`: * If `true`, sqlc will apply this override when a numeric column is unsigned. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. * `nullable`: * If `true`, sqlc will apply this override when a column is nullable. Otherwise `sqlc` will apply this override when a column is non-nullable. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. Note When generating code, `column` override configurations take precedence over `db_type` configurations. ### The `go_type` map[](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html#the-go-type-map "Link to this heading") Some overrides may require more detailed configuration. If necessary, `go_type` can be a map with the following keys: * `import`: * The import path for the package where the type is defined. * `package`: * The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name. * `type`: * The type name itself, without any package prefix. * `pointer`: * If `true`, generated code will use a pointer to the type rather than the type itself. * `slice`: * If `true`, generated code will use a slice of the type rather than the type itself. An example: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" go\_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true Global overrides[](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html#global-overrides "Link to this heading") ------------------------------------------------------------------------------------------------------------------- To override types in all packages that `sqlc` generates, add an override configuration to the top-level `overrides` section of your `sqlc` config: version: "2" overrides: go: overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "service1/schema.sql" queries: "service1/query.sql" engine: "postgresql" gen: go: package: "service1" out: "service1" \- schema: "service2/schema.sql" queries: "service2/query.sql" engine: "postgresql" gen: go: package: "service2" out: "service2" Using this configuration, whenever there is a nullable `timestamp with time zone` column in a Postgres table, `sqlc` will generate Go code using `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in per-package type overrides. This field is only used when there are multiple `sql` sections using different engines. If you’re only generating code for a single database engine you can omit it. ### Version 1 configuration[](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html#version-1-configuration "Link to this heading") If you are using the older version 1 of the `sqlc` configuration format, override configurations themselves are unchanged but are nested differently. Per-package configurations are nested under the `overrides` key within an item in the `packages` list: version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" overrides: \[...\] And global configurations are nested under the top-level `overrides` key: version: "1" packages: \[...\] overrides: \- db\_type: "uuid" go\_type: "github.com/gofrs/uuid.UUID" --- # Modifying the database schema — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Modifying the database schema * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/ddl.md.txt) * * * Modifying the database schema[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#modifying-the-database-schema "Link to this heading") ======================================================================================================================================= sqlc parses `CREATE TABLE` and `ALTER TABLE` statements in order to generate the necessary code. CREATE TABLE authors ( id SERIAL PRIMARY KEY, birth\_year int NOT NULL ); ALTER TABLE authors ADD COLUMN bio text NOT NULL; ALTER TABLE authors DROP COLUMN birth\_year; ALTER TABLE authors RENAME TO writers; package db type Writer struct { ID int Bio string } Handling SQL migrations[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#handling-sql-migrations "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- sqlc does not perform database migrations for you. However, sqlc is able to differentiate between up and down migrations. sqlc ignores down migrations when parsing SQL files. sqlc supports parsing migrations from the following tools: * [atlas](https://github.com/ariga/atlas) * [dbmate](https://github.com/amacneil/dbmate) * [golang-migrate](https://github.com/golang-migrate/migrate) * [goose](https://github.com/pressly/goose) * [sql-migrate](https://github.com/rubenv/sql-migrate) * [tern](https://github.com/jackc/tern) To enable migration parsing, specify the migration directory instead of a schema file: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "db/migrations" gen: go: package: "tutorial" out: "tutorial" ### atlas[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#atlas "Link to this heading") \-- Create "post" table CREATE TABLE "public"."post" ("id" integer NOT NULL, "title" text NULL, "body" text NULL, PRIMARY KEY ("id")); package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### dbmate[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#dbmate "Link to this heading") \-- migrate:up CREATE TABLE foo (bar INT NOT NULL); \-- migrate:down DROP TABLE foo; package db type Foo struct { Bar int32 } ### golang-migrate[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#golang-migrate "Link to this heading") **Warning:** [golang-migrate interprets](https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md#migration-filename-format) migration filenames numerically. However, sqlc parses migration files in lexicographic order. If you choose to have sqlc enumerate your migration files, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.up.sql ... 9\_foo.up.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.up.sql This worked as intended. 001\_initial.up.sql ... 009\_foo.up.sql 010\_bar.up.sql In `20060102.up.sql`: CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); In `20060102.down.sql`: DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### goose[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#goose "Link to this heading") **Warning:** sqlc parses migration files in lexicographic order. **If you are using numeric filenames for migrations in Goose and you choose to have sqlc enumerate your migration files**, make sure their numeric ordering matches their lexicographic ordering to avoid unexpected behavior. This can be done by prepending enough zeroes to the migration filenames. This doesn’t work as intended. 1\_initial.sql ... 9\_foo.sql \# this migration file will be parsed BEFORE 9\_foo 10\_bar.sql This worked as intended. 001\_initial.sql ... 009\_foo.sql 010\_bar.sql \-- +goose Up CREATE TABLE post ( id int NOT NULL, title text, body text, PRIMARY KEY(id) ); \-- +goose Down DROP TABLE post; package db type Post struct { ID int Title sql.NullString Body sql.NullString } ### sql-migrate[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#sql-migrate "Link to this heading") \-- +migrate Up \-- SQL in section 'Up' is executed when this migration is applied CREATE TABLE people (id int); \-- +migrate Down \-- SQL section 'Down' is executed when this migration is rolled back DROP TABLE people; package db type People struct { ID int32 } ### tern[](https://docs.sqlc.dev/en/v1.31.1/howto/ddl.html#tern "Link to this heading") CREATE TABLE comment (id int NOT NULL, text text NOT NULL); \---- create above / drop below ---- DROP TABLE comment; package db type Comment struct { ID int32 Text string } --- # Getting started with MySQL — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Getting started with MySQL * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/tutorials/getting-started-mysql.md.txt) * * * Getting started with MySQL[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-mysql.html#getting-started-with-mysql "Link to this heading") ======================================================================================================================================================= This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.31.1/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.31.1/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-mysql.html#setting-up "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-mysql.html#schema-and-queries "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGINT NOT NULL AUTO\_INCREMENT PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following four queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :execresult INSERT INTO authors ( name, bio ) VALUES ( ?, ? ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; Generating code[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-mysql.html#generating-code "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-mysql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" "log" "reflect" \_ "github.com/go-sql-driver/mysql" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() db, err := sql.Open("mysql", "user:password@/dbname?parseTime=true") if err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant MySQL driver: go get github.com/go-sql-driver/mysql go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `sql.Open()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-mysql.html#query-verification "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial --- # Inserting rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Inserting rows * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/insert.md.txt) * * * Inserting rows[](https://docs.sqlc.dev/en/v1.31.1/howto/insert.html#inserting-rows "Link to this heading") ============================================================================================================ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1); **MySQL and SQLite:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES (?); package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const createAuthor \= \`-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1) \` func (q \*Queries) CreateAuthor(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, createAuthor, bio) return err } Returning columns from inserted rows[](https://docs.sqlc.dev/en/v1.31.1/howto/insert.html#returning-columns-from-inserted-rows "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------- sqlc has full support for the `RETURNING` statement. \-- Example queries for sqlc CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); **PostgreSQL:** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id; **SQLite (with RETURNING support):** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING id; Note: MySQL does not support the `RETURNING` clause. Use `:execresult` instead to get the last insert ID. package db import ( "context" "database/sql" ) const createAuthor \= \`-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id, name, bio \` type CreateAuthorParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) var i Author err := row.Scan(&i.ID, &i.Name, &i.Bio) return i, err } const createAuthorAndReturnId \= \`-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id \` type CreateAuthorAndReturnIdParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthorAndReturnId(ctx context.Context, arg CreateAuthorAndReturnIdParams) (int64, error) { row := q.db.QueryRowContext(ctx, createAuthorAndReturnId, arg.Name, arg.Bio) var id int64 err := row.Scan(&id) return id, err } Using CopyFrom[](https://docs.sqlc.dev/en/v1.31.1/howto/insert.html#using-copyfrom "Link to this heading") ------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.31.1/howto/insert.html#postgresql "Link to this heading") PostgreSQL supports the [COPY protocol](https://www.postgresql.org/docs/current/sql-copy.html) that can insert rows a lot faster than sequential inserts. You can use this easily with sqlc: CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text NOT NULL ); \-- name: CreateAuthors :copyfrom INSERT INTO authors (name, bio) VALUES ($1, $2); type CreateAuthorsParams struct { Name string Bio string } func (q \*Queries) CreateAuthors(ctx context.Context, arg \[\]CreateAuthorsParams) (int64, error) { ... } The `:copyfrom` command requires either `pgx/v4` or `pgx/v5`. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" ### MySQL[](https://docs.sqlc.dev/en/v1.31.1/howto/insert.html#mysql "Link to this heading") MySQL supports a similar feature using [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) . Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use SHOW WARNINGS to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } The `:copyfrom` command requires setting the `sql_package` and `sql_driver` options. version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "database/sql" sql\_driver: "github.com/go-sql-driver/mysql" out: "db" --- # Query annotations — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Query annotations * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/query-annotations.md.txt) * * * Query annotations[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#query-annotations "Link to this heading") ================================================================================================================================= sqlc requires each query to have a small comment indicating the name and command. The format of this comment is as follows: \-- name: `:exec`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#exec "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return the error from [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; func (q \*Queries) DeleteAuthor(ctx context.Context, id int64) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } `:execresult`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#execresult "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the [sql.Result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execresult DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (sql.Result, error) { return q.db.ExecContext(ctx, deleteAllAuthors) } `:execrows`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#execrows "Link to this heading") ------------------------------------------------------------------------------------------------------------------ The generated method will return the number of affected rows from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execrows DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (int64, error) { \_, err := q.db.ExecContext(ctx, deleteAllAuthors) // ... } `:execlastid`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#execlastid "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the number generated by the database from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: InsertAuthor :execlastid INSERT INTO authors (name) VALUES (?); func (q \*Queries) InsertAuthor(ctx context.Context, name string) (int64, error) { \_, err := q.db.ExecContext(ctx, insertAuthor, name) // ... } `:many`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#many "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return a slice of records via [QueryContext](https://golang.org/pkg/database/sql/#DB.QueryContext) . \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) // ... } `:one`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#one "Link to this heading") -------------------------------------------------------------------------------------------------------- The generated method will return a single record via [QueryRowContext](https://golang.org/pkg/database/sql/#DB.QueryRowContext) . \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; func (q \*Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) // ... } `:batchexec`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#batchexec "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Exec`, that takes a `func(int, error)` parameter, * `Close`, to close the batch operation early. \-- name: DeleteBook :batchexec DELETE FROM books WHERE book\_id \= $1; type DeleteBookBatchResults struct { br pgx.BatchResults ind int } func (q \*Queries) DeleteBook(ctx context.Context, bookID \[\]int32) \*DeleteBookBatchResults { //... } func (b \*DeleteBookBatchResults) Exec(f func(int, error)) { //... } func (b \*DeleteBookBatchResults) Close() error { //... } `:batchmany`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#batchmany "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Query`, that takes a `func(int, []T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: BooksByTitleYear :batchmany SELECT \* FROM books WHERE title \= $1 AND year \= $2; type BooksByTitleYearBatchResults struct { br pgx.BatchResults ind int } type BooksByTitleYearParams struct { Title string \`json:"title"\` Year int32 \`json:"year"\` } func (q \*Queries) BooksByTitleYear(ctx context.Context, arg \[\]BooksByTitleYearParams) \*BooksByTitleYearBatchResults { //... } func (b \*BooksByTitleYearBatchResults) Query(f func(int, \[\]Book, error)) { //... } func (b \*BooksByTitleYearBatchResults) Close() error { //... } `:batchone`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#batchone "Link to this heading") ------------------------------------------------------------------------------------------------------------------ **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `QueryRow`, that takes a `func(int, T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: CreateBook :batchone INSERT INTO books ( author\_id, isbn ) VALUES ( $1, $2 ) RETURNING book\_id, author\_id, isbn type CreateBookBatchResults struct { br pgx.BatchResults ind int } type CreateBookParams struct { AuthorID int32 \`json:"author\_id"\` Isbn string \`json:"isbn"\` } func (q \*Queries) CreateBook(ctx context.Context, arg \[\]CreateBookParams) \*CreateBookBatchResults { //... } func (b \*CreateBookBatchResults) QueryRow(f func(int, Book, error)) { //... } func (b \*CreateBookBatchResults) Close() error { //... } `:copyfrom`[](https://docs.sqlc.dev/en/v1.31.0/reference/query-annotations.html#copyfrom "Link to this heading") ------------------------------------------------------------------------------------------------------------------ \_\_NOTE: This command is driver and package specific, see [how to insert](https://docs.sqlc.dev/en/v1.31.0/howto/insert.html#using-copyfrom) This command is used to insert rows a lot faster than sequential inserts. --- # Overriding types — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Overriding types * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/overrides.md.txt) * * * Overriding types[](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html#overriding-types "Link to this heading") =================================================================================================================== Note Type overrides and field renaming are only fully-supported for Go. In many cases it’s useful to tell `sqlc` explicitly what Go type you want it to use for a query input or output. For instance, by default when you use `pgx/v5`, `sqlc` will map a PostgreSQL UUID type to `UUID` from `github.com/jackc/pgx/pgtype`. But you may want `sqlc` to use `UUID` from `github.com/google/uuid` instead. To tell `sqlc` to use a different Go type, add an entry to the `overrides` list in your configuration. `sqlc` offers two kinds of Go type overrides: * `db_type` overrides, which override the Go type for a specific database type. * `column` overrides, which override the Go type for a column or columns by name. Here’s an example including one of each kind: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" nullable: true go\_type: import: "github.com/google/uuid" type: "UUID" \- column: "users.birthday" go\_type: "time.Time" Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. The `overrides` list[](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html#the-overrides-list "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- Each element in the `overrides` list has the following keys: * `db_type`: * A database type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use pg\_catalog-prefixed names where available. `db_type` and `column` are mutually exclusive. * `column`: * A column name to override. The value should be of the form `table.column` but you can also specify `schema.table.column` or `catalog.schema.table.column`. `column` and `db_type` are mutually exclusive. * `go_type`: * The fully-qualified name of a Go type to use in generated code. This is usually a string but can also be [a map](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html#the-go-type-map) for more complex configurations. * `go_struct_tag`: * A reflect-style struct tag to use in generated code, e.g. `a:"b" x:"y,z"`. If you want `json` or `db` tags for all fields, configure `emit_json_tags` or `emit_db_tags` instead. * `unsigned`: * If `true`, sqlc will apply this override when a numeric column is unsigned. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. * `nullable`: * If `true`, sqlc will apply this override when a column is nullable. Otherwise `sqlc` will apply this override when a column is non-nullable. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. Note When generating code, `column` override configurations take precedence over `db_type` configurations. ### The `go_type` map[](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html#the-go-type-map "Link to this heading") Some overrides may require more detailed configuration. If necessary, `go_type` can be a map with the following keys: * `import`: * The import path for the package where the type is defined. * `package`: * The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name. * `type`: * The type name itself, without any package prefix. * `pointer`: * If `true`, generated code will use a pointer to the type rather than the type itself. * `slice`: * If `true`, generated code will use a slice of the type rather than the type itself. An example: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" go\_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true Global overrides[](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html#global-overrides "Link to this heading") ------------------------------------------------------------------------------------------------------------------- To override types in all packages that `sqlc` generates, add an override configuration to the top-level `overrides` section of your `sqlc` config: version: "2" overrides: go: overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "service1/schema.sql" queries: "service1/query.sql" engine: "postgresql" gen: go: package: "service1" out: "service1" \- schema: "service2/schema.sql" queries: "service2/query.sql" engine: "postgresql" gen: go: package: "service2" out: "service2" Using this configuration, whenever there is a nullable `timestamp with time zone` column in a Postgres table, `sqlc` will generate Go code using `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in per-package type overrides. This field is only used when there are multiple `sql` sections using different engines. If you’re only generating code for a single database engine you can omit it. ### Version 1 configuration[](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html#version-1-configuration "Link to this heading") If you are using the older version 1 of the `sqlc` configuration format, override configurations themselves are unchanged but are nested differently. Per-package configurations are nested under the `overrides` key within an item in the `packages` list: version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" overrides: \[...\] And global configurations are nested under the top-level `overrides` key: version: "1" packages: \[...\] overrides: \- db\_type: "uuid" go\_type: "github.com/gofrs/uuid.UUID" --- # Query annotations — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Query annotations * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/query-annotations.md.txt) * * * Query annotations[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#query-annotations "Link to this heading") ================================================================================================================================= sqlc requires each query to have a small comment indicating the name and command. The format of this comment is as follows: \-- name: `:exec`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#exec "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return the error from [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; func (q \*Queries) DeleteAuthor(ctx context.Context, id int64) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } `:execresult`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#execresult "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the [sql.Result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execresult DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (sql.Result, error) { return q.db.ExecContext(ctx, deleteAllAuthors) } `:execrows`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#execrows "Link to this heading") ------------------------------------------------------------------------------------------------------------------ The generated method will return the number of affected rows from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execrows DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (int64, error) { \_, err := q.db.ExecContext(ctx, deleteAllAuthors) // ... } `:execlastid`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#execlastid "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the number generated by the database from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: InsertAuthor :execlastid INSERT INTO authors (name) VALUES (?); func (q \*Queries) InsertAuthor(ctx context.Context, name string) (int64, error) { \_, err := q.db.ExecContext(ctx, insertAuthor, name) // ... } `:many`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#many "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return a slice of records via [QueryContext](https://golang.org/pkg/database/sql/#DB.QueryContext) . \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) // ... } `:one`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#one "Link to this heading") -------------------------------------------------------------------------------------------------------- The generated method will return a single record via [QueryRowContext](https://golang.org/pkg/database/sql/#DB.QueryRowContext) . \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; func (q \*Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) // ... } `:batchexec`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#batchexec "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Exec`, that takes a `func(int, error)` parameter, * `Close`, to close the batch operation early. \-- name: DeleteBook :batchexec DELETE FROM books WHERE book\_id \= $1; type DeleteBookBatchResults struct { br pgx.BatchResults ind int } func (q \*Queries) DeleteBook(ctx context.Context, bookID \[\]int32) \*DeleteBookBatchResults { //... } func (b \*DeleteBookBatchResults) Exec(f func(int, error)) { //... } func (b \*DeleteBookBatchResults) Close() error { //... } `:batchmany`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#batchmany "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Query`, that takes a `func(int, []T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: BooksByTitleYear :batchmany SELECT \* FROM books WHERE title \= $1 AND year \= $2; type BooksByTitleYearBatchResults struct { br pgx.BatchResults ind int } type BooksByTitleYearParams struct { Title string \`json:"title"\` Year int32 \`json:"year"\` } func (q \*Queries) BooksByTitleYear(ctx context.Context, arg \[\]BooksByTitleYearParams) \*BooksByTitleYearBatchResults { //... } func (b \*BooksByTitleYearBatchResults) Query(f func(int, \[\]Book, error)) { //... } func (b \*BooksByTitleYearBatchResults) Close() error { //... } `:batchone`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#batchone "Link to this heading") ------------------------------------------------------------------------------------------------------------------ **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `QueryRow`, that takes a `func(int, T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: CreateBook :batchone INSERT INTO books ( author\_id, isbn ) VALUES ( $1, $2 ) RETURNING book\_id, author\_id, isbn type CreateBookBatchResults struct { br pgx.BatchResults ind int } type CreateBookParams struct { AuthorID int32 \`json:"author\_id"\` Isbn string \`json:"isbn"\` } func (q \*Queries) CreateBook(ctx context.Context, arg \[\]CreateBookParams) \*CreateBookBatchResults { //... } func (b \*CreateBookBatchResults) QueryRow(f func(int, Book, error)) { //... } func (b \*CreateBookBatchResults) Close() error { //... } `:copyfrom`[](https://docs.sqlc.dev/en/v1.31.1/reference/query-annotations.html#copyfrom "Link to this heading") ------------------------------------------------------------------------------------------------------------------ \_\_NOTE: This command is driver and package specific, see [how to insert](https://docs.sqlc.dev/en/v1.31.1/howto/insert.html#using-copyfrom) This command is used to insert rows a lot faster than sequential inserts. --- # Getting started with MySQL — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Getting started with MySQL * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/tutorials/getting-started-mysql.md.txt) * * * Getting started with MySQL[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-mysql.html#getting-started-with-mysql "Link to this heading") ======================================================================================================================================================= This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.30.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.30.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-mysql.html#setting-up "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-mysql.html#schema-and-queries "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGINT NOT NULL AUTO\_INCREMENT PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following four queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :execresult INSERT INTO authors ( name, bio ) VALUES ( ?, ? ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; Generating code[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-mysql.html#generating-code "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-mysql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" "log" "reflect" \_ "github.com/go-sql-driver/mysql" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() db, err := sql.Open("mysql", "user:password@/dbname?parseTime=true") if err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant MySQL driver: go get github.com/go-sql-driver/mysql go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `sql.Open()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-mysql.html#query-verification "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial --- # Overriding types — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Overriding types * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/overrides.md.txt) * * * Overriding types[](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html#overriding-types "Link to this heading") =================================================================================================================== Note Type overrides and field renaming are only fully-supported for Go. In many cases it’s useful to tell `sqlc` explicitly what Go type you want it to use for a query input or output. For instance, by default when you use `pgx/v5`, `sqlc` will map a PostgreSQL UUID type to `UUID` from `github.com/jackc/pgx/pgtype`. But you may want `sqlc` to use `UUID` from `github.com/google/uuid` instead. To tell `sqlc` to use a different Go type, add an entry to the `overrides` list in your configuration. `sqlc` offers two kinds of Go type overrides: * `db_type` overrides, which override the Go type for a specific database type. * `column` overrides, which override the Go type for a column or columns by name. Here’s an example including one of each kind: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" nullable: true go\_type: import: "github.com/google/uuid" type: "UUID" \- column: "users.birthday" go\_type: "time.Time" Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. The `overrides` list[](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html#the-overrides-list "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- Each element in the `overrides` list has the following keys: * `db_type`: * A database type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use pg\_catalog-prefixed names where available. `db_type` and `column` are mutually exclusive. * `column`: * A column name to override. The value should be of the form `table.column` but you can also specify `schema.table.column` or `catalog.schema.table.column`. `column` and `db_type` are mutually exclusive. * `go_type`: * The fully-qualified name of a Go type to use in generated code. This is usually a string but can also be [a map](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html#the-go-type-map) for more complex configurations. * `go_struct_tag`: * A reflect-style struct tag to use in generated code, e.g. `a:"b" x:"y,z"`. If you want `json` or `db` tags for all fields, configure `emit_json_tags` or `emit_db_tags` instead. * `unsigned`: * If `true`, sqlc will apply this override when a numeric column is unsigned. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. * `nullable`: * If `true`, sqlc will apply this override when a column is nullable. Otherwise `sqlc` will apply this override when a column is non-nullable. Note that this only applies to `db_type` overrides and has no effect on `column` overrides. Defaults to `false`. Tip A single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want the same Go type to override regardless of nullability, you’ll need to configure two overrides: one with `nullable: true` and one without. Note When generating code, `column` override configurations take precedence over `db_type` configurations. ### The `go_type` map[](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html#the-go-type-map "Link to this heading") Some overrides may require more detailed configuration. If necessary, `go_type` can be a map with the following keys: * `import`: * The import path for the package where the type is defined. * `package`: * The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name. * `type`: * The type name itself, without any package prefix. * `pointer`: * If `true`, generated code will use a pointer to the type rather than the type itself. * `slice`: * If `true`, generated code will use a slice of the type rather than the type itself. An example: version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql\_package: "pgx/v5" overrides: \- db\_type: "uuid" go\_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true Global overrides[](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html#global-overrides "Link to this heading") ------------------------------------------------------------------------------------------------------------------- To override types in all packages that `sqlc` generates, add an override configuration to the top-level `overrides` section of your `sqlc` config: version: "2" overrides: go: overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "service1/schema.sql" queries: "service1/query.sql" engine: "postgresql" gen: go: package: "service1" out: "service1" \- schema: "service2/schema.sql" queries: "service2/query.sql" engine: "postgresql" gen: go: package: "service2" out: "service2" Using this configuration, whenever there is a nullable `timestamp with time zone` column in a Postgres table, `sqlc` will generate Go code using `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in per-package type overrides. This field is only used when there are multiple `sql` sections using different engines. If you’re only generating code for a single database engine you can omit it. ### Version 1 configuration[](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html#version-1-configuration "Link to this heading") If you are using the older version 1 of the `sqlc` configuration format, override configurations themselves are unchanged but are nested differently. Per-package configurations are nested under the `overrides` key within an item in the `packages` list: version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" overrides: \[...\] And global configurations are nested under the top-level `overrides` key: version: "1" packages: \[...\] overrides: \- db\_type: "uuid" go\_type: "github.com/gofrs/uuid.UUID" --- # Getting started with MySQL — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/index.html) * Getting started with MySQL * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/tutorials/getting-started-mysql.md.txt) * * * Getting started with MySQL[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-mysql.html#getting-started-with-mysql "Link to this heading") ======================================================================================================================================================= This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.29.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.29.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-mysql.html#setting-up "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-mysql.html#schema-and-queries "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGINT NOT NULL AUTO\_INCREMENT PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following four queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :execresult INSERT INTO authors ( name, bio ) VALUES ( ?, ? ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; Generating code[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-mysql.html#generating-code "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-mysql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" "log" "reflect" \_ "github.com/go-sql-driver/mysql" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() db, err := sql.Open("mysql", "user:password@/dbname?parseTime=true") if err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant MySQL driver: go get github.com/go-sql-driver/mysql go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `sql.Open()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-mysql.html#query-verification "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial --- # Macros — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Macros * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/macros.md.txt) * * * Macros[](https://docs.sqlc.dev/en/v1.30.0/reference/macros.html#macros "Link to this heading") ================================================================================================ `sqlc.arg`[](https://docs.sqlc.dev/en/v1.30.0/reference/macros.html#sqlc-arg "Link to this heading") ------------------------------------------------------------------------------------------------------ Attach a name to a parameter in a SQL query. This macro expands to an engine-specific parameter placeholder. The name of the parameter is noted and used during code generation. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.arg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.30.0/howto/named_parameters.html) . `sqlc.embed`[](https://docs.sqlc.dev/en/v1.30.0/reference/macros.html#sqlc-embed "Link to this heading") ---------------------------------------------------------------------------------------------------------- Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ); CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ); \-- name: GetStudentAndScore :one SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; \-- >>> EXPANDS TO >>> \-- name: GetStudentAndScore :one SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; The Go method will return a struct with a field for the `Student` and field for the test `TestScore` instead of each column existing on the struct. type GetStudentAndScoreRow struct { Student Student TestScore TestScore } func (q \*Queries) GetStudentAndScore(ctx context.Context, id int64) (GetStudentAndScoreRow, error) { // ... } See a full example in [Embedding structs](https://docs.sqlc.dev/en/v1.30.0/howto/embedding.html) . `sqlc.narg`[](https://docs.sqlc.dev/en/v1.30.0/reference/macros.html#sqlc-narg "Link to this heading") -------------------------------------------------------------------------------------------------------- The same as `sqlc.arg`, but always marks the parameter as nullable. \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE lower(name) \= sqlc.narg(name); \-- >>> EXPANDS TO >>> \-- name: GetAuthorByName :one SELECT \* FROM authors WHERE LOWER(name) \= ?; See more examples in [Naming parameters](https://docs.sqlc.dev/en/v1.30.0/howto/named_parameters.html) . `sqlc.slice`[](https://docs.sqlc.dev/en/v1.30.0/reference/macros.html#sqlc-slice "Link to this heading") ---------------------------------------------------------------------------------------------------------- For drivers that do not support passing slices to the IN operator, the `sqlc.slice` macro generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) \-- >>> EXPANDS TO >>> /\* name: SelectStudents :many \*/ SELECT id, name, age FROM authors WHERE age IN (/\*SLICE:ages\*/?) Since the `/*SLICE:ages*/` placeholder is dynamically replaced on a per-query basis, this macro can’t be used with prepared statements. See a full example in [Passing a slice as a parameter to a query](https://docs.sqlc.dev/en/v1.30.0/howto/select.html#mysql-and-sqlite) . --- # Inserting rows — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Inserting rows * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/insert.md.txt) * * * Inserting rows[](https://docs.sqlc.dev/en/v1.30.0/howto/insert.html#inserting-rows "Link to this heading") ============================================================================================================ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1); **MySQL and SQLite:** \-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES (?); package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const createAuthor \= \`-- name: CreateAuthor :exec INSERT INTO authors (bio) VALUES ($1) \` func (q \*Queries) CreateAuthor(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, createAuthor, bio) return err } Returning columns from inserted rows[](https://docs.sqlc.dev/en/v1.30.0/howto/insert.html#returning-columns-from-inserted-rows "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------- sqlc has full support for the `RETURNING` statement. \-- Example queries for sqlc CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); **PostgreSQL:** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id; **SQLite (with RETURNING support):** \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING id; Note: MySQL does not support the `RETURNING` clause. Use `:execresult` instead to get the last insert ID. package db import ( "context" "database/sql" ) const createAuthor \= \`-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id, name, bio \` type CreateAuthorParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) var i Author err := row.Scan(&i.ID, &i.Name, &i.Bio) return i, err } const createAuthorAndReturnId \= \`-- name: CreateAuthorAndReturnId :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING id \` type CreateAuthorAndReturnIdParams struct { Name string Bio sql.NullString } func (q \*Queries) CreateAuthorAndReturnId(ctx context.Context, arg CreateAuthorAndReturnIdParams) (int64, error) { row := q.db.QueryRowContext(ctx, createAuthorAndReturnId, arg.Name, arg.Bio) var id int64 err := row.Scan(&id) return id, err } Using CopyFrom[](https://docs.sqlc.dev/en/v1.30.0/howto/insert.html#using-copyfrom "Link to this heading") ------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.30.0/howto/insert.html#postgresql "Link to this heading") PostgreSQL supports the [COPY protocol](https://www.postgresql.org/docs/current/sql-copy.html) that can insert rows a lot faster than sequential inserts. You can use this easily with sqlc: CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text NOT NULL ); \-- name: CreateAuthors :copyfrom INSERT INTO authors (name, bio) VALUES ($1, $2); type CreateAuthorsParams struct { Name string Bio string } func (q \*Queries) CreateAuthors(ctx context.Context, arg \[\]CreateAuthorsParams) (int64, error) { ... } The `:copyfrom` command requires either `pgx/v4` or `pgx/v5`. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" ### MySQL[](https://docs.sqlc.dev/en/v1.30.0/howto/insert.html#mysql "Link to this heading") MySQL supports a similar feature using [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) . Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use SHOW WARNINGS to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } The `:copyfrom` command requires setting the `sql_package` and `sql_driver` options. version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "database/sql" sql\_driver: "github.com/go-sql-driver/mysql" out: "db" --- # Getting started with SQLite — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/index.html) * Getting started with SQLite * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/tutorials/getting-started-sqlite.md.txt) * * * Getting started with SQLite[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-sqlite.html#getting-started-with-sqlite "Link to this heading") ========================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.29.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.29.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. Setting up[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-sqlite.html#setting-up "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "sqlite" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-sqlite.html#schema-and-queries "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id INTEGER PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( ?, ? ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= ?, bio \= ? WHERE id \= ?; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= ?, bio \= ? WHERE id \= ? RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-sqlite.html#generating-code "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-sqlite.html#using-generated-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" \_ "embed" "log" "reflect" \_ "modernc.org/sqlite" "tutorial.sqlc.dev/app/tutorial" ) //go:embed schema.sql var ddl string func run() error { ctx := context.Background() db, err := sql.Open("sqlite", ":memory:") if err != nil { return err } // create tables if \_, err := db.ExecContext(ctx, ddl); err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant SQLite driver: go get modernc.org/sqlite go build ./... The program should compile without errors, and run successfully. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. --- # Getting started with PostgreSQL — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Getting started with PostgreSQL * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/tutorials/getting-started-postgresql.md) * * * Getting started with PostgreSQL[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-postgresql.html#getting-started-with-postgresql "Link to this heading") ====================================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.27.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.27.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-postgresql.html#setting-up "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app`: go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Schema and queries[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-postgresql.html#schema-and-queries "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1 RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-postgresql.html#generating-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-postgresql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------ You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "log" "reflect" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() conn, err := pgx.Connect(ctx, "user=pqgotest dbname=pqgotest sslmode=verify-full") if err != nil { return err } defer conn.Close(ctx) queries := tutorial.New(conn) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant PostgreSQL driver. You can use `lib/pq` with the standard library’s `database/sql` package, but in this tutorial we’ve used `pgx/v5`: go get github.com/jackc/pgx/v5 go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `pgx.Connect()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-postgresql.html#query-verification "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial In the sidebar, go to the “Queries” section to see your published queries. Run `verify` to ensure that previously published queries continue to work against updated database schema. $ sqlc verify \--against tutorial --- # Getting started with MySQL — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Getting started with MySQL * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/tutorials/getting-started-mysql.md) * * * Getting started with MySQL[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-mysql.html#getting-started-with-mysql "Link to this heading") ======================================================================================================================================================= This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.27.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.27.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-mysql.html#setting-up "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Schema and queries[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-mysql.html#schema-and-queries "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGINT NOT NULL AUTO\_INCREMENT PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following four queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ? LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :execresult INSERT INTO authors ( name, bio ) VALUES ( ?, ? ); \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; Generating code[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-mysql.html#generating-code "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-mysql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "database/sql" "log" "reflect" \_ "github.com/go-sql-driver/mysql" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() db, err := sql.Open("mysql", "user:password@/dbname?parseTime=true") if err != nil { return err } queries := tutorial.New(db) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } insertedAuthorID, err := result.LastInsertId() if err != nil { return err } log.Println(insertedAuthorID) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant MySQL driver: go get github.com/go-sql-driver/mysql go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `sql.Open()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.27.0/tutorials/getting-started-mysql.html#query-verification "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "mysql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial --- # Environment variables — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Environment variables * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/environment-variables.md) * * * Environment variables[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#environment-variables "Link to this heading") ============================================================================================================================================= SQLCCACHE[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#sqlccache "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCCACHE` environment variable dictates where `sqlc` will store cached WASM-based plugins and modules. By default `sqlc` follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) . SQLCDEBUG[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#sqlcdebug "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCDEBUG` variable controls debugging variables within the runtime. It is a comma-separated list of name=val pairs settings. ### dumpast[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#dumpast "Link to this heading") The `dumpast` command shows the SQL AST that was generated by the parser. Note that this is the generic SQL AST, not the engine-specific SQL AST. SQLCDEBUG\=dumpast\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc0004f48c0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc0004f4930)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc00052ff20)({ Rel: (\*ast.TableName)(0xc00052fda0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### dumpcatalog[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#dumpcatalog "Link to this heading") The `dumpcatalog` command outputs the entire catalog. If you’re using MySQL or PostgreSQL, this can be a bit overwhelming. Expect this output to change in future versions. SQLCDEBUG\=dumpcatalog\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc00050d1f0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc00050d260)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc0000c0840)({ Rel: (\*ast.TableName)(0xc0000c06c0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### trace[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#trace "Link to this heading") The `trace` command is helpful for tracking down performance issues. `SQLCDEBUG=trace=1` By default, the trace output is written to `trace.out` in the current working directory. You can configure a different path if needed. `SQLCDEBUG=trace=name.out` View the execution trace using the Go `trace` tool. go tool trace trace.out There’s a ton of different views for the trace output, but here’s an example log showing the execution time for each package. 0.000043897 . 1 task sqlc (id 1, parent 0) created 0.000144923 . 101026 1 region generate started (duration: 47.619781ms) 0.001048975 . 904052 1 region package started (duration: 14.588456ms) 0.001054616 . 5641 1 name\=authors dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.001071257 . 16641 1 region parse started (duration: 7.966549ms) 0.009043960 . 7972703 1 region codegen started (duration: 6.587086ms) 0.009171704 . 127744 1 new goroutine 35: text/template/parse.lex·dwrap·1 0.010361654 . 1189950 1 new goroutine 36: text/template/parse.lex·dwrap·1 0.015641815 . 5280161 1 region package started (duration: 10.904938ms) 0.015644943 . 3128 1 name\=booktest dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.015647431 . 2488 1 region parse started (duration: 4.207749ms) 0.019860308 . 4212877 1 region codegen started (duration: 6.681624ms) 0.020028488 . 168180 1 new goroutine 37: text/template/parse.lex·dwrap·1 0.021020310 . 991822 1 new goroutine 8: text/template/parse.lex·dwrap·1 0.026551163 . 5530853 1 region package started (duration: 9.217294ms) 0.026554368 . 3205 1 name\=jets dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.026556804 . 2436 1 region parse started (duration: 3.491005ms) 0.030051911 . 3495107 1 region codegen started (duration: 5.711931ms) 0.030213937 . 162026 1 new goroutine 20: text/template/parse.lex·dwrap·1 0.031099938 . 886001 1 new goroutine 38: text/template/parse.lex·dwrap·1 0.035772637 . 4672699 1 region package started (duration: 10.267039ms) 0.035775688 . 3051 1 name\=ondeck dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.035778150 . 2462 1 region parse started (duration: 4.094518ms) 0.039877181 . 4099031 1 region codegen started (duration: 6.156341ms) 0.040010771 . 133590 1 new goroutine 39: text/template/parse.lex·dwrap·1 0.040894567 . 883796 1 new goroutine 40: text/template/parse.lex·dwrap·1 0.046042779 . 5148212 1 region writefiles started (duration: 1.718259ms) 0.047767781 . 1725002 1 task end ### processplugins[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#processplugins "Link to this heading") Setting this value to `0` disables process-based plugins. If a process-based plugin is declared in the configuration file, running any `sqlc` command will return an error. `SQLCDEBUG=processplugins=0` ### dumpvetenv[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#dumpvetenv "Link to this heading") The `dumpvetenv` command prints the variables available to a `sqlc vet` rule during evaluation. `SQLCDEBUG=dumpvetenv=1` ### dumpexplain[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#dumpexplain "Link to this heading") The `dumpexplain` command prints the JSON-formatted result from running `EXPLAIN ...` on a query when a `sqlc vet` rule evaluation requires its output. `SQLCDEBUG=dumpexplain=1` SQLCTMPDIR[](https://docs.sqlc.dev/en/v1.27.0/reference/environment-variables.html#sqlctmpdir "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- If specified, use the given directory as the base for temporary folders. Only applies when using WASM-based codegen plugins. When not specified, this defaults to passing an empty string to [`os.MkdirTemp`](https://pkg.go.dev/os#MkdirTemp) . --- # Managed databases — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Managed databases * [View page source](https://docs.sqlc.dev/en/latest/_sources/howto/managed-databases.md.txt) * * * Managed databases[](https://docs.sqlc.dev/en/latest/howto/managed-databases.html#managed-databases "Link to this heading") ============================================================================================================================ _Added in v1.22.0_ `sqlc` can automatically create read-only databases to power query analysis, linting and verification. These databases are immediately useful for powering sqlc’s database-connected query analyzer, an opt-in feature that improves upon sqlc’s built-in query analysis engine. PostgreSQL support is available today, with MySQL on the way. Once configured, `sqlc` will also use managed databases when linting queries with [`sqlc vet`](https://docs.sqlc.dev/en/latest/howto/vet.html) in cases where your lint rules require a connection to a running database. Managed databases are under active development, and we’re interested in supporting other use-cases. Configuring managed databases[](https://docs.sqlc.dev/en/latest/howto/managed-databases.html#configuring-managed-databases "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------- To configure `sqlc` to use managed databases, remove the `uri` key from your `database` configuration and replace it with the `managed` key set to `true`. Access to a running database server is required. Add a connection string to the `servers` mapping. version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true An environment variable can also be used via the `${}` syntax. version: '2' servers: \- engine: postgresql uri: ${DATABASE\_URI} sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true Improving codegen[](https://docs.sqlc.dev/en/latest/howto/managed-databases.html#improving-codegen "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- Without a database connection, sqlc does its best to parse, analyze and compile your queries just using the schema you pass it and what it knows about the various database engines it supports. In many cases this works just fine, but for more advanced queries sqlc might not have enough information to produce good code. With managed databases configured, `sqlc generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future codegen runs. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true gen: go: out: "db" Linting queries[](https://docs.sqlc.dev/en/latest/howto/managed-databases.html#linting-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ With managed databases configured, `sqlc vet` will automatically create a hosted ephemeral database with your schema and use that database when running lint rules that require a database connection, e.g. any [rule relying on `EXPLAIN ...` output](https://docs.sqlc.dev/en/latest/howto/vet.html#rules-using-explain-output) . If you don’t yet have any vet rules, the [built-in sqlc/db-prepare rule](https://docs.sqlc.dev/en/latest/howto/vet.html#sqlc-db-prepare) is a good place to start. It prepares each of your queries against the database to ensure the query is valid. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true rules: \- sqlc/db-prepare --- # Managed databases — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Managed databases * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/managed-databases.md.txt) * * * Managed databases[](https://docs.sqlc.dev/en/stable/howto/managed-databases.html#managed-databases "Link to this heading") ============================================================================================================================ _Added in v1.22.0_ `sqlc` can automatically create read-only databases to power query analysis, linting and verification. These databases are immediately useful for powering sqlc’s database-connected query analyzer, an opt-in feature that improves upon sqlc’s built-in query analysis engine. PostgreSQL support is available today, with MySQL on the way. Once configured, `sqlc` will also use managed databases when linting queries with [`sqlc vet`](https://docs.sqlc.dev/en/stable/howto/vet.html) in cases where your lint rules require a connection to a running database. Managed databases are under active development, and we’re interested in supporting other use-cases. Configuring managed databases[](https://docs.sqlc.dev/en/stable/howto/managed-databases.html#configuring-managed-databases "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------- To configure `sqlc` to use managed databases, remove the `uri` key from your `database` configuration and replace it with the `managed` key set to `true`. Access to a running database server is required. Add a connection string to the `servers` mapping. version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true An environment variable can also be used via the `${}` syntax. version: '2' servers: \- engine: postgresql uri: ${DATABASE\_URI} sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true Improving codegen[](https://docs.sqlc.dev/en/stable/howto/managed-databases.html#improving-codegen "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- Without a database connection, sqlc does its best to parse, analyze and compile your queries just using the schema you pass it and what it knows about the various database engines it supports. In many cases this works just fine, but for more advanced queries sqlc might not have enough information to produce good code. With managed databases configured, `sqlc generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future codegen runs. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true gen: go: out: "db" Linting queries[](https://docs.sqlc.dev/en/stable/howto/managed-databases.html#linting-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ With managed databases configured, `sqlc vet` will automatically create a hosted ephemeral database with your schema and use that database when running lint rules that require a database connection, e.g. any [rule relying on `EXPLAIN ...` output](https://docs.sqlc.dev/en/stable/howto/vet.html#rules-using-explain-output) . If you don’t yet have any vet rules, the [built-in sqlc/db-prepare rule](https://docs.sqlc.dev/en/stable/howto/vet.html#sqlc-db-prepare) is a good place to start. It prepares each of your queries against the database to ensure the query is valid. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true rules: \- sqlc/db-prepare --- # Database and language support — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Database and language support * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/language-support.rst.txt) * * * Database and language support[](https://docs.sqlc.dev/en/stable/reference/language-support.html#database-and-language-support "Link to this heading") ======================================================================================================================================================= | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Go | (built-in) | Stable | Stable | Beta | | Go | [sqlc-gen-go](https://github.com/sqlc-dev/sqlc-gen-go) | Stable | Stable | Beta | | Kotlin | [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) | Beta | Beta | Not implemented | | Python | [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) | Beta | Beta | Not implemented | | TypeScript | [sqlc-gen-typescript](https://github.com/sqlc-dev/sqlc-gen-typescript) | Beta | Beta | Not implemented | Community language support[](https://docs.sqlc.dev/en/stable/reference/language-support.html#community-language-support "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------- New languages can be added via [plugins](https://docs.sqlc.dev/en/stable/guides/plugins.html) . | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | C# | [DaredevilOSS/sqlc-gen-csharp](https://github.com/DaredevilOSS/sqlc-gen-csharp) | Stable | Stable | Stable | | F# | [kaashyapan/sqlc-gen-fsharp](https://github.com/kaashyapan/sqlc-gen-fsharp) | N/A | Beta | Beta | | Java | [tandemdude/sqlc-gen-java](https://github.com/tandemdude/sqlc-gen-java) | Beta | Beta | N/A | | PHP | [lcarilla/sqlc-plugin-php-dbal](https://github.com/lcarilla/sqlc-plugin-php-dbal) | Beta | N/A | N/A | | Ruby | [DaredevilOSS/sqlc-gen-ruby](https://github.com/DaredevilOSS/sqlc-gen-ruby) | Beta | Beta | Beta | | Zig | [tinyzimmer/sqlc-gen-zig](https://github.com/tinyzimmer/sqlc-gen-zig) | N/A | Beta | Beta | | Python | [rayakame/sqlc-gen-better-python](https://github.com/rayakame/sqlc-gen-better-python) | N/A | Beta | Beta | | Rust | [mathematic-inc/sqlc-gen-sqlx](https://github.com/mathematic-inc/sqlc-gen-sqlx) | N/A | Beta | N/A | | \[Any\] | [fdietze/sqlc-gen-from-template](https://github.com/fdietze/sqlc-gen-from-template) | Stable | Stable | Stable | Plugins developed by our Community can also be found using our [github topic](https://github.com/topics/sqlc-plugin) . Community projects[](https://docs.sqlc.dev/en/stable/reference/language-support.html#community-projects "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- | Language | Project | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Gleam | [daniellionel01/parrot](https://github.com/daniellionel01/parrot) | Stable | Stable | Stable | --- # Managed databases — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Managed databases * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/managed-databases.md.txt) * * * Managed databases[](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html#managed-databases "Link to this heading") ============================================================================================================================= _Added in v1.22.0_ `sqlc` can automatically create read-only databases to power query analysis, linting and verification. These databases are immediately useful for powering sqlc’s database-connected query analyzer, an opt-in feature that improves upon sqlc’s built-in query analysis engine. PostgreSQL support is available today, with MySQL on the way. Once configured, `sqlc` will also use managed databases when linting queries with [`sqlc vet`](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html) in cases where your lint rules require a connection to a running database. Managed databases are under active development, and we’re interested in supporting other use-cases. Configuring managed databases[](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html#configuring-managed-databases "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------- To configure `sqlc` to use managed databases, remove the `uri` key from your `database` configuration and replace it with the `managed` key set to `true`. Access to a running database server is required. Add a connection string to the `servers` mapping. version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true An environment variable can also be used via the `${}` syntax. version: '2' servers: \- engine: postgresql uri: ${DATABASE\_URI} sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true Improving codegen[](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html#improving-codegen "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------- Without a database connection, sqlc does its best to parse, analyze and compile your queries just using the schema you pass it and what it knows about the various database engines it supports. In many cases this works just fine, but for more advanced queries sqlc might not have enough information to produce good code. With managed databases configured, `sqlc generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future codegen runs. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true gen: go: out: "db" Linting queries[](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html#linting-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- With managed databases configured, `sqlc vet` will automatically create a hosted ephemeral database with your schema and use that database when running lint rules that require a database connection, e.g. any [rule relying on `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#rules-using-explain-output) . If you don’t yet have any vet rules, the [built-in sqlc/db-prepare rule](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#sqlc-db-prepare) is a good place to start. It prepares each of your queries against the database to ensure the query is valid. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true rules: \- sqlc/db-prepare --- # Database and language support — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Database and language support * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/language-support.rst.txt) * * * Database and language support[](https://docs.sqlc.dev/en/v1.31.0/reference/language-support.html#database-and-language-support "Link to this heading") ======================================================================================================================================================== | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Go | (built-in) | Stable | Stable | Beta | | Go | [sqlc-gen-go](https://github.com/sqlc-dev/sqlc-gen-go) | Stable | Stable | Beta | | Kotlin | [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) | Beta | Beta | Not implemented | | Python | [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) | Beta | Beta | Not implemented | | TypeScript | [sqlc-gen-typescript](https://github.com/sqlc-dev/sqlc-gen-typescript) | Beta | Beta | Not implemented | Community language support[](https://docs.sqlc.dev/en/v1.31.0/reference/language-support.html#community-language-support "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------- New languages can be added via [plugins](https://docs.sqlc.dev/en/v1.31.0/guides/plugins.html) . | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | C# | [DaredevilOSS/sqlc-gen-csharp](https://github.com/DaredevilOSS/sqlc-gen-csharp) | Stable | Stable | Stable | | F# | [kaashyapan/sqlc-gen-fsharp](https://github.com/kaashyapan/sqlc-gen-fsharp) | N/A | Beta | Beta | | Java | [tandemdude/sqlc-gen-java](https://github.com/tandemdude/sqlc-gen-java) | Beta | Beta | N/A | | PHP | [lcarilla/sqlc-plugin-php-dbal](https://github.com/lcarilla/sqlc-plugin-php-dbal) | Beta | N/A | N/A | | Ruby | [DaredevilOSS/sqlc-gen-ruby](https://github.com/DaredevilOSS/sqlc-gen-ruby) | Beta | Beta | Beta | | Zig | [tinyzimmer/sqlc-gen-zig](https://github.com/tinyzimmer/sqlc-gen-zig) | N/A | Beta | Beta | | Python | [rayakame/sqlc-gen-better-python](https://github.com/rayakame/sqlc-gen-better-python) | N/A | Beta | Beta | | Rust | [mathematic-inc/sqlc-gen-sqlx](https://github.com/mathematic-inc/sqlc-gen-sqlx) | N/A | Beta | N/A | | \[Any\] | [fdietze/sqlc-gen-from-template](https://github.com/fdietze/sqlc-gen-from-template) | Stable | Stable | Stable | Plugins developed by our Community can also be found using our [github topic](https://github.com/topics/sqlc-plugin) . Community projects[](https://docs.sqlc.dev/en/v1.31.0/reference/language-support.html#community-projects "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- | Language | Project | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Gleam | [daniellionel01/parrot](https://github.com/daniellionel01/parrot) | Stable | Stable | Stable | --- # Database and language support — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Database and language support * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/language-support.rst.txt) * * * Database and language support[](https://docs.sqlc.dev/en/v1.31.1/reference/language-support.html#database-and-language-support "Link to this heading") ======================================================================================================================================================== | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Go | (built-in) | Stable | Stable | Beta | | Go | [sqlc-gen-go](https://github.com/sqlc-dev/sqlc-gen-go) | Stable | Stable | Beta | | Kotlin | [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) | Beta | Beta | Not implemented | | Python | [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) | Beta | Beta | Not implemented | | TypeScript | [sqlc-gen-typescript](https://github.com/sqlc-dev/sqlc-gen-typescript) | Beta | Beta | Not implemented | Community language support[](https://docs.sqlc.dev/en/v1.31.1/reference/language-support.html#community-language-support "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------- New languages can be added via [plugins](https://docs.sqlc.dev/en/v1.31.1/guides/plugins.html) . | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | C# | [DaredevilOSS/sqlc-gen-csharp](https://github.com/DaredevilOSS/sqlc-gen-csharp) | Stable | Stable | Stable | | F# | [kaashyapan/sqlc-gen-fsharp](https://github.com/kaashyapan/sqlc-gen-fsharp) | N/A | Beta | Beta | | Java | [tandemdude/sqlc-gen-java](https://github.com/tandemdude/sqlc-gen-java) | Beta | Beta | N/A | | PHP | [lcarilla/sqlc-plugin-php-dbal](https://github.com/lcarilla/sqlc-plugin-php-dbal) | Beta | N/A | N/A | | Ruby | [DaredevilOSS/sqlc-gen-ruby](https://github.com/DaredevilOSS/sqlc-gen-ruby) | Beta | Beta | Beta | | Zig | [tinyzimmer/sqlc-gen-zig](https://github.com/tinyzimmer/sqlc-gen-zig) | N/A | Beta | Beta | | Python | [rayakame/sqlc-gen-better-python](https://github.com/rayakame/sqlc-gen-better-python) | N/A | Beta | Beta | | Rust | [mathematic-inc/sqlc-gen-sqlx](https://github.com/mathematic-inc/sqlc-gen-sqlx) | N/A | Beta | N/A | | \[Any\] | [fdietze/sqlc-gen-from-template](https://github.com/fdietze/sqlc-gen-from-template) | Stable | Stable | Stable | Plugins developed by our Community can also be found using our [github topic](https://github.com/topics/sqlc-plugin) . Community projects[](https://docs.sqlc.dev/en/v1.31.1/reference/language-support.html#community-projects "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- | Language | Project | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Gleam | [daniellionel01/parrot](https://github.com/daniellionel01/parrot) | Stable | Stable | Stable | --- # Configuring generated structs — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Configuring generated structs * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/structs.md) * * * Configuring generated structs[](https://docs.sqlc.dev/en/v1.27.0/howto/structs.html#configuring-generated-structs "Link to this heading") =========================================================================================================================================== Naming scheme[](https://docs.sqlc.dev/en/v1.27.0/howto/structs.html#naming-scheme "Link to this heading") ----------------------------------------------------------------------------------------------------------- Structs generated from tables will attempt to use the singular form of a table name if the table name is pluralized. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL ); package db // Struct names use the singular form of table names type Author struct { ID int Name string } JSON tags[](https://docs.sqlc.dev/en/v1.27.0/howto/structs.html#json-tags "Link to this heading") --------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL ); sqlc can generate structs with JSON tags by adding the `emit_json_tags` key to the configuration file as it shows on [configuration reference](https://docs.sqlc.dev/en/v1.27.0/reference/config.html) . The JSON name for a field matches the column name in the database. package db import ( "time" ) type Author struct { ID int \`json:"id"\` CreatedAt time.Time \`json:"created\_at"\` } More control[](https://docs.sqlc.dev/en/v1.27.0/howto/structs.html#more-control "Link to this heading") --------------------------------------------------------------------------------------------------------- See the guide to [Overriding types](https://docs.sqlc.dev/en/v1.27.0/howto/overrides.html) for fine-grained control over struct field types and tags. --- # Preparing queries — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Preparing queries * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/prepared_query.md.txt) * * * Preparing queries[](https://docs.sqlc.dev/en/v1.30.0/howto/prepared_query.html#preparing-queries "Link to this heading") ========================================================================================================================== If you’re using `pgx/v5` you get its [implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching) for prepared statements. No additional `sqlc` configuration is required. For other drivers, `sqlc` can give you the option to explicitly use prepared queries. These prepared queries also work with transactions. You’ll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration to generate code similar to the example below. CREATE TABLE records ( id SERIAL PRIMARY KEY ); \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; package db import ( "context" "database/sql" "fmt" ) type Record struct { ID int32 } type DBTX interface { PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } func Prepare(ctx context.Context, db DBTX) (\*Queries, error) { q := Queries{db: db} var err error if q.getRecordStmt, err \= db.PrepareContext(ctx, getRecord); err != nil { return nil, fmt.Errorf("error preparing query GetRecord: %w", err) } return &q, nil } func (q \*Queries) queryRow(ctx context.Context, stmt \*sql.Stmt, query string, args ...interface{}) \*sql.Row { switch { case stmt != nil && q.tx != nil: return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...) case stmt != nil: return stmt.QueryRowContext(ctx, args...) default: return q.db.QueryRowContext(ctx, query, args...) } } type Queries struct { db DBTX tx \*sql.Tx getRecordStmt \*sql.Stmt } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, tx: tx, getRecordStmt: q.getRecordStmt, } } const getRecord \= \`-- name: GetRecord :one SELECT id FROM records WHERE id = $1 \` func (q \*Queries) GetRecord(ctx context.Context, id int32) (int32, error) { row := q.queryRow(ctx, q.getRecordStmt, getRecord, id) err := row.Scan(&id) return id, err } --- # Installing sqlc — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Installing sqlc * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/overview/install.md.txt) * * * Installing sqlc[](https://docs.sqlc.dev/en/v1.30.0/overview/install.html#installing-sqlc "Link to this heading") ================================================================================================================== sqlc is distributed as a single binary with zero dependencies. macOS[](https://docs.sqlc.dev/en/v1.30.0/overview/install.html#macos "Link to this heading") ---------------------------------------------------------------------------------------------- brew install sqlc Ubuntu[](https://docs.sqlc.dev/en/v1.30.0/overview/install.html#ubuntu "Link to this heading") ------------------------------------------------------------------------------------------------ sudo snap install sqlc go install[](https://docs.sqlc.dev/en/v1.30.0/overview/install.html#go-install "Link to this heading") -------------------------------------------------------------------------------------------------------- Installing recent versions of sqlc requires Go 1.21+. go install github.com/sqlc\-dev/sqlc/cmd/sqlc@latest Docker[](https://docs.sqlc.dev/en/v1.30.0/overview/install.html#docker "Link to this heading") ------------------------------------------------------------------------------------------------ docker pull sqlc/sqlc Run `sqlc` using `docker run`: docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate Run `sqlc` using `docker run` in the Command Prompt on Windows (`cmd`): docker run \--rm \-v "%cd%:/src" \-w /src sqlc/sqlc generate Downloads[](https://docs.sqlc.dev/en/v1.30.0/overview/install.html#downloads "Link to this heading") ------------------------------------------------------------------------------------------------------ Get pre-built binaries for _v1.30.0_: * [Linux](https://downloads.sqlc.dev/sqlc_1.30.0_linux_amd64.tar.gz) * [macOS](https://downloads.sqlc.dev/sqlc_1.30.0_darwin_amd64.zip) * [Windows](https://downloads.sqlc.dev/sqlc_1.30.0_windows_amd64.zip) See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions. --- # Renaming fields — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Renaming fields * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/rename.md.txt) * * * Renaming fields[](https://docs.sqlc.dev/en/v1.30.0/howto/rename.html#renaming-fields "Link to this heading") ============================================================================================================== Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" rename: spotify\_url: "SpotifyURL" Tables[](https://docs.sqlc.dev/en/v1.30.0/howto/rename.html#tables "Link to this heading") -------------------------------------------------------------------------------------------- The output structs associated with tables can also be renamed. By default, the struct name will be the singular version of the table name. For example, the `authors` table will generate an `Author` struct and the `book_publishers` table will generate a `BookPublisher` struct. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); CREATE TABLE book\_publishers ( id BIGSERIAL PRIMARY KEY, name text NOT NULL ); package db import ( "database/sql" ) type Author struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } To rename these structs, you must use the generated struct name. In this example, that would be `author` and `book_publisher`. Use the `rename` map to change the name of these struct to `Writer` and `BookPublisher` (note the camel-casing and the underscore for multi-worded tables). version: '1' packages: \- path: db engine: postgresql schema: query.sql queries: query.sql rename: author: Writer book\_publisher: Publisher version: "2" sql: \- engine: postgresql queries: query.sql schema: query.sql overrides: go: rename: author: Writer book\_publisher: Publisher package db import ( "database/sql" ) type Writer struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } Limitations[](https://docs.sqlc.dev/en/v1.30.0/howto/rename.html#limitations "Link to this heading") ------------------------------------------------------------------------------------------------------ Rename mappings apply to an entire package. Therefore, a column named `foo` and a table name `foo` can’t map to different rename values. --- # Deleting rows — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Deleting rows * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/delete.md.txt) * * * Deleting rows[](https://docs.sqlc.dev/en/v1.30.0/howto/delete.html#deleting-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; **MySQL and SQLite:** \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const deleteAuthor \= \`-- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $1 \` func (q \*Queries) DeleteAuthor(ctx context.Context, id int) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } --- # CLI — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * CLI * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/cli.md.txt) * * * CLI[](https://docs.sqlc.dev/en/v1.30.0/reference/cli.html#cli "Link to this heading") ======================================================================================= Usage: sqlc \[command\] Available Commands: compile Statically check SQL for syntax and type errors completion Generate the autocompletion script for the specified shell createdb Create an ephemeral database diff Compare the generated files to the existing files generate Generate source code from SQL help Help about any command init Create an empty sqlc.yaml settings file push Push the schema, queries, and configuration for this project verify Verify schema, queries, and configuration for this project version Print the sqlc version number vet Vet examines queries Flags: \-f, \--file string specify an alternate config file (default: sqlc.yaml) \-h, \--help help for sqlc \--no-database disable database connections (default: false) \--no-remote disable remote execution (default: false) Use "sqlc \[command\] --help" for more information about a command. --- # Installing sqlc — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/index.html) * Installing sqlc * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/overview/install.md.txt) * * * Installing sqlc[](https://docs.sqlc.dev/en/v1.29.0/overview/install.html#installing-sqlc "Link to this heading") ================================================================================================================== sqlc is distributed as a single binary with zero dependencies. macOS[](https://docs.sqlc.dev/en/v1.29.0/overview/install.html#macos "Link to this heading") ---------------------------------------------------------------------------------------------- brew install sqlc Ubuntu[](https://docs.sqlc.dev/en/v1.29.0/overview/install.html#ubuntu "Link to this heading") ------------------------------------------------------------------------------------------------ sudo snap install sqlc go install[](https://docs.sqlc.dev/en/v1.29.0/overview/install.html#go-install "Link to this heading") -------------------------------------------------------------------------------------------------------- Installing recent versions of sqlc requires Go 1.21+. go install github.com/sqlc\-dev/sqlc/cmd/sqlc@latest Docker[](https://docs.sqlc.dev/en/v1.29.0/overview/install.html#docker "Link to this heading") ------------------------------------------------------------------------------------------------ docker pull sqlc/sqlc Run `sqlc` using `docker run`: docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate Run `sqlc` using `docker run` in the Command Prompt on Windows (`cmd`): docker run \--rm \-v "%cd%:/src" \-w /src sqlc/sqlc generate Downloads[](https://docs.sqlc.dev/en/v1.29.0/overview/install.html#downloads "Link to this heading") ------------------------------------------------------------------------------------------------------ Get pre-built binaries for _v1.29.0_: * [Linux](https://downloads.sqlc.dev/sqlc_1.29.0_linux_amd64.tar.gz) * [macOS](https://downloads.sqlc.dev/sqlc_1.29.0_darwin_amd64.zip) * [Windows](https://downloads.sqlc.dev/sqlc_1.29.0_windows_amd64.zip) See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions. --- # Embedding structs — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Embedding structs * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/embedding.md) * * * Embedding structs[](https://docs.sqlc.dev/en/v1.27.0/howto/embedding.html#embedding-structs "Link to this heading") ===================================================================================================================== Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text NOT NULL, age integer NOT NULL ); CREATE TABLE test\_scores ( student\_id bigint NOT NULL, score integer NOT NULL, grade text NOT NULL ); We want to select the student record and the scores they got on a test. Here’s how we’d usually do that: \-- name: ScoreAndTests :many SELECT students.\*, test\_scores.\* FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; When using Go, sqlc will produce a struct like this: type ScoreAndTestsRow struct { ID int64 Name string Age int32 StudentID int64 Score int32 Grade string } With embedding, the struct will contain a model for both tables instead of a flattened list of columns. \-- name: ScoreAndTests :many SELECT sqlc.embed(students), sqlc.embed(test\_scores) FROM students JOIN test\_scores ON test\_scores.student\_id \= students.id WHERE students.id \= $1; type ScoreAndTestsRow struct { Student Student TestScore TestScore } --- # Environment variables — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Environment variables * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/environment-variables.md.txt) * * * Environment variables[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#environment-variables "Link to this heading") ============================================================================================================================================ SQLCEXPERIMENT[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#sqlcexperiment "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------ The `SQLCEXPERIMENT` variable controls experimental features within sqlc. It is a comma-separated list of experiment names. This is modeled after Go’s [GOEXPERIMENT](https://pkg.go.dev/internal/goexperiment) environment variable. Experiment names can be prefixed with `no` to explicitly disable them. SQLCEXPERIMENT\=foo,bar \# enable foo and bar experiments SQLCEXPERIMENT\=nofoo \# explicitly disable foo experiment SQLCEXPERIMENT\=foo,nobar \# enable foo, disable bar Currently, no experiments are defined. Experiments will be documented here as they are introduced. SQLCCACHE[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#sqlccache "Link to this heading") -------------------------------------------------------------------------------------------------------------------- The `SQLCCACHE` environment variable dictates where `sqlc` will store cached WASM-based plugins and modules. By default `sqlc` follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) . SQLCDEBUG[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#sqlcdebug "Link to this heading") -------------------------------------------------------------------------------------------------------------------- The `SQLCDEBUG` variable controls debugging variables within the runtime. It is a comma-separated list of name=val pairs settings. ### dumpast[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#dumpast "Link to this heading") The `dumpast` command shows the SQL AST that was generated by the parser. Note that this is the generic SQL AST, not the engine-specific SQL AST. SQLCDEBUG\=dumpast\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc0004f48c0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc0004f4930)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc00052ff20)({ Rel: (\*ast.TableName)(0xc00052fda0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### dumpcatalog[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#dumpcatalog "Link to this heading") The `dumpcatalog` command outputs the entire catalog. If you’re using MySQL or PostgreSQL, this can be a bit overwhelming. Expect this output to change in future versions. SQLCDEBUG\=dumpcatalog\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc00050d1f0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc00050d260)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc0000c0840)({ Rel: (\*ast.TableName)(0xc0000c06c0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### trace[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#trace "Link to this heading") The `trace` command is helpful for tracking down performance issues. `SQLCDEBUG=trace=1` By default, the trace output is written to `trace.out` in the current working directory. You can configure a different path if needed. `SQLCDEBUG=trace=name.out` View the execution trace using the Go `trace` tool. go tool trace trace.out There’s a ton of different views for the trace output, but here’s an example log showing the execution time for each package. 0.000043897 . 1 task sqlc (id 1, parent 0) created 0.000144923 . 101026 1 region generate started (duration: 47.619781ms) 0.001048975 . 904052 1 region package started (duration: 14.588456ms) 0.001054616 . 5641 1 name\=authors dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.001071257 . 16641 1 region parse started (duration: 7.966549ms) 0.009043960 . 7972703 1 region codegen started (duration: 6.587086ms) 0.009171704 . 127744 1 new goroutine 35: text/template/parse.lex·dwrap·1 0.010361654 . 1189950 1 new goroutine 36: text/template/parse.lex·dwrap·1 0.015641815 . 5280161 1 region package started (duration: 10.904938ms) 0.015644943 . 3128 1 name\=booktest dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.015647431 . 2488 1 region parse started (duration: 4.207749ms) 0.019860308 . 4212877 1 region codegen started (duration: 6.681624ms) 0.020028488 . 168180 1 new goroutine 37: text/template/parse.lex·dwrap·1 0.021020310 . 991822 1 new goroutine 8: text/template/parse.lex·dwrap·1 0.026551163 . 5530853 1 region package started (duration: 9.217294ms) 0.026554368 . 3205 1 name\=jets dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.026556804 . 2436 1 region parse started (duration: 3.491005ms) 0.030051911 . 3495107 1 region codegen started (duration: 5.711931ms) 0.030213937 . 162026 1 new goroutine 20: text/template/parse.lex·dwrap·1 0.031099938 . 886001 1 new goroutine 38: text/template/parse.lex·dwrap·1 0.035772637 . 4672699 1 region package started (duration: 10.267039ms) 0.035775688 . 3051 1 name\=ondeck dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.035778150 . 2462 1 region parse started (duration: 4.094518ms) 0.039877181 . 4099031 1 region codegen started (duration: 6.156341ms) 0.040010771 . 133590 1 new goroutine 39: text/template/parse.lex·dwrap·1 0.040894567 . 883796 1 new goroutine 40: text/template/parse.lex·dwrap·1 0.046042779 . 5148212 1 region writefiles started (duration: 1.718259ms) 0.047767781 . 1725002 1 task end ### processplugins[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#processplugins "Link to this heading") Setting this value to `0` disables process-based plugins. If a process-based plugin is declared in the configuration file, running any `sqlc` command will return an error. `SQLCDEBUG=processplugins=0` ### dumpvetenv[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#dumpvetenv "Link to this heading") The `dumpvetenv` command prints the variables available to a `sqlc vet` rule during evaluation. `SQLCDEBUG=dumpvetenv=1` ### dumpexplain[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#dumpexplain "Link to this heading") The `dumpexplain` command prints the JSON-formatted result from running `EXPLAIN ...` on a query when a `sqlc vet` rule evaluation requires its output. `SQLCDEBUG=dumpexplain=1` SQLCTMPDIR[](https://docs.sqlc.dev/en/stable/reference/environment-variables.html#sqlctmpdir "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- If specified, use the given directory as the base for temporary folders. Only applies when using WASM-based codegen plugins. When not specified, this defaults to passing an empty string to [`os.MkdirTemp`](https://pkg.go.dev/os#MkdirTemp) . --- # Getting started with PostgreSQL — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Getting started with PostgreSQL * [View page source](https://docs.sqlc.dev/en/stable/_sources/tutorials/getting-started-postgresql.md.txt) * * * Getting started with PostgreSQL[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-postgresql.html#getting-started-with-postgresql "Link to this heading") ===================================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/stable/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/stable/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-postgresql.html#setting-up "Link to this heading") --------------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app`: go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Schema and queries[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-postgresql.html#schema-and-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1 RETURNING \*; Generating code[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-postgresql.html#generating-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-postgresql.html#using-generated-code "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------- You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "log" "reflect" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() conn, err := pgx.Connect(ctx, "user=pqgotest dbname=pqgotest sslmode=verify-full") if err != nil { return err } defer conn.Close(ctx) queries := tutorial.New(conn) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant PostgreSQL driver. You can use `lib/pq` with the standard library’s `database/sql` package, but in this tutorial we’ve used `pgx/v5`: go get github.com/jackc/pgx/v5 go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `pgx.Connect()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/stable/tutorials/getting-started-postgresql.html#query-verification "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial In the sidebar, go to the “Queries” section to see your published queries. Run `verify` to ensure that previously published queries continue to work against updated database schema. $ sqlc verify \--against tutorial --- # Datatypes — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Datatypes * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/datatypes.md.txt) * * * Datatypes[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#datatypes "Link to this heading") ======================================================================================================== `sqlc` attempts to make reasonable default choices when mapping internal database types to Go types. Choices for more complex types are described below. If you’re unsatisfied with the default, you can override any type using the [overrides list](https://docs.sqlc.dev/en/stable/reference/config.html#overrides) in your `sqlc` config file. Arrays[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#arrays "Link to this heading") -------------------------------------------------------------------------------------------------- PostgreSQL [arrays](https://www.postgresql.org/docs/current/arrays.html) are materialized as Go slices. CREATE TABLE places ( name text not null, tags text\[\] ); package db type Place struct { Name string Tags \[\]string } Dates and times[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#dates-and-times "Link to this heading") -------------------------------------------------------------------------------------------------------------------- All date and time types are returned as `time.Time` structs. For null time or date values, the `NullTime` type from `database/sql` is used. The `pgx/v5` sql package uses the appropriate pgx types. For MySQL users relying on `github.com/go-sql-driver/mysql`, ensure that `parseTime=true` is added to your database connection string. CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL DEFAULT NOW(), updated\_at timestamp ); package db import ( "database/sql" "time" ) type Author struct { ID int CreatedAt time.Time UpdatedAt sql.NullTime } Enums[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#enums "Link to this heading") ------------------------------------------------------------------------------------------------ PostgreSQL [enums](https://www.postgresql.org/docs/current/datatype-enum.html) are mapped to an aliased string type. CREATE TYPE status AS ENUM ( 'open', 'closed' ); CREATE TABLE stores ( name text PRIMARY KEY, status status NOT NULL ); package db type Status string const ( StatusOpen Status \= "open" StatusClosed Status \= "closed" ) type Store struct { Name string Status Status } Null[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#null "Link to this heading") ---------------------------------------------------------------------------------------------- For structs, null values are represented using the appropriate type from the `database/sql` or `pgx` package. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text ); package db import ( "database/sql" ) type Author struct { ID int Name string Bio sql.NullString } UUIDs[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#uuids "Link to this heading") ------------------------------------------------------------------------------------------------ The Go standard library does not come with a `uuid` package. For UUID support, sqlc uses the excellent `github.com/google/uuid` package. The pgx/v5 sql package uses `pgtype.UUID`. CREATE TABLE records ( id uuid PRIMARY KEY ); package db import ( "github.com/google/uuid" ) type Author struct { ID uuid.UUID } For MySQL, there is no native `uuid` data type. When using `UUID_TO_BIN` to store a `UUID()`, the underlying field type is `BINARY(16)` which by default sqlc would map to `sql.NullString`. To have sqlc automatically convert these fields to a `uuid.UUID` type, use an overide on the column storing the `uuid` (see [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for details). { "overrides": \[\ {\ "column": "\*.uuid",\ "go\_type": "github.com/google/uuid.UUID"\ }\ \] } JSON[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#json "Link to this heading") ---------------------------------------------------------------------------------------------- By default, sqlc will generate the `[]byte`, `pgtype.JSON` or `json.RawMessage` for JSON column type. But if you use the `pgx/v5` sql package then you can specify a struct instead of the default type (see [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for details). The `pgx` implementation will marshal/unmarshal the struct automatically. package dto type BookData struct { Genres \[\]string \`json:"genres"\` Title string \`json:"title"\` Published bool \`json:"published"\` } CREATE TABLE books ( data jsonb ); { "overrides": \[\ {\ "column": "books.data",\ "go\_type": {\ "import":"example.com/db",\ "package": "dto",\ "type":"BookData",\ "pointer": true\ }\ }\ \] } package db import ( "example.com/db/dto" ) type Book struct { Data \*dto.BookData } TEXT[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#text "Link to this heading") ---------------------------------------------------------------------------------------------- In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a Go string by default. This default mapping applies to `TEXT` columns that are not nullable. However, for nullable `TEXT` columns, sqlc maps them to `pgtype.Text` when using the pgx/v5 driver. This distinction is crucial for developers looking to handle null values appropriately in their Go applications. To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in your sqlc config file (see [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for details). Geometry[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#geometry "Link to this heading") ------------------------------------------------------------------------------------------------------ ### PostGIS[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#postgis "Link to this heading") #### Using `github.com/twpayne/go-geos` (pgx/v5 only)[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#using-github-com-twpayne-go-geos-pgx-v5-only "Link to this heading") sqlc can be configured to use the [geos](https://github.com/twpayne/go-geos) package for working with PostGIS geometry types in [GEOS](https://libgeos.org/) . There are three steps: 1. Configure sqlc to use `*github.com/twpayne/go-geos.Geom` for geometry types (see [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for details). 2. Call `github.com/twpayne/pgx-geos.Register` on each `*github.com/jackc/pgx/v5.Conn`. 3. Annotate your SQL with `::geometry` typecasts, if needed. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetCentroids :many SELECT id, name, ST\_Centroid(geom)::geometry FROM shapes; { "version": 2, "gen": { "go": { "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": {\ "import": "github.com/twpayne/go-geos",\ "package": "geos",\ "pointer": true,\ "type": "Geom"\ },\ "nullable": true\ }\ \] } } } import ( "github.com/twpayne/go-geos" pgxgeos "github.com/twpayne/pgx-geos" ) // ... config.AfterConnect \= func(ctx context.Context, conn \*pgx.Conn) error { if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil { return err } return nil } #### Using `github.com/twpayne/go-geom`[](https://docs.sqlc.dev/en/stable/reference/datatypes.html#using-github-com-twpayne-go-geom "Link to this heading") sqlc can be configured to use the [geom](https://github.com/twpayne/go-geom) package for working with PostGIS geometry types. See [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for more information. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetShapes :many SELECT \* FROM shapes; { "version": "1", "packages": \[\ {\ "path": "db",\ "engine": "postgresql",\ "schema": "query.sql",\ "queries": "query.sql"\ }\ \], "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon"\ },\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon",\ "nullable": true\ }\ \] } --- # vet - Linting queries — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * `vet` - Linting queries * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/vet.md.txt) * * * `vet` - Linting queries[](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#vet-linting-queries "Link to this heading") ======================================================================================================================= _Added in v1.19.0_ `sqlc vet` runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.31.0/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, `sqlc vet` will report an error using the given message. Defining lint rules[](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#defining-lint-rules "Link to this heading") ------------------------------------------------------------------------------------------------------------------- Each lint rule’s CEL expression has access to information from your sqlc configuration and queries via variables defined in the following proto messages. message Config { string version \= 1; string engine \= 2 ; repeated string schema \= 3; repeated string queries \= 4; } message Query { // SQL body string sql \= 1; // Name of the query string name \= 2; // One of "many", "one", "exec", etc. string cmd \= 3; // Query parameters, if any repeated Parameter params \= 4; } message Parameter { int32 number \= 1; } In addition to this basic information, when you have a PostgreSQL or MySQL [database connection configured](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database) each CEL expression has access to the output from running `EXPLAIN ...` on your query via the `postgresql.explain` and `mysql.explain` variables. This output is quite complex and depends on the structure of your query but sqlc attempts to parse and provide as much information as it can. See [Rules using `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#rules-using-explain-output) for more information. Here are a few example rules just using the basic configuration and query information available to the CEL expression environment. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Rules using `EXPLAIN ...` output[](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#rules-using-explain-output "Link to this heading") _Added in v1.20.0_ The CEL expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- debug rules: \- name: debug rule: "!has(postgresql.explain)" \# A dummy rule to trigger explain Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with rules that depend on `EXPLAIN ...` output. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. Built-in rules[](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#built-in-rules "Link to this heading") --------------------------------------------------------------------------------------------------------- ### sqlc/db-prepare[](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#sqlc-db-prepare "Link to this heading") When a [database](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database) connection is configured, you can run the built-in `sqlc/db-prepare` rule. This rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with the `sqlc/db-prepare` rule. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. version: 2 cloud: project: "" sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: managed: true rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Running lint rules[](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#running-lint-rules "Link to this heading") ----------------------------------------------------------------------------------------------------------------- When you add the name of a defined rule to the rules list for a [sql package](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#sql) , `sqlc vet` will evaluate that rule against every query in the package. In the example below, two rules are defined but only one is enabled. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-delete rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") ### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. The annotation accepts a list of rules to ignore. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; The rules can also be split across lines. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare \*/ /\* @sqlc-vet-disable no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; To skip all rules for a query, you can provide the `@sqlc-vet-disable` annotation without any parameters. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; --- # Datatypes — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Datatypes * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/datatypes.md.txt) * * * Datatypes[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#datatypes "Link to this heading") ========================================================================================================= `sqlc` attempts to make reasonable default choices when mapping internal database types to Go types. Choices for more complex types are described below. If you’re unsatisfied with the default, you can override any type using the [overrides list](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#overrides) in your `sqlc` config file. Arrays[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#arrays "Link to this heading") --------------------------------------------------------------------------------------------------- PostgreSQL [arrays](https://www.postgresql.org/docs/current/arrays.html) are materialized as Go slices. CREATE TABLE places ( name text not null, tags text\[\] ); package db type Place struct { Name string Tags \[\]string } Dates and times[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#dates-and-times "Link to this heading") --------------------------------------------------------------------------------------------------------------------- All date and time types are returned as `time.Time` structs. For null time or date values, the `NullTime` type from `database/sql` is used. The `pgx/v5` sql package uses the appropriate pgx types. For MySQL users relying on `github.com/go-sql-driver/mysql`, ensure that `parseTime=true` is added to your database connection string. CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL DEFAULT NOW(), updated\_at timestamp ); package db import ( "database/sql" "time" ) type Author struct { ID int CreatedAt time.Time UpdatedAt sql.NullTime } Enums[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#enums "Link to this heading") ------------------------------------------------------------------------------------------------- PostgreSQL [enums](https://www.postgresql.org/docs/current/datatype-enum.html) are mapped to an aliased string type. CREATE TYPE status AS ENUM ( 'open', 'closed' ); CREATE TABLE stores ( name text PRIMARY KEY, status status NOT NULL ); package db type Status string const ( StatusOpen Status \= "open" StatusClosed Status \= "closed" ) type Store struct { Name string Status Status } Null[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#null "Link to this heading") ----------------------------------------------------------------------------------------------- For structs, null values are represented using the appropriate type from the `database/sql` or `pgx` package. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text ); package db import ( "database/sql" ) type Author struct { ID int Name string Bio sql.NullString } UUIDs[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#uuids "Link to this heading") ------------------------------------------------------------------------------------------------- The Go standard library does not come with a `uuid` package. For UUID support, sqlc uses the excellent `github.com/google/uuid` package. The pgx/v5 sql package uses `pgtype.UUID`. CREATE TABLE records ( id uuid PRIMARY KEY ); package db import ( "github.com/google/uuid" ) type Author struct { ID uuid.UUID } For MySQL, there is no native `uuid` data type. When using `UUID_TO_BIN` to store a `UUID()`, the underlying field type is `BINARY(16)` which by default sqlc would map to `sql.NullString`. To have sqlc automatically convert these fields to a `uuid.UUID` type, use an overide on the column storing the `uuid` (see [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for details). { "overrides": \[\ {\ "column": "\*.uuid",\ "go\_type": "github.com/google/uuid.UUID"\ }\ \] } JSON[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#json "Link to this heading") ----------------------------------------------------------------------------------------------- By default, sqlc will generate the `[]byte`, `pgtype.JSON` or `json.RawMessage` for JSON column type. But if you use the `pgx/v5` sql package then you can specify a struct instead of the default type (see [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for details). The `pgx` implementation will marshal/unmarshal the struct automatically. package dto type BookData struct { Genres \[\]string \`json:"genres"\` Title string \`json:"title"\` Published bool \`json:"published"\` } CREATE TABLE books ( data jsonb ); { "overrides": \[\ {\ "column": "books.data",\ "go\_type": {\ "import":"example.com/db",\ "package": "dto",\ "type":"BookData",\ "pointer": true\ }\ }\ \] } package db import ( "example.com/db/dto" ) type Book struct { Data \*dto.BookData } TEXT[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#text "Link to this heading") ----------------------------------------------------------------------------------------------- In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a Go string by default. This default mapping applies to `TEXT` columns that are not nullable. However, for nullable `TEXT` columns, sqlc maps them to `pgtype.Text` when using the pgx/v5 driver. This distinction is crucial for developers looking to handle null values appropriately in their Go applications. To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in your sqlc config file (see [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for details). Geometry[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#geometry "Link to this heading") ------------------------------------------------------------------------------------------------------- ### PostGIS[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#postgis "Link to this heading") #### Using `github.com/twpayne/go-geos` (pgx/v5 only)[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#using-github-com-twpayne-go-geos-pgx-v5-only "Link to this heading") sqlc can be configured to use the [geos](https://github.com/twpayne/go-geos) package for working with PostGIS geometry types in [GEOS](https://libgeos.org/) . There are three steps: 1. Configure sqlc to use `*github.com/twpayne/go-geos.Geom` for geometry types (see [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for details). 2. Call `github.com/twpayne/pgx-geos.Register` on each `*github.com/jackc/pgx/v5.Conn`. 3. Annotate your SQL with `::geometry` typecasts, if needed. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetCentroids :many SELECT id, name, ST\_Centroid(geom)::geometry FROM shapes; { "version": 2, "gen": { "go": { "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": {\ "import": "github.com/twpayne/go-geos",\ "package": "geos",\ "pointer": true,\ "type": "Geom"\ },\ "nullable": true\ }\ \] } } } import ( "github.com/twpayne/go-geos" pgxgeos "github.com/twpayne/pgx-geos" ) // ... config.AfterConnect \= func(ctx context.Context, conn \*pgx.Conn) error { if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil { return err } return nil } #### Using `github.com/twpayne/go-geom`[](https://docs.sqlc.dev/en/v1.31.0/reference/datatypes.html#using-github-com-twpayne-go-geom "Link to this heading") sqlc can be configured to use the [geom](https://github.com/twpayne/go-geom) package for working with PostGIS geometry types. See [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for more information. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetShapes :many SELECT \* FROM shapes; { "version": "1", "packages": \[\ {\ "path": "db",\ "engine": "postgresql",\ "schema": "query.sql",\ "queries": "query.sql"\ }\ \], "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon"\ },\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon",\ "nullable": true\ }\ \] } --- # Environment variables — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Environment variables * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/environment-variables.md.txt) * * * Environment variables[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#environment-variables "Link to this heading") ============================================================================================================================================= SQLCEXPERIMENT[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#sqlcexperiment "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------- The `SQLCEXPERIMENT` variable controls experimental features within sqlc. It is a comma-separated list of experiment names. This is modeled after Go’s [GOEXPERIMENT](https://pkg.go.dev/internal/goexperiment) environment variable. Experiment names can be prefixed with `no` to explicitly disable them. SQLCEXPERIMENT\=foo,bar \# enable foo and bar experiments SQLCEXPERIMENT\=nofoo \# explicitly disable foo experiment SQLCEXPERIMENT\=foo,nobar \# enable foo, disable bar Currently, no experiments are defined. Experiments will be documented here as they are introduced. SQLCCACHE[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#sqlccache "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCCACHE` environment variable dictates where `sqlc` will store cached WASM-based plugins and modules. By default `sqlc` follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) . SQLCDEBUG[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#sqlcdebug "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCDEBUG` variable controls debugging variables within the runtime. It is a comma-separated list of name=val pairs settings. ### dumpast[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#dumpast "Link to this heading") The `dumpast` command shows the SQL AST that was generated by the parser. Note that this is the generic SQL AST, not the engine-specific SQL AST. SQLCDEBUG\=dumpast\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc0004f48c0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc0004f4930)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc00052ff20)({ Rel: (\*ast.TableName)(0xc00052fda0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### dumpcatalog[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#dumpcatalog "Link to this heading") The `dumpcatalog` command outputs the entire catalog. If you’re using MySQL or PostgreSQL, this can be a bit overwhelming. Expect this output to change in future versions. SQLCDEBUG\=dumpcatalog\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc00050d1f0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc00050d260)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc0000c0840)({ Rel: (\*ast.TableName)(0xc0000c06c0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### trace[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#trace "Link to this heading") The `trace` command is helpful for tracking down performance issues. `SQLCDEBUG=trace=1` By default, the trace output is written to `trace.out` in the current working directory. You can configure a different path if needed. `SQLCDEBUG=trace=name.out` View the execution trace using the Go `trace` tool. go tool trace trace.out There’s a ton of different views for the trace output, but here’s an example log showing the execution time for each package. 0.000043897 . 1 task sqlc (id 1, parent 0) created 0.000144923 . 101026 1 region generate started (duration: 47.619781ms) 0.001048975 . 904052 1 region package started (duration: 14.588456ms) 0.001054616 . 5641 1 name\=authors dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.001071257 . 16641 1 region parse started (duration: 7.966549ms) 0.009043960 . 7972703 1 region codegen started (duration: 6.587086ms) 0.009171704 . 127744 1 new goroutine 35: text/template/parse.lex·dwrap·1 0.010361654 . 1189950 1 new goroutine 36: text/template/parse.lex·dwrap·1 0.015641815 . 5280161 1 region package started (duration: 10.904938ms) 0.015644943 . 3128 1 name\=booktest dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.015647431 . 2488 1 region parse started (duration: 4.207749ms) 0.019860308 . 4212877 1 region codegen started (duration: 6.681624ms) 0.020028488 . 168180 1 new goroutine 37: text/template/parse.lex·dwrap·1 0.021020310 . 991822 1 new goroutine 8: text/template/parse.lex·dwrap·1 0.026551163 . 5530853 1 region package started (duration: 9.217294ms) 0.026554368 . 3205 1 name\=jets dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.026556804 . 2436 1 region parse started (duration: 3.491005ms) 0.030051911 . 3495107 1 region codegen started (duration: 5.711931ms) 0.030213937 . 162026 1 new goroutine 20: text/template/parse.lex·dwrap·1 0.031099938 . 886001 1 new goroutine 38: text/template/parse.lex·dwrap·1 0.035772637 . 4672699 1 region package started (duration: 10.267039ms) 0.035775688 . 3051 1 name\=ondeck dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.035778150 . 2462 1 region parse started (duration: 4.094518ms) 0.039877181 . 4099031 1 region codegen started (duration: 6.156341ms) 0.040010771 . 133590 1 new goroutine 39: text/template/parse.lex·dwrap·1 0.040894567 . 883796 1 new goroutine 40: text/template/parse.lex·dwrap·1 0.046042779 . 5148212 1 region writefiles started (duration: 1.718259ms) 0.047767781 . 1725002 1 task end ### processplugins[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#processplugins "Link to this heading") Setting this value to `0` disables process-based plugins. If a process-based plugin is declared in the configuration file, running any `sqlc` command will return an error. `SQLCDEBUG=processplugins=0` ### dumpvetenv[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#dumpvetenv "Link to this heading") The `dumpvetenv` command prints the variables available to a `sqlc vet` rule during evaluation. `SQLCDEBUG=dumpvetenv=1` ### dumpexplain[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#dumpexplain "Link to this heading") The `dumpexplain` command prints the JSON-formatted result from running `EXPLAIN ...` on a query when a `sqlc vet` rule evaluation requires its output. `SQLCDEBUG=dumpexplain=1` SQLCTMPDIR[](https://docs.sqlc.dev/en/v1.31.0/reference/environment-variables.html#sqlctmpdir "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- If specified, use the given directory as the base for temporary folders. Only applies when using WASM-based codegen plugins. When not specified, this defaults to passing an empty string to [`os.MkdirTemp`](https://pkg.go.dev/os#MkdirTemp) . --- # Getting started with PostgreSQL — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Getting started with PostgreSQL * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/tutorials/getting-started-postgresql.md.txt) * * * Getting started with PostgreSQL[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-postgresql.html#getting-started-with-postgresql "Link to this heading") ====================================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.31.1/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.31.1/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-postgresql.html#setting-up "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app`: go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Schema and queries[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-postgresql.html#schema-and-queries "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1 RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-postgresql.html#generating-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-postgresql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------ You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "log" "reflect" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() conn, err := pgx.Connect(ctx, "user=pqgotest dbname=pqgotest sslmode=verify-full") if err != nil { return err } defer conn.Close(ctx) queries := tutorial.New(conn) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant PostgreSQL driver. You can use `lib/pq` with the standard library’s `database/sql` package, but in this tutorial we’ve used `pgx/v5`: go get github.com/jackc/pgx/v5 go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `pgx.Connect()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.31.1/tutorials/getting-started-postgresql.html#query-verification "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial In the sidebar, go to the “Queries” section to see your published queries. Run `verify` to ensure that previously published queries continue to work against updated database schema. $ sqlc verify \--against tutorial --- # vet - Linting queries — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * `vet` - Linting queries * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/vet.md.txt) * * * `vet` - Linting queries[](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#vet-linting-queries "Link to this heading") ======================================================================================================================= _Added in v1.19.0_ `sqlc vet` runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.31.1/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, `sqlc vet` will report an error using the given message. Defining lint rules[](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#defining-lint-rules "Link to this heading") ------------------------------------------------------------------------------------------------------------------- Each lint rule’s CEL expression has access to information from your sqlc configuration and queries via variables defined in the following proto messages. message Config { string version \= 1; string engine \= 2 ; repeated string schema \= 3; repeated string queries \= 4; } message Query { // SQL body string sql \= 1; // Name of the query string name \= 2; // One of "many", "one", "exec", etc. string cmd \= 3; // Query parameters, if any repeated Parameter params \= 4; } message Parameter { int32 number \= 1; } In addition to this basic information, when you have a PostgreSQL or MySQL [database connection configured](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database) each CEL expression has access to the output from running `EXPLAIN ...` on your query via the `postgresql.explain` and `mysql.explain` variables. This output is quite complex and depends on the structure of your query but sqlc attempts to parse and provide as much information as it can. See [Rules using `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#rules-using-explain-output) for more information. Here are a few example rules just using the basic configuration and query information available to the CEL expression environment. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Rules using `EXPLAIN ...` output[](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#rules-using-explain-output "Link to this heading") _Added in v1.20.0_ The CEL expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- debug rules: \- name: debug rule: "!has(postgresql.explain)" \# A dummy rule to trigger explain Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with rules that depend on `EXPLAIN ...` output. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. Built-in rules[](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#built-in-rules "Link to this heading") --------------------------------------------------------------------------------------------------------- ### sqlc/db-prepare[](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#sqlc-db-prepare "Link to this heading") When a [database](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database) connection is configured, you can run the built-in `sqlc/db-prepare` rule. This rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with the `sqlc/db-prepare` rule. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. version: 2 cloud: project: "" sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: managed: true rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Running lint rules[](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#running-lint-rules "Link to this heading") ----------------------------------------------------------------------------------------------------------------- When you add the name of a defined rule to the rules list for a [sql package](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#sql) , `sqlc vet` will evaluate that rule against every query in the package. In the example below, two rules are defined but only one is enabled. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-delete rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") ### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. The annotation accepts a list of rules to ignore. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; The rules can also be split across lines. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare \*/ /\* @sqlc-vet-disable no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; To skip all rules for a query, you can provide the `@sqlc-vet-disable` annotation without any parameters. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; --- # Datatypes — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Datatypes * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/datatypes.md.txt) * * * Datatypes[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#datatypes "Link to this heading") ========================================================================================================= `sqlc` attempts to make reasonable default choices when mapping internal database types to Go types. Choices for more complex types are described below. If you’re unsatisfied with the default, you can override any type using the [overrides list](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#overrides) in your `sqlc` config file. Arrays[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#arrays "Link to this heading") --------------------------------------------------------------------------------------------------- PostgreSQL [arrays](https://www.postgresql.org/docs/current/arrays.html) are materialized as Go slices. CREATE TABLE places ( name text not null, tags text\[\] ); package db type Place struct { Name string Tags \[\]string } Dates and times[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#dates-and-times "Link to this heading") --------------------------------------------------------------------------------------------------------------------- All date and time types are returned as `time.Time` structs. For null time or date values, the `NullTime` type from `database/sql` is used. The `pgx/v5` sql package uses the appropriate pgx types. For MySQL users relying on `github.com/go-sql-driver/mysql`, ensure that `parseTime=true` is added to your database connection string. CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL DEFAULT NOW(), updated\_at timestamp ); package db import ( "database/sql" "time" ) type Author struct { ID int CreatedAt time.Time UpdatedAt sql.NullTime } Enums[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#enums "Link to this heading") ------------------------------------------------------------------------------------------------- PostgreSQL [enums](https://www.postgresql.org/docs/current/datatype-enum.html) are mapped to an aliased string type. CREATE TYPE status AS ENUM ( 'open', 'closed' ); CREATE TABLE stores ( name text PRIMARY KEY, status status NOT NULL ); package db type Status string const ( StatusOpen Status \= "open" StatusClosed Status \= "closed" ) type Store struct { Name string Status Status } Null[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#null "Link to this heading") ----------------------------------------------------------------------------------------------- For structs, null values are represented using the appropriate type from the `database/sql` or `pgx` package. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text ); package db import ( "database/sql" ) type Author struct { ID int Name string Bio sql.NullString } UUIDs[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#uuids "Link to this heading") ------------------------------------------------------------------------------------------------- The Go standard library does not come with a `uuid` package. For UUID support, sqlc uses the excellent `github.com/google/uuid` package. The pgx/v5 sql package uses `pgtype.UUID`. CREATE TABLE records ( id uuid PRIMARY KEY ); package db import ( "github.com/google/uuid" ) type Author struct { ID uuid.UUID } For MySQL, there is no native `uuid` data type. When using `UUID_TO_BIN` to store a `UUID()`, the underlying field type is `BINARY(16)` which by default sqlc would map to `sql.NullString`. To have sqlc automatically convert these fields to a `uuid.UUID` type, use an overide on the column storing the `uuid` (see [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for details). { "overrides": \[\ {\ "column": "\*.uuid",\ "go\_type": "github.com/google/uuid.UUID"\ }\ \] } JSON[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#json "Link to this heading") ----------------------------------------------------------------------------------------------- By default, sqlc will generate the `[]byte`, `pgtype.JSON` or `json.RawMessage` for JSON column type. But if you use the `pgx/v5` sql package then you can specify a struct instead of the default type (see [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for details). The `pgx` implementation will marshal/unmarshal the struct automatically. package dto type BookData struct { Genres \[\]string \`json:"genres"\` Title string \`json:"title"\` Published bool \`json:"published"\` } CREATE TABLE books ( data jsonb ); { "overrides": \[\ {\ "column": "books.data",\ "go\_type": {\ "import":"example.com/db",\ "package": "dto",\ "type":"BookData",\ "pointer": true\ }\ }\ \] } package db import ( "example.com/db/dto" ) type Book struct { Data \*dto.BookData } TEXT[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#text "Link to this heading") ----------------------------------------------------------------------------------------------- In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a Go string by default. This default mapping applies to `TEXT` columns that are not nullable. However, for nullable `TEXT` columns, sqlc maps them to `pgtype.Text` when using the pgx/v5 driver. This distinction is crucial for developers looking to handle null values appropriately in their Go applications. To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in your sqlc config file (see [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for details). Geometry[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#geometry "Link to this heading") ------------------------------------------------------------------------------------------------------- ### PostGIS[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#postgis "Link to this heading") #### Using `github.com/twpayne/go-geos` (pgx/v5 only)[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#using-github-com-twpayne-go-geos-pgx-v5-only "Link to this heading") sqlc can be configured to use the [geos](https://github.com/twpayne/go-geos) package for working with PostGIS geometry types in [GEOS](https://libgeos.org/) . There are three steps: 1. Configure sqlc to use `*github.com/twpayne/go-geos.Geom` for geometry types (see [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for details). 2. Call `github.com/twpayne/pgx-geos.Register` on each `*github.com/jackc/pgx/v5.Conn`. 3. Annotate your SQL with `::geometry` typecasts, if needed. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetCentroids :many SELECT id, name, ST\_Centroid(geom)::geometry FROM shapes; { "version": 2, "gen": { "go": { "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": {\ "import": "github.com/twpayne/go-geos",\ "package": "geos",\ "pointer": true,\ "type": "Geom"\ },\ "nullable": true\ }\ \] } } } import ( "github.com/twpayne/go-geos" pgxgeos "github.com/twpayne/pgx-geos" ) // ... config.AfterConnect \= func(ctx context.Context, conn \*pgx.Conn) error { if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil { return err } return nil } #### Using `github.com/twpayne/go-geom`[](https://docs.sqlc.dev/en/v1.31.1/reference/datatypes.html#using-github-com-twpayne-go-geom "Link to this heading") sqlc can be configured to use the [geom](https://github.com/twpayne/go-geom) package for working with PostGIS geometry types. See [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for more information. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetShapes :many SELECT \* FROM shapes; { "version": "1", "packages": \[\ {\ "path": "db",\ "engine": "postgresql",\ "schema": "query.sql",\ "queries": "query.sql"\ }\ \], "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon"\ },\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon",\ "nullable": true\ }\ \] } --- # Environment variables — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Environment variables * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/environment-variables.md.txt) * * * Environment variables[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#environment-variables "Link to this heading") ============================================================================================================================================= SQLCEXPERIMENT[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#sqlcexperiment "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------- The `SQLCEXPERIMENT` variable controls experimental features within sqlc. It is a comma-separated list of experiment names. This is modeled after Go’s [GOEXPERIMENT](https://pkg.go.dev/internal/goexperiment) environment variable. Experiment names can be prefixed with `no` to explicitly disable them. SQLCEXPERIMENT\=foo,bar \# enable foo and bar experiments SQLCEXPERIMENT\=nofoo \# explicitly disable foo experiment SQLCEXPERIMENT\=foo,nobar \# enable foo, disable bar Currently, no experiments are defined. Experiments will be documented here as they are introduced. SQLCCACHE[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#sqlccache "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCCACHE` environment variable dictates where `sqlc` will store cached WASM-based plugins and modules. By default `sqlc` follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) . SQLCDEBUG[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#sqlcdebug "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCDEBUG` variable controls debugging variables within the runtime. It is a comma-separated list of name=val pairs settings. ### dumpast[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#dumpast "Link to this heading") The `dumpast` command shows the SQL AST that was generated by the parser. Note that this is the generic SQL AST, not the engine-specific SQL AST. SQLCDEBUG\=dumpast\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc0004f48c0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc0004f4930)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc00052ff20)({ Rel: (\*ast.TableName)(0xc00052fda0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### dumpcatalog[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#dumpcatalog "Link to this heading") The `dumpcatalog` command outputs the entire catalog. If you’re using MySQL or PostgreSQL, this can be a bit overwhelming. Expect this output to change in future versions. SQLCDEBUG\=dumpcatalog\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc00050d1f0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc00050d260)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc0000c0840)({ Rel: (\*ast.TableName)(0xc0000c06c0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### trace[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#trace "Link to this heading") The `trace` command is helpful for tracking down performance issues. `SQLCDEBUG=trace=1` By default, the trace output is written to `trace.out` in the current working directory. You can configure a different path if needed. `SQLCDEBUG=trace=name.out` View the execution trace using the Go `trace` tool. go tool trace trace.out There’s a ton of different views for the trace output, but here’s an example log showing the execution time for each package. 0.000043897 . 1 task sqlc (id 1, parent 0) created 0.000144923 . 101026 1 region generate started (duration: 47.619781ms) 0.001048975 . 904052 1 region package started (duration: 14.588456ms) 0.001054616 . 5641 1 name\=authors dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.001071257 . 16641 1 region parse started (duration: 7.966549ms) 0.009043960 . 7972703 1 region codegen started (duration: 6.587086ms) 0.009171704 . 127744 1 new goroutine 35: text/template/parse.lex·dwrap·1 0.010361654 . 1189950 1 new goroutine 36: text/template/parse.lex·dwrap·1 0.015641815 . 5280161 1 region package started (duration: 10.904938ms) 0.015644943 . 3128 1 name\=booktest dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.015647431 . 2488 1 region parse started (duration: 4.207749ms) 0.019860308 . 4212877 1 region codegen started (duration: 6.681624ms) 0.020028488 . 168180 1 new goroutine 37: text/template/parse.lex·dwrap·1 0.021020310 . 991822 1 new goroutine 8: text/template/parse.lex·dwrap·1 0.026551163 . 5530853 1 region package started (duration: 9.217294ms) 0.026554368 . 3205 1 name\=jets dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.026556804 . 2436 1 region parse started (duration: 3.491005ms) 0.030051911 . 3495107 1 region codegen started (duration: 5.711931ms) 0.030213937 . 162026 1 new goroutine 20: text/template/parse.lex·dwrap·1 0.031099938 . 886001 1 new goroutine 38: text/template/parse.lex·dwrap·1 0.035772637 . 4672699 1 region package started (duration: 10.267039ms) 0.035775688 . 3051 1 name\=ondeck dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.035778150 . 2462 1 region parse started (duration: 4.094518ms) 0.039877181 . 4099031 1 region codegen started (duration: 6.156341ms) 0.040010771 . 133590 1 new goroutine 39: text/template/parse.lex·dwrap·1 0.040894567 . 883796 1 new goroutine 40: text/template/parse.lex·dwrap·1 0.046042779 . 5148212 1 region writefiles started (duration: 1.718259ms) 0.047767781 . 1725002 1 task end ### processplugins[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#processplugins "Link to this heading") Setting this value to `0` disables process-based plugins. If a process-based plugin is declared in the configuration file, running any `sqlc` command will return an error. `SQLCDEBUG=processplugins=0` ### dumpvetenv[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#dumpvetenv "Link to this heading") The `dumpvetenv` command prints the variables available to a `sqlc vet` rule during evaluation. `SQLCDEBUG=dumpvetenv=1` ### dumpexplain[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#dumpexplain "Link to this heading") The `dumpexplain` command prints the JSON-formatted result from running `EXPLAIN ...` on a query when a `sqlc vet` rule evaluation requires its output. `SQLCDEBUG=dumpexplain=1` SQLCTMPDIR[](https://docs.sqlc.dev/en/v1.31.1/reference/environment-variables.html#sqlctmpdir "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- If specified, use the given directory as the base for temporary folders. Only applies when using WASM-based codegen plugins. When not specified, this defaults to passing an empty string to [`os.MkdirTemp`](https://pkg.go.dev/os#MkdirTemp) . --- # Getting started with PostgreSQL — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Getting started with PostgreSQL * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/tutorials/getting-started-postgresql.md.txt) * * * Getting started with PostgreSQL[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-postgresql.html#getting-started-with-postgresql "Link to this heading") ====================================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.30.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.30.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-postgresql.html#setting-up "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app`: go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Schema and queries[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-postgresql.html#schema-and-queries "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1 RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-postgresql.html#generating-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-postgresql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------ You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "log" "reflect" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() conn, err := pgx.Connect(ctx, "user=pqgotest dbname=pqgotest sslmode=verify-full") if err != nil { return err } defer conn.Close(ctx) queries := tutorial.New(conn) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant PostgreSQL driver. You can use `lib/pq` with the standard library’s `database/sql` package, but in this tutorial we’ve used `pgx/v5`: go get github.com/jackc/pgx/v5 go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `pgx.Connect()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.30.0/tutorials/getting-started-postgresql.html#query-verification "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial In the sidebar, go to the “Queries” section to see your published queries. Run `verify` to ensure that previously published queries continue to work against updated database schema. $ sqlc verify \--against tutorial --- # Configuring generated structs — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Configuring generated structs * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/structs.md.txt) * * * Configuring generated structs[](https://docs.sqlc.dev/en/stable/howto/structs.html#configuring-generated-structs "Link to this heading") ========================================================================================================================================== Naming scheme[](https://docs.sqlc.dev/en/stable/howto/structs.html#naming-scheme "Link to this heading") ---------------------------------------------------------------------------------------------------------- Structs generated from tables will attempt to use the singular form of a table name if the table name is pluralized. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL ); package db // Struct names use the singular form of table names type Author struct { ID int Name string } JSON tags[](https://docs.sqlc.dev/en/stable/howto/structs.html#json-tags "Link to this heading") -------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL ); sqlc can generate structs with JSON tags by adding the `emit_json_tags` key to the configuration file as it shows on [configuration reference](https://docs.sqlc.dev/en/stable/reference/config.html) . The JSON name for a field matches the column name in the database. package db import ( "time" ) type Author struct { ID int \`json:"id"\` CreatedAt time.Time \`json:"created\_at"\` } More control[](https://docs.sqlc.dev/en/stable/howto/structs.html#more-control "Link to this heading") -------------------------------------------------------------------------------------------------------- See the guide to [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for fine-grained control over struct field types and tags. --- # Configuring generated structs — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Configuring generated structs * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/structs.md.txt) * * * Configuring generated structs[](https://docs.sqlc.dev/en/v1.31.0/howto/structs.html#configuring-generated-structs "Link to this heading") =========================================================================================================================================== Naming scheme[](https://docs.sqlc.dev/en/v1.31.0/howto/structs.html#naming-scheme "Link to this heading") ----------------------------------------------------------------------------------------------------------- Structs generated from tables will attempt to use the singular form of a table name if the table name is pluralized. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL ); package db // Struct names use the singular form of table names type Author struct { ID int Name string } JSON tags[](https://docs.sqlc.dev/en/v1.31.0/howto/structs.html#json-tags "Link to this heading") --------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL ); sqlc can generate structs with JSON tags by adding the `emit_json_tags` key to the configuration file as it shows on [configuration reference](https://docs.sqlc.dev/en/v1.31.0/reference/config.html) . The JSON name for a field matches the column name in the database. package db import ( "time" ) type Author struct { ID int \`json:"id"\` CreatedAt time.Time \`json:"created\_at"\` } More control[](https://docs.sqlc.dev/en/v1.31.0/howto/structs.html#more-control "Link to this heading") --------------------------------------------------------------------------------------------------------- See the guide to [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for fine-grained control over struct field types and tags. --- # Configuring generated structs — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Configuring generated structs * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/structs.md.txt) * * * Configuring generated structs[](https://docs.sqlc.dev/en/v1.31.1/howto/structs.html#configuring-generated-structs "Link to this heading") =========================================================================================================================================== Naming scheme[](https://docs.sqlc.dev/en/v1.31.1/howto/structs.html#naming-scheme "Link to this heading") ----------------------------------------------------------------------------------------------------------- Structs generated from tables will attempt to use the singular form of a table name if the table name is pluralized. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL ); package db // Struct names use the singular form of table names type Author struct { ID int Name string } JSON tags[](https://docs.sqlc.dev/en/v1.31.1/howto/structs.html#json-tags "Link to this heading") --------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL ); sqlc can generate structs with JSON tags by adding the `emit_json_tags` key to the configuration file as it shows on [configuration reference](https://docs.sqlc.dev/en/v1.31.1/reference/config.html) . The JSON name for a field matches the column name in the database. package db import ( "time" ) type Author struct { ID int \`json:"id"\` CreatedAt time.Time \`json:"created\_at"\` } More control[](https://docs.sqlc.dev/en/v1.31.1/howto/structs.html#more-control "Link to this heading") --------------------------------------------------------------------------------------------------------- See the guide to [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for fine-grained control over struct field types and tags. --- # Managed databases — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Managed databases * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/managed-databases.md.txt) * * * Managed databases[](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html#managed-databases "Link to this heading") ============================================================================================================================= _Added in v1.22.0_ `sqlc` can automatically create read-only databases to power query analysis, linting and verification. These databases are immediately useful for powering sqlc’s database-connected query analyzer, an opt-in feature that improves upon sqlc’s built-in query analysis engine. PostgreSQL support is available today, with MySQL on the way. Once configured, `sqlc` will also use managed databases when linting queries with [`sqlc vet`](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html) in cases where your lint rules require a connection to a running database. Managed databases are under active development, and we’re interested in supporting other use-cases. Configuring managed databases[](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html#configuring-managed-databases "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------- To configure `sqlc` to use managed databases, remove the `uri` key from your `database` configuration and replace it with the `managed` key set to `true`. Access to a running database server is required. Add a connection string to the `servers` mapping. version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true An environment variable can also be used via the `${}` syntax. version: '2' servers: \- engine: postgresql uri: ${DATABASE\_URI} sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true Improving codegen[](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html#improving-codegen "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------- Without a database connection, sqlc does its best to parse, analyze and compile your queries just using the schema you pass it and what it knows about the various database engines it supports. In many cases this works just fine, but for more advanced queries sqlc might not have enough information to produce good code. With managed databases configured, `sqlc generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future codegen runs. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true gen: go: out: "db" Linting queries[](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html#linting-queries "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- With managed databases configured, `sqlc vet` will automatically create a hosted ephemeral database with your schema and use that database when running lint rules that require a database connection, e.g. any [rule relying on `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#rules-using-explain-output) . If you don’t yet have any vet rules, the [built-in sqlc/db-prepare rule](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#sqlc-db-prepare) is a good place to start. It prepares each of your queries against the database to ensure the query is valid. Here’s a minimal working configuration: version: '2' servers: \- engine: postgresql uri: "postgres://localhost:5432/postgres?sslmode=disable" sql: \- schema: schema.sql queries: query.sql engine: postgresql database: managed: true rules: \- sqlc/db-prepare --- # Naming parameters — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Naming parameters * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/named_parameters.md.txt) * * * Naming parameters[](https://docs.sqlc.dev/en/v1.31.1/howto/named_parameters.html#naming-parameters "Link to this heading") ============================================================================================================================ sqlc tries to generate good names for positional parameters, but sometimes it lacks enough context. The following SQL generates parameters with less than ideal names: \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN $1::bool THEN $2::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { Column1 bool \`json:""\` Column2\_2 string \`json:"\_2"\` } In these cases, named parameters give you the control over field names on the Params struct. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN sqlc.arg(set\_name)::bool THEN sqlc.arg(name)::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { SetName bool \`json:"set\_name"\` Name string \`json:"name"\` } If the `sqlc.arg()` syntax is too verbose for your taste, you can use the `@` operator as a shortcut. Note The `@` operator as a shortcut for `sqlc.arg()` is not supported in MySQL. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN @set\_name::bool THEN @name::text ELSE name END RETURNING \*; Nullable parameters[](https://docs.sqlc.dev/en/v1.31.1/howto/named_parameters.html#nullable-parameters "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------- sqlc infers the nullability of any specified parameters, and often does exactly what you want. If you want finer control over the nullability of your parameters, you may use `sqlc.narg()` (**n**ullable arg) to override the default behavior. Using `sqlc.narg` tells sqlc to ignore whatever nullability it has inferred and generate a nullable parameter instead. There is no nullable equivalent of the `@` syntax. Here is an example that uses a single query to allow updating an author’s name, bio or both. \-- name: UpdateAuthor :one UPDATE author SET name \= coalesce(sqlc.narg('name'), name), bio \= coalesce(sqlc.narg('bio'), bio) WHERE id \= sqlc.arg('id') RETURNING \*; The following code is generated: type UpdateAuthorParams struct { Name sql.NullString Bio sql.NullString ID int64 } --- # Renaming fields — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Renaming fields * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/rename.md.txt) * * * Renaming fields[](https://docs.sqlc.dev/en/v1.31.1/howto/rename.html#renaming-fields "Link to this heading") ============================================================================================================== Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "2" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" rename: spotify\_url: "SpotifyURL" Tables[](https://docs.sqlc.dev/en/v1.31.1/howto/rename.html#tables "Link to this heading") -------------------------------------------------------------------------------------------- The output structs associated with tables can also be renamed. By default, the struct name will be the singular version of the table name. For example, the `authors` table will generate an `Author` struct and the `book_publishers` table will generate a `BookPublisher` struct. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); CREATE TABLE book\_publishers ( id BIGSERIAL PRIMARY KEY, name text NOT NULL ); package db import ( "database/sql" ) type Author struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } To rename these structs, you must use the generated struct name. In this example, that would be `author` and `book_publisher`. Use the `rename` map to change the name of these struct to `Writer` and `BookPublisher` (note the camel-casing and the underscore for multi-worded tables). version: '1' packages: \- path: db engine: postgresql schema: query.sql queries: query.sql rename: author: Writer book\_publisher: Publisher version: "2" sql: \- engine: postgresql queries: query.sql schema: query.sql overrides: go: rename: author: Writer book\_publisher: Publisher package db import ( "database/sql" ) type Writer struct { ID int64 Name string Bio sql.NullString } type Publisher struct { ID int64 Name string } Limitations[](https://docs.sqlc.dev/en/v1.31.1/howto/rename.html#limitations "Link to this heading") ------------------------------------------------------------------------------------------------------ Rename mappings apply to an entire package. Therefore, a column named `foo` and a table name `foo` can’t map to different rename values. --- # push - Uploading projects — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * `push` - Uploading projects * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/push.md.txt) * * * `push` - Uploading projects[](https://docs.sqlc.dev/en/v1.30.0/howto/push.html#push-uploading-projects "Link to this heading") ================================================================================================================================ Note `push` is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. _Added in v1.24.0_ We’ve renamed the `upload` sub-command to `push`. We’ve also changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. Add configuration[](https://docs.sqlc.dev/en/v1.30.0/howto/push.html#add-configuration "Link to this heading") ---------------------------------------------------------------------------------------------------------------- After creating a project, add the project ID to your sqlc configuration file. version: "2" cloud: project: "" You’ll also need to create an auth token and make it available via the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Dry run[](https://docs.sqlc.dev/en/v1.30.0/howto/push.html#dry-run "Link to this heading") -------------------------------------------------------------------------------------------- You can see what’s included when uploading your project by using using the `--dry-run` flag: $ sqlc push \--dry-run 2023/11/21 10:39:51 INFO config file\=sqlc.yaml bytes\=912 2023/11/21 10:39:51 INFO codegen\_request queryset\=app file\=codegen\_request.pb 2023/11/21 10:39:51 INFO schema queryset\=app file\=migrations/00001\_initial.sql bytes\=3033 2023/11/21 10:39:51 INFO query queryset\=app file\=queries/app.sql bytes\=1150 The output is the files `sqlc` would have sent without the `--dry-run` flag. Push[](https://docs.sqlc.dev/en/v1.30.0/howto/push.html#push "Link to this heading") -------------------------------------------------------------------------------------- Once you’re ready to push, remove the `--dry-run` flag. $ sqlc push ### Tags[](https://docs.sqlc.dev/en/v1.30.0/howto/push.html#tags "Link to this heading") You can provide tags to associate with a push, primarily as a convenient reference when using `sqlc verify` with the `against` argument. Tags only refer to a single push, so if you pass an existing tag to `push` it will overwrite the previous reference. $ sqlc push \--tag main ### Annotations[](https://docs.sqlc.dev/en/v1.30.0/howto/push.html#annotations "Link to this heading") Annotations are added to each push request. By default, we include these environment variables (if they are present). GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA --- # Counting rows — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Counting rows * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/query_count.md.txt) * * * Counting rows[](https://docs.sqlc.dev/en/v1.30.0/howto/query_count.html#counting-rows "Link to this heading") =============================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, hometown text NOT NULL ); \-- name: CountAuthors :one SELECT count(\*) FROM authors; \-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1; package db import ( "context" "database/sql" ) type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const countAuthors \= \`-- name: CountAuthors :one SELECT count(\*) FROM authors \` func (q \*Queries) CountAuthors(ctx context.Context) (int, error) { row := q.db.QueryRowContext(ctx, countAuthors) var i int err := row.Scan(&i) return i, err } const countAuthorsByTown \= \`-- name: CountAuthorsByTown :many SELECT hometown, count(\*) FROM authors GROUP BY 1 ORDER BY 1 \` type CountAuthorsByTownRow struct { Hometown string Count int } func (q \*Queries) CountAuthorsByTown(ctx context.Context) (\[\]CountAuthorsByTownRow, error) { rows, err := q.db.QueryContext(ctx, countAuthorsByTown) if err != nil { return nil, err } defer rows.Close() items := \[\]CountAuthorsByTownRow{} for rows.Next() { var i CountAuthorsByTownRow if err := rows.Scan(&i.Hometown, &i.Count); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Updating rows — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Updating rows * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/update.md.txt) * * * Updating rows[](https://docs.sqlc.dev/en/v1.30.0/howto/update.html#updating-rows "Link to this heading") ========================================================================================================== CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL ); Single parameter[](https://docs.sqlc.dev/en/v1.30.0/howto/update.html#single-parameter "Link to this heading") ---------------------------------------------------------------------------------------------------------------- If your query has a single parameter, your Go method will also have a single parameter. The parameter syntax varies by database engine: **PostgreSQL:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= $1; **MySQL and SQLite:** \-- name: UpdateAuthorBios :exec UPDATE authors SET bio \= ?; package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthorBios \= \`-- name: UpdateAuthorBios :exec UPDATE authors SET bio = $1 \` func (q \*Queries) UpdateAuthorBios(ctx context.Context, bio string) error { \_, err := q.db.ExecContext(ctx, updateAuthorBios, bio) return err } Multiple parameters[](https://docs.sqlc.dev/en/v1.30.0/howto/update.html#multiple-parameters "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- If your query has more than one parameter, your Go method will accept a `Params` struct. **PostgreSQL:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= $2 WHERE id \= $1; **MySQL and SQLite:** \-- name: UpdateAuthor :exec UPDATE authors SET bio \= ? WHERE id \= ?; Note: For MySQL and SQLite, parameters are bound in the order they appear in the query, regardless of the order in the function signature. package db import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const updateAuthor \= \`-- name: UpdateAuthor :exec UPDATE authors SET bio = $2 WHERE id = $1 \` type UpdateAuthorParams struct { ID int32 Bio string } func (q \*Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error { \_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio) return err } --- # Using transactions — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Using transactions * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/transactions.md.txt) * * * Using transactions[](https://docs.sqlc.dev/en/v1.30.0/howto/transactions.html#using-transactions "Link to this heading") ========================================================================================================================== In the code generated by sqlc, the `WithTx` method allows a `Queries` instance to be associated with a transaction. For example, with the following SQL structure: `schema.sql`: CREATE TABLE records ( id SERIAL PRIMARY KEY, counter INT NOT NULL ); `query.sql` \-- name: GetRecord :one SELECT \* FROM records WHERE id \= $1; \-- name: UpdateRecord :exec UPDATE records SET counter \= $2 WHERE id \= $1; And the generated code from sqlc in `db.go`: package tutorial import ( "context" "database/sql" ) type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } You’d use it like this: // Using \`github/lib/pq\` as the driver. func bumpCounter(ctx context.Context, db \*sql.DB, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin() if err != nil { return err } defer tx.Rollback() qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit() } // Using \`github.com/jackc/pgx/v5\` as the driver. func bumpCounter(ctx context.Context, db \*pgx.Conn, queries \*tutorial.Queries, id int32) error { tx, err := db.Begin(ctx) if err != nil { return err } defer tx.Rollback(ctx) qtx := queries.WithTx(tx) r, err := qtx.GetRecord(ctx, id) if err != nil { return err } if err := qtx.UpdateRecord(ctx, tutorial.UpdateRecordParams{ ID: r.ID, Counter: r.Counter + 1, }); err != nil { return err } return tx.Commit(ctx) } --- # Naming parameters — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Naming parameters * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/named_parameters.md.txt) * * * Naming parameters[](https://docs.sqlc.dev/en/v1.30.0/howto/named_parameters.html#naming-parameters "Link to this heading") ============================================================================================================================ sqlc tries to generate good names for positional parameters, but sometimes it lacks enough context. The following SQL generates parameters with less than ideal names: \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN $1::bool THEN $2::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { Column1 bool \`json:""\` Column2\_2 string \`json:"\_2"\` } In these cases, named parameters give you the control over field names on the Params struct. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN sqlc.arg(set\_name)::bool THEN sqlc.arg(name)::text ELSE name END RETURNING \*; type UpdateAuthorNameParams struct { SetName bool \`json:"set\_name"\` Name string \`json:"name"\` } If the `sqlc.arg()` syntax is too verbose for your taste, you can use the `@` operator as a shortcut. Note The `@` operator as a shortcut for `sqlc.arg()` is not supported in MySQL. \-- name: UpsertAuthorName :one UPDATE author SET name \= CASE WHEN @set\_name::bool THEN @name::text ELSE name END RETURNING \*; Nullable parameters[](https://docs.sqlc.dev/en/v1.30.0/howto/named_parameters.html#nullable-parameters "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------- sqlc infers the nullability of any specified parameters, and often does exactly what you want. If you want finer control over the nullability of your parameters, you may use `sqlc.narg()` (**n**ullable arg) to override the default behavior. Using `sqlc.narg` tells sqlc to ignore whatever nullability it has inferred and generate a nullable parameter instead. There is no nullable equivalent of the `@` syntax. Here is an example that uses a single query to allow updating an author’s name, bio or both. \-- name: UpdateAuthor :one UPDATE author SET name \= coalesce(sqlc.narg('name'), name), bio \= coalesce(sqlc.narg('bio'), bio) WHERE id \= sqlc.arg('id') RETURNING \*; The following code is generated: type UpdateAuthorParams struct { Name sql.NullString Bio sql.NullString ID int64 } --- # Using plugins — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Using plugins * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/guides/plugins.md.txt) * * * Using plugins[](https://docs.sqlc.dev/en/v1.30.0/guides/plugins.html#using-plugins "Link to this heading") ============================================================================================================ To use plugins, you must be using [Version 2](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#version-2) of the configuration file. The top-level `plugins` array defines the available plugins. WASM plugins[](https://docs.sqlc.dev/en/v1.30.0/guides/plugins.html#wasm-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------- > WASM plugins are fully sandboxed; they do not have access to the network, filesystem, or environment variables. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: greeter wasm: url: https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm sha256: afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07 sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: greeter options: lang: en-US For a complete working example see the following files: * [sqlc-gen-greeter](https://github.com/sqlc-dev/sqlc-gen-greeter) * A WASM plugin (written in Rust) that outputs a friendly message * [wasm\_plugin\_sqlc\_gen\_greeter](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter) * An example project showing how to use a WASM plugin Process plugins[](https://docs.sqlc.dev/en/v1.30.0/guides/plugins.html#process-plugins "Link to this heading") ---------------------------------------------------------------------------------------------------------------- > Process-based plugins offer minimal security. Only use plugins that you trust. Better yet, only use plugins that you’ve written yourself. In the `codegen` section, the `out` field dictates what directory will contain the new files. The `plugin` key must reference a plugin defined in the top-level `plugins` map. Any `options` are serialized to a string as JSON and passed on to the plugin itself. version: '2' plugins: \- name: jsonb process: cmd: sqlc-gen-json sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: jsonb options: indent: " " filename: codegen.json For a complete working example see the following files: * [sqlc-gen-json](https://github.com/sqlc-dev/sqlc/tree/main/cmd/sqlc-gen-json) * A process-based plugin that serializes the CodeGenRequest to JSON * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json) * An example project showing how to use a process-based plugin * [process\_plugin\_sqlc\_gen\_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_format_json/) * An example project showing how to use a process-based plugin using json Environment variables[](https://docs.sqlc.dev/en/v1.30.0/guides/plugins.html#environment-variables "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- By default, plugins do not inherit access to environment variables. Instead, you can configure access on a per-variable basis. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. --- # Query annotations — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Query annotations * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/query-annotations.md.txt) * * * Query annotations[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#query-annotations "Link to this heading") ================================================================================================================================= sqlc requires each query to have a small comment indicating the name and command. The format of this comment is as follows: \-- name: `:exec`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#exec "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return the error from [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; func (q \*Queries) DeleteAuthor(ctx context.Context, id int64) error { \_, err := q.db.ExecContext(ctx, deleteAuthor, id) return err } `:execresult`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#execresult "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the [sql.Result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execresult DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (sql.Result, error) { return q.db.ExecContext(ctx, deleteAllAuthors) } `:execrows`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#execrows "Link to this heading") ------------------------------------------------------------------------------------------------------------------ The generated method will return the number of affected rows from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: DeleteAllAuthors :execrows DELETE FROM authors; func (q \*Queries) DeleteAllAuthors(ctx context.Context) (int64, error) { \_, err := q.db.ExecContext(ctx, deleteAllAuthors) // ... } `:execlastid`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#execlastid "Link to this heading") ---------------------------------------------------------------------------------------------------------------------- The generated method will return the number generated by the database from the [result](https://golang.org/pkg/database/sql/#Result) returned by [ExecContext](https://golang.org/pkg/database/sql/#DB.ExecContext) . \-- name: InsertAuthor :execlastid INSERT INTO authors (name) VALUES (?); func (q \*Queries) InsertAuthor(ctx context.Context, name string) (int64, error) { \_, err := q.db.ExecContext(ctx, insertAuthor, name) // ... } `:many`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#many "Link to this heading") ---------------------------------------------------------------------------------------------------------- The generated method will return a slice of records via [QueryContext](https://golang.org/pkg/database/sql/#DB.QueryContext) . \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) // ... } `:one`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#one "Link to this heading") -------------------------------------------------------------------------------------------------------- The generated method will return a single record via [QueryRowContext](https://golang.org/pkg/database/sql/#DB.QueryRowContext) . \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; func (q \*Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) // ... } `:batchexec`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#batchexec "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Exec`, that takes a `func(int, error)` parameter, * `Close`, to close the batch operation early. \-- name: DeleteBook :batchexec DELETE FROM books WHERE book\_id \= $1; type DeleteBookBatchResults struct { br pgx.BatchResults ind int } func (q \*Queries) DeleteBook(ctx context.Context, bookID \[\]int32) \*DeleteBookBatchResults { //... } func (b \*DeleteBookBatchResults) Exec(f func(int, error)) { //... } func (b \*DeleteBookBatchResults) Close() error { //... } `:batchmany`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#batchmany "Link to this heading") -------------------------------------------------------------------------------------------------------------------- **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `Query`, that takes a `func(int, []T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: BooksByTitleYear :batchmany SELECT \* FROM books WHERE title \= $1 AND year \= $2; type BooksByTitleYearBatchResults struct { br pgx.BatchResults ind int } type BooksByTitleYearParams struct { Title string \`json:"title"\` Year int32 \`json:"year"\` } func (q \*Queries) BooksByTitleYear(ctx context.Context, arg \[\]BooksByTitleYearParams) \*BooksByTitleYearBatchResults { //... } func (b \*BooksByTitleYearBatchResults) Query(f func(int, \[\]Book, error)) { //... } func (b \*BooksByTitleYearBatchResults) Close() error { //... } `:batchone`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#batchone "Link to this heading") ------------------------------------------------------------------------------------------------------------------ **NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.** The generated method will return a batch object. The batch object will have the following methods: * `QueryRow`, that takes a `func(int, T, error)` parameter, where `T` is your query’s return type * `Close`, to close the batch operation early. \-- name: CreateBook :batchone INSERT INTO books ( author\_id, isbn ) VALUES ( $1, $2 ) RETURNING book\_id, author\_id, isbn type CreateBookBatchResults struct { br pgx.BatchResults ind int } type CreateBookParams struct { AuthorID int32 \`json:"author\_id"\` Isbn string \`json:"isbn"\` } func (q \*Queries) CreateBook(ctx context.Context, arg \[\]CreateBookParams) \*CreateBookBatchResults { //... } func (b \*CreateBookBatchResults) QueryRow(f func(int, Book, error)) { //... } func (b \*CreateBookBatchResults) Close() error { //... } `:copyfrom`[](https://docs.sqlc.dev/en/v1.30.0/reference/query-annotations.html#copyfrom "Link to this heading") ------------------------------------------------------------------------------------------------------------------ \_\_NOTE: This command is driver and package specific, see [how to insert](https://docs.sqlc.dev/en/v1.30.0/howto/insert.html#using-copyfrom) This command is used to insert rows a lot faster than sequential inserts. --- # vet - Linting queries — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * `vet` - Linting queries * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/vet.md.txt) * * * `vet` - Linting queries[](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#vet-linting-queries "Link to this heading") ======================================================================================================================= _Added in v1.19.0_ `sqlc vet` runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.30.0/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, `sqlc vet` will report an error using the given message. Defining lint rules[](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#defining-lint-rules "Link to this heading") ------------------------------------------------------------------------------------------------------------------- Each lint rule’s CEL expression has access to information from your sqlc configuration and queries via variables defined in the following proto messages. message Config { string version \= 1; string engine \= 2 ; repeated string schema \= 3; repeated string queries \= 4; } message Query { // SQL body string sql \= 1; // Name of the query string name \= 2; // One of "many", "one", "exec", etc. string cmd \= 3; // Query parameters, if any repeated Parameter params \= 4; } message Parameter { int32 number \= 1; } In addition to this basic information, when you have a PostgreSQL or MySQL [database connection configured](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database) each CEL expression has access to the output from running `EXPLAIN ...` on your query via the `postgresql.explain` and `mysql.explain` variables. This output is quite complex and depends on the structure of your query but sqlc attempts to parse and provide as much information as it can. See [Rules using `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#rules-using-explain-output) for more information. Here are a few example rules just using the basic configuration and query information available to the CEL expression environment. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Rules using `EXPLAIN ...` output[](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#rules-using-explain-output "Link to this heading") _Added in v1.20.0_ The CEL expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- debug rules: \- name: debug rule: "!has(postgresql.explain)" \# A dummy rule to trigger explain Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with rules that depend on `EXPLAIN ...` output. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. Built-in rules[](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#built-in-rules "Link to this heading") --------------------------------------------------------------------------------------------------------- ### sqlc/db-prepare[](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#sqlc-db-prepare "Link to this heading") When a [database](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database) connection is configured, you can run the built-in `sqlc/db-prepare` rule. This rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with the `sqlc/db-prepare` rule. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. version: 2 cloud: project: "" sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: managed: true rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Running lint rules[](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#running-lint-rules "Link to this heading") ----------------------------------------------------------------------------------------------------------------- When you add the name of a defined rule to the rules list for a [sql package](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#sql) , `sqlc vet` will evaluate that rule against every query in the package. In the example below, two rules are defined but only one is enabled. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-delete rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") ### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. The annotation accepts a list of rules to ignore. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; The rules can also be split across lines. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable sqlc/db-prepare \*/ /\* @sqlc-vet-disable no-pg \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; To skip all rules for a query, you can provide the `@sqlc-vet-disable` annotation without any parameters. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; --- # Datatypes — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Datatypes * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/datatypes.md.txt) * * * Datatypes[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#datatypes "Link to this heading") ========================================================================================================= `sqlc` attempts to make reasonable default choices when mapping internal database types to Go types. Choices for more complex types are described below. If you’re unsatisfied with the default, you can override any type using the [overrides list](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#overrides) in your `sqlc` config file. Arrays[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#arrays "Link to this heading") --------------------------------------------------------------------------------------------------- PostgreSQL [arrays](https://www.postgresql.org/docs/current/arrays.html) are materialized as Go slices. CREATE TABLE places ( name text not null, tags text\[\] ); package db type Place struct { Name string Tags \[\]string } Dates and times[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#dates-and-times "Link to this heading") --------------------------------------------------------------------------------------------------------------------- All date and time types are returned as `time.Time` structs. For null time or date values, the `NullTime` type from `database/sql` is used. The `pgx/v5` sql package uses the appropriate pgx types. For MySQL users relying on `github.com/go-sql-driver/mysql`, ensure that `parseTime=true` is added to your database connection string. CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL DEFAULT NOW(), updated\_at timestamp ); package db import ( "database/sql" "time" ) type Author struct { ID int CreatedAt time.Time UpdatedAt sql.NullTime } Enums[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#enums "Link to this heading") ------------------------------------------------------------------------------------------------- PostgreSQL [enums](https://www.postgresql.org/docs/current/datatype-enum.html) are mapped to an aliased string type. CREATE TYPE status AS ENUM ( 'open', 'closed' ); CREATE TABLE stores ( name text PRIMARY KEY, status status NOT NULL ); package db type Status string const ( StatusOpen Status \= "open" StatusClosed Status \= "closed" ) type Store struct { Name string Status Status } Null[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#null "Link to this heading") ----------------------------------------------------------------------------------------------- For structs, null values are represented using the appropriate type from the `database/sql` or `pgx` package. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text ); package db import ( "database/sql" ) type Author struct { ID int Name string Bio sql.NullString } UUIDs[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#uuids "Link to this heading") ------------------------------------------------------------------------------------------------- The Go standard library does not come with a `uuid` package. For UUID support, sqlc uses the excellent `github.com/google/uuid` package. The pgx/v5 sql package uses `pgtype.UUID`. CREATE TABLE records ( id uuid PRIMARY KEY ); package db import ( "github.com/google/uuid" ) type Author struct { ID uuid.UUID } For MySQL, there is no native `uuid` data type. When using `UUID_TO_BIN` to store a `UUID()`, the underlying field type is `BINARY(16)` which by default sqlc would map to `sql.NullString`. To have sqlc automatically convert these fields to a `uuid.UUID` type, use an overide on the column storing the `uuid` (see [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for details). { "overrides": \[\ {\ "column": "\*.uuid",\ "go\_type": "github.com/google/uuid.UUID"\ }\ \] } JSON[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#json "Link to this heading") ----------------------------------------------------------------------------------------------- By default, sqlc will generate the `[]byte`, `pgtype.JSON` or `json.RawMessage` for JSON column type. But if you use the `pgx/v5` sql package then you can specify a struct instead of the default type (see [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for details). The `pgx` implementation will marshal/unmarshal the struct automatically. package dto type BookData struct { Genres \[\]string \`json:"genres"\` Title string \`json:"title"\` Published bool \`json:"published"\` } CREATE TABLE books ( data jsonb ); { "overrides": \[\ {\ "column": "books.data",\ "go\_type": {\ "import":"example.com/db",\ "package": "dto",\ "type":"BookData",\ "pointer": true\ }\ }\ \] } package db import ( "example.com/db/dto" ) type Book struct { Data \*dto.BookData } TEXT[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#text "Link to this heading") ----------------------------------------------------------------------------------------------- In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a Go string by default. This default mapping applies to `TEXT` columns that are not nullable. However, for nullable `TEXT` columns, sqlc maps them to `pgtype.Text` when using the pgx/v5 driver. This distinction is crucial for developers looking to handle null values appropriately in their Go applications. To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in your sqlc config file (see [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for details). Geometry[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#geometry "Link to this heading") ------------------------------------------------------------------------------------------------------- ### PostGIS[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#postgis "Link to this heading") #### Using `github.com/twpayne/go-geos` (pgx/v5 only)[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#using-github-com-twpayne-go-geos-pgx-v5-only "Link to this heading") sqlc can be configured to use the [geos](https://github.com/twpayne/go-geos) package for working with PostGIS geometry types in [GEOS](https://libgeos.org/) . There are three steps: 1. Configure sqlc to use `*github.com/twpayne/go-geos.Geom` for geometry types (see [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for details). 2. Call `github.com/twpayne/pgx-geos.Register` on each `*github.com/jackc/pgx/v5.Conn`. 3. Annotate your SQL with `::geometry` typecasts, if needed. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetCentroids :many SELECT id, name, ST\_Centroid(geom)::geometry FROM shapes; { "version": 2, "gen": { "go": { "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": {\ "import": "github.com/twpayne/go-geos",\ "package": "geos",\ "pointer": true,\ "type": "Geom"\ },\ "nullable": true\ }\ \] } } } import ( "github.com/twpayne/go-geos" pgxgeos "github.com/twpayne/pgx-geos" ) // ... config.AfterConnect \= func(ctx context.Context, conn \*pgx.Conn) error { if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil { return err } return nil } #### Using `github.com/twpayne/go-geom`[](https://docs.sqlc.dev/en/v1.30.0/reference/datatypes.html#using-github-com-twpayne-go-geom "Link to this heading") sqlc can be configured to use the [geom](https://github.com/twpayne/go-geom) package for working with PostGIS geometry types. See [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for more information. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetShapes :many SELECT \* FROM shapes; { "version": "1", "packages": \[\ {\ "path": "db",\ "engine": "postgresql",\ "schema": "query.sql",\ "queries": "query.sql"\ }\ \], "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon"\ },\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon",\ "nullable": true\ }\ \] } --- # vet - Linting queries — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * `vet` - Linting queries * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/vet.md) * * * `vet` - Linting queries[](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#vet-linting-queries "Link to this heading") ======================================================================================================================= _Added in v1.19.0_ `sqlc vet` runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.27.0/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, `sqlc vet` will report an error using the given message. Defining lint rules[](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#defining-lint-rules "Link to this heading") ------------------------------------------------------------------------------------------------------------------- Each lint rule’s CEL expression has access to information from your sqlc configuration and queries via variables defined in the following proto messages. message Config { string version \= 1; string engine \= 2 ; repeated string schema \= 3; repeated string queries \= 4; } message Query { // SQL body string sql \= 1; // Name of the query string name \= 2; // One of "many", "one", "exec", etc. string cmd \= 3; // Query parameters, if any repeated Parameter params \= 4; } message Parameter { int32 number \= 1; } In addition to this basic information, when you have a PostgreSQL or MySQL [database connection configured](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database) each CEL expression has access to the output from running `EXPLAIN ...` on your query via the `postgresql.explain` and `mysql.explain` variables. This output is quite complex and depends on the structure of your query but sqlc attempts to parse and provide as much information as it can. See [Rules using `EXPLAIN ...` output](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#rules-using-explain-output) for more information. Here are a few example rules just using the basic configuration and query information available to the CEL expression environment. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Rules using `EXPLAIN ...` output[](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#rules-using-explain-output "Link to this heading") _Added in v1.20.0_ The CEL expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- debug rules: \- name: debug rule: "!has(postgresql.explain)" \# A dummy rule to trigger explain Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with rules that depend on `EXPLAIN ...` output. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. Built-in rules[](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#built-in-rules "Link to this heading") --------------------------------------------------------------------------------------------------------- ### sqlc/db-prepare[](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#sqlc-db-prepare "Link to this heading") When a [database](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database) connection is configured, you can run the built-in `sqlc/db-prepare` rule. This rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare Please note that databases configured with a `uri` must have an up-to-date schema for `vet` to work correctly, and `sqlc` does not apply schema migrations to your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc vet` with the `sqlc/db-prepare` rule. Alternatively, configure [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html) to have `sqlc` create hosted ephemeral databases with the correct schema automatically. version: 2 cloud: project: "" sql: \- schema: "schema.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: managed: true rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Running lint rules[](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#running-lint-rules "Link to this heading") ----------------------------------------------------------------------------------------------------------------- When you add the name of a defined rule to the rules list for a [sql package](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#sql) , `sqlc vet` will evaluate that rule against every query in the package. In the example below, two rules are defined but only one is enabled. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-delete rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") ### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; --- # Datatypes — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Datatypes * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/datatypes.md) * * * Datatypes[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#datatypes "Link to this heading") ========================================================================================================= `sqlc` attempts to make reasonable default choices when mapping internal database types to Go types. Choices for more complex types are described below. If you’re unsatisfied with the default, you can override any type using the [overrides list](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#type-overriding) in your `sqlc` config file. Arrays[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#arrays "Link to this heading") --------------------------------------------------------------------------------------------------- PostgreSQL [arrays](https://www.postgresql.org/docs/current/arrays.html) are materialized as Go slices. CREATE TABLE places ( name text not null, tags text\[\] ); package db type Place struct { Name string Tags \[\]string } Dates and times[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#dates-and-times "Link to this heading") --------------------------------------------------------------------------------------------------------------------- All date and time types are returned as `time.Time` structs. For null time or date values, the `NullTime` type from `database/sql` is used. The `pgx/v5` sql package uses the appropriate pgx types. For MySQL users relying on `github.com/go-sql-driver/mysql`, ensure that `parseTime=true` is added to your database connection string. CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL DEFAULT NOW(), updated\_at timestamp ); package db import ( "database/sql" "time" ) type Author struct { ID int CreatedAt time.Time UpdatedAt sql.NullTime } Enums[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#enums "Link to this heading") ------------------------------------------------------------------------------------------------- PostgreSQL [enums](https://www.postgresql.org/docs/current/datatype-enum.html) are mapped to an aliased string type. CREATE TYPE status AS ENUM ( 'open', 'closed' ); CREATE TABLE stores ( name text PRIMARY KEY, status status NOT NULL ); package db type Status string const ( StatusOpen Status \= "open" StatusClosed Status \= "closed" ) type Store struct { Name string Status Status } Null[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#null "Link to this heading") ----------------------------------------------------------------------------------------------- For structs, null values are represented using the appropriate type from the `database/sql` or `pgx` package. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL, bio text ); package db import ( "database/sql" ) type Author struct { ID int Name string Bio sql.NullString } UUIDs[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#uuids "Link to this heading") ------------------------------------------------------------------------------------------------- The Go standard library does not come with a `uuid` package. For UUID support, sqlc uses the excellent `github.com/google/uuid` package. The pgx/v5 sql package uses `pgtype.UUID`. CREATE TABLE records ( id uuid PRIMARY KEY ); package db import ( "github.com/google/uuid" ) type Author struct { ID uuid.UUID } For MySQL, there is no native `uuid` data type. When using `UUID_TO_BIN` to store a `UUID()`, the underlying field type is `BINARY(16)` which by default sqlc would interpret this to `sql.NullString`. To have sqlc automatically convert these fields to a `uuid.UUID` type, use an overide on the column storing the `uuid`. { "overrides": \[\ {\ "column": "\*.uuid",\ "go\_type": "github.com/google/uuid.UUID"\ }\ \] } JSON[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#json "Link to this heading") ----------------------------------------------------------------------------------------------- By default, sqlc will generate the `[]byte`, `pgtype.JSON` or `json.RawMessage` for JSON column type. But if you use the `pgx/v5` sql package then you can specify a some struct instead of default type. The `pgx` implementation will marshall/unmarshall the struct automatically. package dto type BookData struct { Genres \[\]string \`json:"genres"\` Title string \`json:"title"\` Published bool \`json:"published"\` } CREATE TABLE books ( data jsonb ); { "overrides": \[\ {\ "column": "books.data",\ "go\_type": {\ "import":"example/db",\ "package": "dto",\ "type":"BookData"\ }\ }\ \] } package db import ( "example.com/db/dto" ) type Book struct { Data \*dto.BookData } TEXT[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#text "Link to this heading") ----------------------------------------------------------------------------------------------- In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a Go string by default. This default mapping applies to `TEXT` columns that are not nullable. However, for nullable `TEXT` columns, sqlc maps them to `pgtype.Text` when using the pgx/v5 driver. This distinction is crucial for developers looking to handle null values appropriately in their Go applications. To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in you sqlc config file. Geometry[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#geometry "Link to this heading") ------------------------------------------------------------------------------------------------------- ### PostGIS[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#postgis "Link to this heading") #### Using `github.com/twpayne/go-geos` (pgx/v5 only)[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#using-github-com-twpayne-go-geos-pgx-v5-only "Link to this heading") sqlc can be configured to use the [geos](https://github.com/twpayne/go-geos) package for working with PostGIS geometry types in [GEOS](https://libgeos.org/) . There are three steps: 1. Configure sqlc to use `*github.com/twpayne/go-geos.Geom` for geometry types. 2. Call `github.com/twpayne/pgx-geos.Register` on each `*github.com/jackc/pgx/v5.Conn`. 3. Annotate your SQL with `::geometry` typecasts, if needed. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetCentroids :many SELECT id, name, ST\_Centriod(geom)::geometry FROM shapes; { "version": 2, "gen": { "go": { "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": {\ "import": "github.com/twpayne/go-geos",\ "package": "geos",\ "pointer": true,\ "type": "Geom"\ },\ "nullable": true\ }\ \] } } } import ( "github.com/twpayne/go-geos" pgxgeos "github.com/twpayne/pgx-geos" ) // ... config.AfterConnect \= func(ctx context.Context, conn \*pgx.Conn) error { if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil { return err } return nil } #### Using `github.com/twpayne/go-geom`[](https://docs.sqlc.dev/en/v1.27.0/reference/datatypes.html#using-github-com-twpayne-go-geom "Link to this heading") sqlc can be configured to use the [geom](https://github.com/twpayne/go-geom) package for working with PostGIS geometry types. \-- Multipolygons in British National Grid (epsg:27700) create table shapes( id serial, name varchar, geom geometry(Multipolygon, 27700) ); \-- name: GetShapes :many SELECT \* FROM shapes; { "version": "1", "packages": \[\ {\ "path": "db",\ "engine": "postgresql",\ "schema": "query.sql",\ "queries": "query.sql"\ }\ \], "overrides": \[\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon"\ },\ {\ "db\_type": "geometry",\ "go\_type": "github.com/twpayne/go-geom.MultiPolygon",\ "null": true\ }\ \] } --- # Configuring generated structs — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Configuring generated structs * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/structs.md.txt) * * * Configuring generated structs[](https://docs.sqlc.dev/en/v1.30.0/howto/structs.html#configuring-generated-structs "Link to this heading") =========================================================================================================================================== Naming scheme[](https://docs.sqlc.dev/en/v1.30.0/howto/structs.html#naming-scheme "Link to this heading") ----------------------------------------------------------------------------------------------------------- Structs generated from tables will attempt to use the singular form of a table name if the table name is pluralized. CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text NOT NULL ); package db // Struct names use the singular form of table names type Author struct { ID int Name string } JSON tags[](https://docs.sqlc.dev/en/v1.30.0/howto/structs.html#json-tags "Link to this heading") --------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, created\_at timestamp NOT NULL ); sqlc can generate structs with JSON tags by adding the `emit_json_tags` key to the configuration file as it shows on [configuration reference](https://docs.sqlc.dev/en/v1.30.0/reference/config.html) . The JSON name for a field matches the column name in the database. package db import ( "time" ) type Author struct { ID int \`json:"id"\` CreatedAt time.Time \`json:"created\_at"\` } More control[](https://docs.sqlc.dev/en/v1.30.0/howto/structs.html#more-control "Link to this heading") --------------------------------------------------------------------------------------------------------- See the guide to [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for fine-grained control over struct field types and tags. --- # Database and language support — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Database and language support * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/language-support.rst.txt) * * * Database and language support[](https://docs.sqlc.dev/en/latest/reference/language-support.html#database-and-language-support "Link to this heading") ======================================================================================================================================================= | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Go | (built-in) | Stable | Stable | Beta | | Go | [sqlc-gen-go](https://github.com/sqlc-dev/sqlc-gen-go) | Stable | Stable | Beta | | Kotlin | [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) | Beta | Beta | Not implemented | | Python | [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) | Beta | Beta | Not implemented | | TypeScript | [sqlc-gen-typescript](https://github.com/sqlc-dev/sqlc-gen-typescript) | Beta | Beta | Not implemented | Community language support[](https://docs.sqlc.dev/en/latest/reference/language-support.html#community-language-support "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------- New languages can be added via [plugins](https://docs.sqlc.dev/en/latest/guides/plugins.html) . | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | C# | [DaredevilOSS/sqlc-gen-csharp](https://github.com/DaredevilOSS/sqlc-gen-csharp) | Stable | Stable | Stable | | F# | [kaashyapan/sqlc-gen-fsharp](https://github.com/kaashyapan/sqlc-gen-fsharp) | N/A | Beta | Beta | | Java | [tandemdude/sqlc-gen-java](https://github.com/tandemdude/sqlc-gen-java) | Beta | Beta | N/A | | PHP | [lcarilla/sqlc-plugin-php-dbal](https://github.com/lcarilla/sqlc-plugin-php-dbal) | Beta | N/A | N/A | | Ruby | [DaredevilOSS/sqlc-gen-ruby](https://github.com/DaredevilOSS/sqlc-gen-ruby) | Beta | Beta | Beta | | Zig | [tinyzimmer/sqlc-gen-zig](https://github.com/tinyzimmer/sqlc-gen-zig) | N/A | Beta | Beta | | Python | [rayakame/sqlc-gen-better-python](https://github.com/rayakame/sqlc-gen-better-python) | N/A | Beta | Beta | | Rust | [mathematic-inc/sqlc-gen-sqlx](https://github.com/mathematic-inc/sqlc-gen-sqlx) | N/A | Beta | N/A | | \[Any\] | [fdietze/sqlc-gen-from-template](https://github.com/fdietze/sqlc-gen-from-template) | Stable | Stable | Stable | Plugins developed by our Community can also be found using our [github topic](https://github.com/topics/sqlc-plugin) . Community projects[](https://docs.sqlc.dev/en/latest/reference/language-support.html#community-projects "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------- | Language | Project | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Gleam | [daniellionel01/parrot](https://github.com/daniellionel01/parrot) | Stable | Stable | Stable | --- # Database and language support — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Database and language support * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/language-support.rst.txt) * * * Database and language support[](https://docs.sqlc.dev/en/v1.30.0/reference/language-support.html#database-and-language-support "Link to this heading") ======================================================================================================================================================== | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Go | (built-in) | Stable | Stable | Beta | | Go | [sqlc-gen-go](https://github.com/sqlc-dev/sqlc-gen-go) | Stable | Stable | Beta | | Kotlin | [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) | Beta | Beta | Not implemented | | Python | [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) | Beta | Beta | Not implemented | | TypeScript | [sqlc-gen-typescript](https://github.com/sqlc-dev/sqlc-gen-typescript) | Beta | Beta | Not implemented | Community language support[](https://docs.sqlc.dev/en/v1.30.0/reference/language-support.html#community-language-support "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------- New languages can be added via [plugins](https://docs.sqlc.dev/en/v1.30.0/guides/plugins.html) . | Language | Plugin | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | C# | [DaredevilOSS/sqlc-gen-csharp](https://github.com/DaredevilOSS/sqlc-gen-csharp) | Stable | Stable | Stable | | F# | [kaashyapan/sqlc-gen-fsharp](https://github.com/kaashyapan/sqlc-gen-fsharp) | N/A | Beta | Beta | | Java | [tandemdude/sqlc-gen-java](https://github.com/tandemdude/sqlc-gen-java) | Beta | Beta | N/A | | PHP | [lcarilla/sqlc-plugin-php-dbal](https://github.com/lcarilla/sqlc-plugin-php-dbal) | Beta | N/A | N/A | | Ruby | [DaredevilOSS/sqlc-gen-ruby](https://github.com/DaredevilOSS/sqlc-gen-ruby) | Beta | Beta | Beta | | Zig | [tinyzimmer/sqlc-gen-zig](https://github.com/tinyzimmer/sqlc-gen-zig) | N/A | Beta | Beta | | \[Any\] | [fdietze/sqlc-gen-from-template](https://github.com/fdietze/sqlc-gen-from-template) | Stable | Stable | Stable | Community projects[](https://docs.sqlc.dev/en/v1.30.0/reference/language-support.html#community-projects "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------- | Language | Project | MySQL | PostgreSQL | SQLite | | --- | --- | --- | --- | --- | | Gleam | [daniellionel01/parrot](https://github.com/daniellionel01/parrot) | Stable | Stable | Stable | --- # Environment variables — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Environment variables * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/environment-variables.md.txt) * * * Environment variables[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#environment-variables "Link to this heading") ============================================================================================================================================= SQLCCACHE[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#sqlccache "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCCACHE` environment variable dictates where `sqlc` will store cached WASM-based plugins and modules. By default `sqlc` follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) . SQLCDEBUG[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#sqlcdebug "Link to this heading") --------------------------------------------------------------------------------------------------------------------- The `SQLCDEBUG` variable controls debugging variables within the runtime. It is a comma-separated list of name=val pairs settings. ### dumpast[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#dumpast "Link to this heading") The `dumpast` command shows the SQL AST that was generated by the parser. Note that this is the generic SQL AST, not the engine-specific SQL AST. SQLCDEBUG\=dumpast\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc0004f48c0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc0004f4930)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc00052ff20)({ Rel: (\*ast.TableName)(0xc00052fda0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### dumpcatalog[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#dumpcatalog "Link to this heading") The `dumpcatalog` command outputs the entire catalog. If you’re using MySQL or PostgreSQL, this can be a bit overwhelming. Expect this output to change in future versions. SQLCDEBUG\=dumpcatalog\=1 (\[\]interface {}) (len\=1 cap\=1) { (\*catalog.Catalog)(0xc00050d1f0)({ Comment: (string) "", DefaultSchema: (string) (len\=6) "public", Name: (string) "", Schemas: (\[\]\*catalog.Schema) (len\=3 cap\=4) { (\*catalog.Schema)(0xc00050d260)({ Name: (string) (len\=6) "public", Tables: (\[\]\*catalog.Table) (len\=1 cap\=1) { (\*catalog.Table)(0xc0000c0840)({ Rel: (\*ast.TableName)(0xc0000c06c0)({ Catalog: (string) "", Schema: (string) "", Name: (string) (len\=7) "authors" }), ### trace[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#trace "Link to this heading") The `trace` command is helpful for tracking down performance issues. `SQLCDEBUG=trace=1` By default, the trace output is written to `trace.out` in the current working directory. You can configure a different path if needed. `SQLCDEBUG=trace=name.out` View the execution trace using the Go `trace` tool. go tool trace trace.out There’s a ton of different views for the trace output, but here’s an example log showing the execution time for each package. 0.000043897 . 1 task sqlc (id 1, parent 0) created 0.000144923 . 101026 1 region generate started (duration: 47.619781ms) 0.001048975 . 904052 1 region package started (duration: 14.588456ms) 0.001054616 . 5641 1 name\=authors dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.001071257 . 16641 1 region parse started (duration: 7.966549ms) 0.009043960 . 7972703 1 region codegen started (duration: 6.587086ms) 0.009171704 . 127744 1 new goroutine 35: text/template/parse.lex·dwrap·1 0.010361654 . 1189950 1 new goroutine 36: text/template/parse.lex·dwrap·1 0.015641815 . 5280161 1 region package started (duration: 10.904938ms) 0.015644943 . 3128 1 name\=booktest dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.015647431 . 2488 1 region parse started (duration: 4.207749ms) 0.019860308 . 4212877 1 region codegen started (duration: 6.681624ms) 0.020028488 . 168180 1 new goroutine 37: text/template/parse.lex·dwrap·1 0.021020310 . 991822 1 new goroutine 8: text/template/parse.lex·dwrap·1 0.026551163 . 5530853 1 region package started (duration: 9.217294ms) 0.026554368 . 3205 1 name\=jets dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.026556804 . 2436 1 region parse started (duration: 3.491005ms) 0.030051911 . 3495107 1 region codegen started (duration: 5.711931ms) 0.030213937 . 162026 1 new goroutine 20: text/template/parse.lex·dwrap·1 0.031099938 . 886001 1 new goroutine 38: text/template/parse.lex·dwrap·1 0.035772637 . 4672699 1 region package started (duration: 10.267039ms) 0.035775688 . 3051 1 name\=ondeck dir\=/Users/kyle/projects/sqlc/examples/python language\=python 0.035778150 . 2462 1 region parse started (duration: 4.094518ms) 0.039877181 . 4099031 1 region codegen started (duration: 6.156341ms) 0.040010771 . 133590 1 new goroutine 39: text/template/parse.lex·dwrap·1 0.040894567 . 883796 1 new goroutine 40: text/template/parse.lex·dwrap·1 0.046042779 . 5148212 1 region writefiles started (duration: 1.718259ms) 0.047767781 . 1725002 1 task end ### processplugins[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#processplugins "Link to this heading") Setting this value to `0` disables process-based plugins. If a process-based plugin is declared in the configuration file, running any `sqlc` command will return an error. `SQLCDEBUG=processplugins=0` ### dumpvetenv[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#dumpvetenv "Link to this heading") The `dumpvetenv` command prints the variables available to a `sqlc vet` rule during evaluation. `SQLCDEBUG=dumpvetenv=1` ### dumpexplain[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#dumpexplain "Link to this heading") The `dumpexplain` command prints the JSON-formatted result from running `EXPLAIN ...` on a query when a `sqlc vet` rule evaluation requires its output. `SQLCDEBUG=dumpexplain=1` SQLCTMPDIR[](https://docs.sqlc.dev/en/v1.30.0/reference/environment-variables.html#sqlctmpdir "Link to this heading") ----------------------------------------------------------------------------------------------------------------------- If specified, use the given directory as the base for temporary folders. Only applies when using WASM-based codegen plugins. When not specified, this defaults to passing an empty string to [`os.MkdirTemp`](https://pkg.go.dev/os#MkdirTemp) . --- # Getting started with PostgreSQL — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Getting started with PostgreSQL * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/tutorials/getting-started-postgresql.md.txt) * * * Getting started with PostgreSQL[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-postgresql.html#getting-started-with-postgresql "Link to this heading") ====================================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.31.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.31.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-postgresql.html#setting-up "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app`: go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Schema and queries[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-postgresql.html#schema-and-queries "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1 RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-postgresql.html#generating-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-postgresql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------ You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "log" "reflect" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() conn, err := pgx.Connect(ctx, "user=pqgotest dbname=pqgotest sslmode=verify-full") if err != nil { return err } defer conn.Close(ctx) queries := tutorial.New(conn) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant PostgreSQL driver. You can use `lib/pq` with the standard library’s `database/sql` package, but in this tutorial we’ve used `pgx/v5`: go get github.com/jackc/pgx/v5 go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `pgx.Connect()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.31.0/tutorials/getting-started-postgresql.html#query-verification "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial In the sidebar, go to the “Queries” section to see your published queries. Run `verify` to ensure that previously published queries continue to work against updated database schema. $ sqlc verify \--against tutorial --- # Getting started with PostgreSQL — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/index.html) * Getting started with PostgreSQL * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/tutorials/getting-started-postgresql.md.txt) * * * Getting started with PostgreSQL[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-postgresql.html#getting-started-with-postgresql "Link to this heading") ====================================================================================================================================================================== This tutorial assumes that the latest version of sqlc is [installed](https://docs.sqlc.dev/en/v1.29.0/overview/install.html) and ready to use. We’ll generate Go code here, but other [language plugins](https://docs.sqlc.dev/en/v1.29.0/reference/language-support.html) are available. You’ll naturally need the Go toolchain if you want to build and run a program with the code sqlc generates, but sqlc itself has no dependencies. At the end, you’ll push your SQL queries to [sqlc Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. Setting up[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-postgresql.html#setting-up "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------- Create a new directory called `sqlc-tutorial` and open it up. Initialize a new Go module named `tutorial.sqlc.dev/app`: go mod init tutorial.sqlc.dev/app sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Schema and queries[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-postgresql.html#schema-and-queries "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- sqlc needs to know your database schema and queries in order to generate code. In the same directory, create a file named `schema.sql` with the following content: CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); Next, create a `query.sql` file with the following five queries: \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: UpdateAuthor :exec UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; If you prefer, you can alter the `UpdateAuthor` query to return the updated record: \-- name: UpdateAuthor :one UPDATE authors set name \= $2, bio \= $3 WHERE id \= $1 RETURNING \*; Generating code[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-postgresql.html#generating-code "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------- You are now ready to generate code. You shouldn’t see any output when you run the `generate` subcommand, unless something goes wrong: sqlc generate You should now have a `tutorial` subdirectory with three files containing Go source code. These files comprise a Go package named `tutorial`: ├── go.mod ├── query.sql ├── schema.sql ├── sqlc.yaml └── tutorial ├── db.go ├── models.go └── query.sql.go Using generated code[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-postgresql.html#using-generated-code "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------ You can use your newly-generated `tutorial` package from any Go program. Create a file named `tutorial.go` and add the following contents: package main import ( "context" "log" "reflect" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "tutorial.sqlc.dev/app/tutorial" ) func run() error { ctx := context.Background() conn, err := pgx.Connect(ctx, "user=pqgotest dbname=pqgotest sslmode=verify-full") if err != nil { return err } defer conn.Close(ctx) queries := tutorial.New(conn) // list all authors authors, err := queries.ListAuthors(ctx) if err != nil { return err } log.Println(authors) // create an author insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{ Name: "Brian Kernighan", Bio: pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, }) if err != nil { return err } log.Println(insertedAuthor) // get the author we just inserted fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) if err != nil { return err } // prints true log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor)) return nil } func main() { if err := run(); err != nil { log.Fatal(err) } } Before this code will compile you’ll need to fetch the relevant PostgreSQL driver. You can use `lib/pq` with the standard library’s `database/sql` package, but in this tutorial we’ve used `pgx/v5`: go get github.com/jackc/pgx/v5 go build ./... The program should compile without errors. To make that possible, sqlc generates readable, **idiomatic** Go code that you otherwise would’ve had to write yourself. Take a look in `tutorial/query.sql.go`. Of course for this program to run successfully you’ll need to compile after replacing the database connection parameters in the call to `pgx.Connect()` with the correct parameters for your database. And your database must have the `authors` table as defined in `schema.sql`. You should now have a working program using sqlc’s generated Go source code, and hopefully can see how you’d use sqlc in your own real-world applications. Query verification[](https://docs.sqlc.dev/en/v1.29.0/tutorials/getting-started-postgresql.html#query-verification "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------- [sqlc Cloud](https://dashboard.sqlc.dev/) provides additional verification, catching subtle bugs. To get started, create a [dashboard account](https://dashboard.sqlc.dev/) . Once you’ve signed in, create a project and generate an auth token. Add your project’s ID to the `cloud` block to your sqlc.yaml. version: "2" cloud: \# Replace with your project ID from the sqlc Cloud dashboard project: "" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" Replace `` with your project ID from the sqlc Cloud dashboard. It will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. And finally, set the `SQLC_AUTH_TOKEN` environment variable: export SQLC\_AUTH\_TOKEN\="" $ sqlc push \--tag tutorial In the sidebar, go to the “Queries” section to see your published queries. Run `verify` to ensure that previously published queries continue to work against updated database schema. $ sqlc verify \--against tutorial --- # Using Go and pgx — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Using Go and pgx * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/guides/using-go-and-pgx.rst.txt) * * * Using Go and pgx[](https://docs.sqlc.dev/en/v1.30.0/guides/using-go-and-pgx.html#using-go-and-pgx "Link to this heading") =========================================================================================================================== Note `pgx/v5` is supported starting from v1.18.0. pgx is a pure Go driver and toolkit for PostgreSQL. It’s become the default PostgreSQL package for many Gophers since lib/pq was put into maintenance mode. Getting started[](https://docs.sqlc.dev/en/v1.30.0/guides/using-go-and-pgx.html#getting-started "Link to this heading") ------------------------------------------------------------------------------------------------------------------------- To start generating code that uses pgx, set the `sql_package` field in your `sqlc.yaml` configuration file. Valid options are `pgx/v4` or `pgx/v5` version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "query.sql" gen: go: package: "db" sql\_package: "pgx/v5" out: "db" If you don’t have an existing sqlc project on hand, create a directory with the configuration file above and the following `query.sql` file. CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1 LIMIT 1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY name; \-- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( $1, $2 ) RETURNING \*; \-- name: DeleteAuthor :exec DELETE FROM authors WHERE id \= $1; Generating the code will now give you pgx-compatible database access methods. sqlc generate Generated code walkthrough[](https://docs.sqlc.dev/en/v1.30.0/guides/using-go-and-pgx.html#generated-code-walkthrough "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------- The generated code is very similar to the code generated when using `lib/pq`. However, instead of using `database/sql`, the code uses pgx types directly. package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v5" "example.com/sqlc-tutorial/db" ) func main() { // urlExample := "postgres://username:password@localhost:5432/database\_name" conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\\n", err) os.Exit(1) } defer conn.Close(context.Background()) q := db.New(conn) author, err := q.GetAuthor(context.Background(), 1) if err != nil { fmt.Fprintf(os.Stderr, "GetAuthor failed: %v\\n", err) os.Exit(1) } fmt.Println(author.Name) } Note For production applications, consider using pgxpool for connection pooling: import ( "github.com/jackc/pgx/v5/pgxpool" "example.com/sqlc-tutorial/db" ) func main() { pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE\_URL")) if err != nil { fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\\n", err) os.Exit(1) } defer pool.Close() q := db.New(pool) // Use q the same way as with single connections } --- # verify - Verifying schema changes — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/index.html) * `verify` - Verifying schema changes * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/howto/verify.md.txt) * * * `verify` - Verifying schema changes[](https://docs.sqlc.dev/en/v1.29.0/howto/verify.html#verify-verifying-schema-changes "Link to this heading") ================================================================================================================================================== _Added in v1.24.0_ Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. Using `verify` requires that you push your queries and schema when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. Authentication[](https://docs.sqlc.dev/en/v1.29.0/howto/verify.html#authentication "Link to this heading") ------------------------------------------------------------------------------------------------------------ `sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . export SQLC\_AUTH\_TOKEN\=sqlc\_xxxxxxxx Expected workflow[](https://docs.sqlc.dev/en/v1.29.0/howto/verify.html#expected-workflow "Link to this heading") ------------------------------------------------------------------------------------------------------------------ Using `sqlc verify` requires pushing your queries and schema to sqlc Cloud. When you release a new version of your application, you should push your schema and queries as well. For example, we run `sqlc push` after any change has been merged into our `main` branch on Github, as we deploy every commit to production. $ sqlc push \--tag main Locally or in pull requests, run `sqlc verify` to check that existing queries continue to work with your current database schema. $ sqlc verify \--against main Picking a tag[](https://docs.sqlc.dev/en/v1.29.0/howto/verify.html#picking-a-tag "Link to this heading") ---------------------------------------------------------------------------------------------------------- Without an `against` argument, `verify` will run its analysis of the provided schema using your most-recently pushed queries. We suggest using the `against` argument to explicitly select a set of queries for comparison. $ sqlc verify \--against \[tag\] --- # Retrieving rows — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Retrieving rows * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/select.md.txt) * * * Retrieving rows[](https://docs.sqlc.dev/en/v1.30.0/howto/select.html#retrieving-rows "Link to this heading") ============================================================================================================== To generate a database access method, annotate a query with a specific comment. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; **MySQL and SQLite:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ?; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; A few new pieces of code are generated beyond the `Author` struct. An interface for the underlying database is generated. The `*sql.DB` and `*sql.Tx` types satisfy this interface. The database access methods are added to a `Queries` struct, which is created using the `New` method. Note that the `*` in our query has been replaced with explicit column names. This change ensures that the query will never return unexpected data. Our query was annotated with `:one`, meaning that it should only return a single row. We scan the data from that one into a `Author` struct. Since the get query has a single parameter, the `GetAuthor` method takes a single `int` as an argument. Since the list query has no parameters, the `ListAuthors` method accepts no arguments. package db import ( "context" "database/sql" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getAuthor \= \`-- name: GetAuthor :one SELECT id, bio, birth\_year FROM authors WHERE id = $1 \` func (q \*Queries) GetAuthor(ctx context.Context, id int) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) var i Author err := row.Scan(&i.ID, &i.Bio, &i.BirthYear) return i, err } const listAuthors \= \`-- name: ListAuthors :many SELECT id, bio, birth\_year FROM authors ORDER BY id \` func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } Selecting columns[](https://docs.sqlc.dev/en/v1.30.0/howto/select.html#selecting-columns "Link to this heading") ------------------------------------------------------------------------------------------------------------------ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id \= $1; \-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id \= $1; When selecting a single column, only that value is returned. The `GetBioForAuthor` method takes a single `int` as an argument and returns a `string` and an `error`. When selecting multiple columns, a row record (method-specific struct) is returned. In this case, `GetInfoForAuthor` returns a struct with two fields: `Bio` and `BirthYear`. If a query result has no row records, a zero value and an `ErrNoRows` error are returned instead of a zero value and `nil`. For instance, when the `GetBioForAuthor` result has no rows, it will return `""` and `ErrNoRows`. package db import ( "context" "database/sql" ) type DBTX interface { QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getBioForAuthor \= \`-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id = $1 \` func (q \*Queries) GetBioForAuthor(ctx context.Context, id int) (string, error) { row := q.db.QueryRowContext(ctx, getBioForAuthor, id) var i string err := row.Scan(&i) return i, err } const getInfoForAuthor \= \`-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id = $1 \` type GetInfoForAuthorRow struct { Bio string BirthYear int } func (q \*Queries) GetInfoForAuthor(ctx context.Context, id int) (GetInfoForAuthorRow, error) { row := q.db.QueryRowContext(ctx, getInfoForAuthor, id) var i GetInfoForAuthorRow err := row.Scan(&i.Bio, &i.BirthYear) return i, err } Passing a slice as a parameter to a query[](https://docs.sqlc.dev/en/v1.30.0/howto/select.html#passing-a-slice-as-a-parameter-to-a-query "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.30.0/howto/select.html#postgresql "Link to this heading") In PostgreSQL, [ANY](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.28.16) allows you to check if a value exists in an array expression. Queries using ANY with a single parameter will generate method signatures with slices as arguments. Use the postgres data types, eg: int, varchar, etc. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id \= ANY($1::int\[\]); The above SQL will generate the following code: package db import ( "context" "database/sql" "github.com/lib/pq" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const listAuthors \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id = ANY($1::int\[\]) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors, pq.Array(ids)) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } ### MySQL and SQLite[](https://docs.sqlc.dev/en/v1.30.0/howto/select.html#mysql-and-sqlite "Link to this heading") MySQL and SQLite differ from PostgreSQL in that placeholders must be generated based on the number of elements in the slice you pass in. Though trivial it is still something of a nuisance. The passed in slice must not be nil or empty or an error will be returned (ie not a panic). The placeholder insertion location is marked by the meta-function `sqlc.slice()` (which is similar to `sqlc.arg()` that you see documented under [Naming parameters](https://docs.sqlc.dev/en/v1.30.0/howto/named_parameters.html) ). To rephrase, the `sqlc.slice('param')` behaves identically to `sqlc.arg()` it terms of how it maps the explicit argument to the function signature, eg: * `sqlc.slice('ids')` maps to `ids []GoType` in the function signature * `sqlc.slice(cust_ids)` maps to `custIds []GoType` in the function signature (like `sqlc.arg()`, the parameter does not have to be quoted) This feature is not compatible with `emit_prepared_queries` statement found in the [Configuration file](https://docs.sqlc.dev/en/v1.30.0/reference/config.html) . CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id IN (sqlc.slice('ids')); The above SQL will generate the following code: package db import ( "context" "database/sql" "fmt" "strings" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } const listAuthorsByIDs \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id IN (/\*SLICE:ids\*/?) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int64) (\[\]Author, error) { sql := listAuthorsByIDs var queryParams \[\]interface{} if len(ids) \== 0 { return nil, fmt.Errorf("slice ids must have at least one element") } for \_, v := range ids { queryParams \= append(queryParams, v) } sql \= strings.Replace(sql, "/\*SLICE:ids\*/?", strings.Repeat(",?", len(ids))\[1:\], 1) rows, err := q.db.QueryContext(ctx, sql, queryParams...) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Retrieving rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Retrieving rows * [View page source](https://docs.sqlc.dev/en/stable/_sources/howto/select.md.txt) * * * Retrieving rows[](https://docs.sqlc.dev/en/stable/howto/select.html#retrieving-rows "Link to this heading") ============================================================================================================= To generate a database access method, annotate a query with a specific comment. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; **MySQL and SQLite:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ?; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; A few new pieces of code are generated beyond the `Author` struct. An interface for the underlying database is generated. The `*sql.DB` and `*sql.Tx` types satisfy this interface. The database access methods are added to a `Queries` struct, which is created using the `New` method. Note that the `*` in our query has been replaced with explicit column names. This change ensures that the query will never return unexpected data. Our query was annotated with `:one`, meaning that it should only return a single row. We scan the data from that one into a `Author` struct. Since the get query has a single parameter, the `GetAuthor` method takes a single `int` as an argument. Since the list query has no parameters, the `ListAuthors` method accepts no arguments. package db import ( "context" "database/sql" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getAuthor \= \`-- name: GetAuthor :one SELECT id, bio, birth\_year FROM authors WHERE id = $1 \` func (q \*Queries) GetAuthor(ctx context.Context, id int) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) var i Author err := row.Scan(&i.ID, &i.Bio, &i.BirthYear) return i, err } const listAuthors \= \`-- name: ListAuthors :many SELECT id, bio, birth\_year FROM authors ORDER BY id \` func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } Selecting columns[](https://docs.sqlc.dev/en/stable/howto/select.html#selecting-columns "Link to this heading") ----------------------------------------------------------------------------------------------------------------- CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id \= $1; \-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id \= $1; When selecting a single column, only that value is returned. The `GetBioForAuthor` method takes a single `int` as an argument and returns a `string` and an `error`. When selecting multiple columns, a row record (method-specific struct) is returned. In this case, `GetInfoForAuthor` returns a struct with two fields: `Bio` and `BirthYear`. If a query result has no row records, a zero value and an `ErrNoRows` error are returned instead of a zero value and `nil`. For instance, when the `GetBioForAuthor` result has no rows, it will return `""` and `ErrNoRows`. package db import ( "context" "database/sql" ) type DBTX interface { QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getBioForAuthor \= \`-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id = $1 \` func (q \*Queries) GetBioForAuthor(ctx context.Context, id int) (string, error) { row := q.db.QueryRowContext(ctx, getBioForAuthor, id) var i string err := row.Scan(&i) return i, err } const getInfoForAuthor \= \`-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id = $1 \` type GetInfoForAuthorRow struct { Bio string BirthYear int } func (q \*Queries) GetInfoForAuthor(ctx context.Context, id int) (GetInfoForAuthorRow, error) { row := q.db.QueryRowContext(ctx, getInfoForAuthor, id) var i GetInfoForAuthorRow err := row.Scan(&i.Bio, &i.BirthYear) return i, err } Passing a slice as a parameter to a query[](https://docs.sqlc.dev/en/stable/howto/select.html#passing-a-slice-as-a-parameter-to-a-query "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------------- ### PostgreSQL[](https://docs.sqlc.dev/en/stable/howto/select.html#postgresql "Link to this heading") In PostgreSQL, [ANY](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.28.16) allows you to check if a value exists in an array expression. Queries using ANY with a single parameter will generate method signatures with slices as arguments. Use the postgres data types, eg: int, varchar, etc. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id \= ANY($1::int\[\]); The above SQL will generate the following code: package db import ( "context" "database/sql" "github.com/lib/pq" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const listAuthors \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id = ANY($1::int\[\]) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors, pq.Array(ids)) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } ### MySQL and SQLite[](https://docs.sqlc.dev/en/stable/howto/select.html#mysql-and-sqlite "Link to this heading") MySQL and SQLite differ from PostgreSQL in that placeholders must be generated based on the number of elements in the slice you pass in. Though trivial it is still something of a nuisance. The passed in slice must not be nil or empty or an error will be returned (ie not a panic). The placeholder insertion location is marked by the meta-function `sqlc.slice()` (which is similar to `sqlc.arg()` that you see documented under [Naming parameters](https://docs.sqlc.dev/en/stable/howto/named_parameters.html) ). To rephrase, the `sqlc.slice('param')` behaves identically to `sqlc.arg()` it terms of how it maps the explicit argument to the function signature, eg: * `sqlc.slice('ids')` maps to `ids []GoType` in the function signature * `sqlc.slice(cust_ids)` maps to `custIds []GoType` in the function signature (like `sqlc.arg()`, the parameter does not have to be quoted) This feature is not compatible with `emit_prepared_queries` statement found in the [Configuration file](https://docs.sqlc.dev/en/stable/reference/config.html) . CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id IN (sqlc.slice('ids')); The above SQL will generate the following code: package db import ( "context" "database/sql" "fmt" "strings" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } const listAuthorsByIDs \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id IN (/\*SLICE:ids\*/?) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int64) (\[\]Author, error) { sql := listAuthorsByIDs var queryParams \[\]interface{} if len(ids) \== 0 { return nil, fmt.Errorf("slice ids must have at least one element") } for \_, v := range ids { queryParams \= append(queryParams, v) } sql \= strings.Replace(sql, "/\*SLICE:ids\*/?", strings.Repeat(",?", len(ids))\[1:\], 1) rows, err := q.db.QueryContext(ctx, sql, queryParams...) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Retrieving rows — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Retrieving rows * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/select.md.txt) * * * Retrieving rows[](https://docs.sqlc.dev/en/v1.31.0/howto/select.html#retrieving-rows "Link to this heading") ============================================================================================================== To generate a database access method, annotate a query with a specific comment. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; **MySQL and SQLite:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ?; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; A few new pieces of code are generated beyond the `Author` struct. An interface for the underlying database is generated. The `*sql.DB` and `*sql.Tx` types satisfy this interface. The database access methods are added to a `Queries` struct, which is created using the `New` method. Note that the `*` in our query has been replaced with explicit column names. This change ensures that the query will never return unexpected data. Our query was annotated with `:one`, meaning that it should only return a single row. We scan the data from that one into a `Author` struct. Since the get query has a single parameter, the `GetAuthor` method takes a single `int` as an argument. Since the list query has no parameters, the `ListAuthors` method accepts no arguments. package db import ( "context" "database/sql" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getAuthor \= \`-- name: GetAuthor :one SELECT id, bio, birth\_year FROM authors WHERE id = $1 \` func (q \*Queries) GetAuthor(ctx context.Context, id int) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) var i Author err := row.Scan(&i.ID, &i.Bio, &i.BirthYear) return i, err } const listAuthors \= \`-- name: ListAuthors :many SELECT id, bio, birth\_year FROM authors ORDER BY id \` func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } Selecting columns[](https://docs.sqlc.dev/en/v1.31.0/howto/select.html#selecting-columns "Link to this heading") ------------------------------------------------------------------------------------------------------------------ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id \= $1; \-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id \= $1; When selecting a single column, only that value is returned. The `GetBioForAuthor` method takes a single `int` as an argument and returns a `string` and an `error`. When selecting multiple columns, a row record (method-specific struct) is returned. In this case, `GetInfoForAuthor` returns a struct with two fields: `Bio` and `BirthYear`. If a query result has no row records, a zero value and an `ErrNoRows` error are returned instead of a zero value and `nil`. For instance, when the `GetBioForAuthor` result has no rows, it will return `""` and `ErrNoRows`. package db import ( "context" "database/sql" ) type DBTX interface { QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getBioForAuthor \= \`-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id = $1 \` func (q \*Queries) GetBioForAuthor(ctx context.Context, id int) (string, error) { row := q.db.QueryRowContext(ctx, getBioForAuthor, id) var i string err := row.Scan(&i) return i, err } const getInfoForAuthor \= \`-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id = $1 \` type GetInfoForAuthorRow struct { Bio string BirthYear int } func (q \*Queries) GetInfoForAuthor(ctx context.Context, id int) (GetInfoForAuthorRow, error) { row := q.db.QueryRowContext(ctx, getInfoForAuthor, id) var i GetInfoForAuthorRow err := row.Scan(&i.Bio, &i.BirthYear) return i, err } Passing a slice as a parameter to a query[](https://docs.sqlc.dev/en/v1.31.0/howto/select.html#passing-a-slice-as-a-parameter-to-a-query "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.31.0/howto/select.html#postgresql "Link to this heading") In PostgreSQL, [ANY](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.28.16) allows you to check if a value exists in an array expression. Queries using ANY with a single parameter will generate method signatures with slices as arguments. Use the postgres data types, eg: int, varchar, etc. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id \= ANY($1::int\[\]); The above SQL will generate the following code: package db import ( "context" "database/sql" "github.com/lib/pq" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const listAuthors \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id = ANY($1::int\[\]) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors, pq.Array(ids)) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } ### MySQL and SQLite[](https://docs.sqlc.dev/en/v1.31.0/howto/select.html#mysql-and-sqlite "Link to this heading") MySQL and SQLite differ from PostgreSQL in that placeholders must be generated based on the number of elements in the slice you pass in. Though trivial it is still something of a nuisance. The passed in slice must not be nil or empty or an error will be returned (ie not a panic). The placeholder insertion location is marked by the meta-function `sqlc.slice()` (which is similar to `sqlc.arg()` that you see documented under [Naming parameters](https://docs.sqlc.dev/en/v1.31.0/howto/named_parameters.html) ). To rephrase, the `sqlc.slice('param')` behaves identically to `sqlc.arg()` it terms of how it maps the explicit argument to the function signature, eg: * `sqlc.slice('ids')` maps to `ids []GoType` in the function signature * `sqlc.slice(cust_ids)` maps to `custIds []GoType` in the function signature (like `sqlc.arg()`, the parameter does not have to be quoted) This feature is not compatible with `emit_prepared_queries` statement found in the [Configuration file](https://docs.sqlc.dev/en/v1.31.0/reference/config.html) . CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id IN (sqlc.slice('ids')); The above SQL will generate the following code: package db import ( "context" "database/sql" "fmt" "strings" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } const listAuthorsByIDs \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id IN (/\*SLICE:ids\*/?) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int64) (\[\]Author, error) { sql := listAuthorsByIDs var queryParams \[\]interface{} if len(ids) \== 0 { return nil, fmt.Errorf("slice ids must have at least one element") } for \_, v := range ids { queryParams \= append(queryParams, v) } sql \= strings.Replace(sql, "/\*SLICE:ids\*/?", strings.Repeat(",?", len(ids))\[1:\], 1) rows, err := q.db.QueryContext(ctx, sql, queryParams...) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Using sqlc in CI/CD — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Using sqlc in CI/CD * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/ci-cd.md) * * * Using sqlc in CI/CD[](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html#using-sqlc-in-ci-cd "Link to this heading") ===================================================================================================================== If your project has more than a single developer, we suggest running `sqlc` as part of your CI/CD pipeline. The four subcommands you’ll want to run are `diff`, `vet`, `verify` and `push` `sqlc diff` ensures that your generated code is up to date. New developers to a project may forget to run `sqlc generate` after adding a query or updating a schema. They also might edit generated code. `sqlc diff` will catch both errors by comparing the expected output from `sqlc generate` to what’s on disk. % sqlc diff \--- a/postgresql/query.sql.go +++ b/postgresql/query.sql.go @@ -55,7 +55,7 @@ const listAuthors = \`-- name: ListAuthors :many SELECT id, name, bio FROM authors \-ORDER BY name +ORDER BY bio \` `sqlc vet` runs a set of lint rules against your SQL queries. These rules are helpful in catching anti-patterns before they make it into production. Please see the [vet](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html) documentation for a complete guide to adding lint rules for your project. `sqlc verify` ensures that schema changes do not break production. Existing queries are checked against new schema changes for correctness. Please see the [verify](https://docs.sqlc.dev/en/v1.27.0/howto/verify.html) documentation for a complete guide. `sqlc push` pushes your database schema, queries and configuration to sqlc Cloud. These archives are used by `verify` to catch breaking changes to your database schema. Learn more about uploading projects [here](https://docs.sqlc.dev/en/v1.27.0/howto/push.html) General setup[](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html#general-setup "Link to this heading") --------------------------------------------------------------------------------------------------------- Install `sqlc` using the [suggested instructions](https://docs.sqlc.dev/en/v1.27.0/overview/install.html) . Create three steps in your pipeline for `sqlc diff`, `sqlc vet`, and `sqlc verify`. Run `sqlc push` after merge on your `main` branch. GitHub Actions[](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html#github-actions "Link to this heading") ----------------------------------------------------------------------------------------------------------- We provide the [setup-sqlc](https://github.com/marketplace/actions/setup-sqlc) GitHub Action to install `sqlc`. The action uses the built-in [tool-cache](https://github.com/actions/toolkit/blob/main/packages/tool-cache/README.md) to speed up the installation process. ### diff[](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html#diff "Link to this heading") The following GitHub Workflow configuration runs `sqlc diff` on every push. name: sqlc on: \[push\] jobs: diff: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.27.0' \- run: sqlc diff ### vet[](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html#vet "Link to this heading") The following GitHub Workflow configuration runs [sqlc vet](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html) on every push. You can use `sqlc vet` without a database connection, but you’ll need one if your `sqlc` configuration references the built-in `sqlc/db-prepare` lint rule. name: sqlc on: \[push\] jobs: vet: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.27.0' \# Start a PostgreSQL server \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc vet env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable ### push[](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html#push "Link to this heading") Note Pushing a project is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. The following GitHub Workflow configuration runs [sqlc push](https://docs.sqlc.dev/en/v1.27.0/howto/push.html) on every push to `main`. Create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . name: sqlc on: \[push\] jobs: push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.27.0' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} ### verify[](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html#verify "Link to this heading") Note Verify database migrations is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. name: sqlc on: \[push\] jobs: verify: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.27.0' \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc verify env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.27.0' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} --- # Retrieving rows — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Retrieving rows * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/select.md.txt) * * * Retrieving rows[](https://docs.sqlc.dev/en/v1.31.1/howto/select.html#retrieving-rows "Link to this heading") ============================================================================================================== To generate a database access method, annotate a query with a specific comment. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); The parameter syntax varies by database engine: **PostgreSQL:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; **MySQL and SQLite:** \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= ?; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; A few new pieces of code are generated beyond the `Author` struct. An interface for the underlying database is generated. The `*sql.DB` and `*sql.Tx` types satisfy this interface. The database access methods are added to a `Queries` struct, which is created using the `New` method. Note that the `*` in our query has been replaced with explicit column names. This change ensures that the query will never return unexpected data. Our query was annotated with `:one`, meaning that it should only return a single row. We scan the data from that one into a `Author` struct. Since the get query has a single parameter, the `GetAuthor` method takes a single `int` as an argument. Since the list query has no parameters, the `ListAuthors` method accepts no arguments. package db import ( "context" "database/sql" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getAuthor \= \`-- name: GetAuthor :one SELECT id, bio, birth\_year FROM authors WHERE id = $1 \` func (q \*Queries) GetAuthor(ctx context.Context, id int) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) var i Author err := row.Scan(&i.ID, &i.Bio, &i.BirthYear) return i, err } const listAuthors \= \`-- name: ListAuthors :many SELECT id, bio, birth\_year FROM authors ORDER BY id \` func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } Selecting columns[](https://docs.sqlc.dev/en/v1.31.1/howto/select.html#selecting-columns "Link to this heading") ------------------------------------------------------------------------------------------------------------------ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id \= $1; \-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id \= $1; When selecting a single column, only that value is returned. The `GetBioForAuthor` method takes a single `int` as an argument and returns a `string` and an `error`. When selecting multiple columns, a row record (method-specific struct) is returned. In this case, `GetInfoForAuthor` returns a struct with two fields: `Bio` and `BirthYear`. If a query result has no row records, a zero value and an `ErrNoRows` error are returned instead of a zero value and `nil`. For instance, when the `GetBioForAuthor` result has no rows, it will return `""` and `ErrNoRows`. package db import ( "context" "database/sql" ) type DBTX interface { QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getBioForAuthor \= \`-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id = $1 \` func (q \*Queries) GetBioForAuthor(ctx context.Context, id int) (string, error) { row := q.db.QueryRowContext(ctx, getBioForAuthor, id) var i string err := row.Scan(&i) return i, err } const getInfoForAuthor \= \`-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id = $1 \` type GetInfoForAuthorRow struct { Bio string BirthYear int } func (q \*Queries) GetInfoForAuthor(ctx context.Context, id int) (GetInfoForAuthorRow, error) { row := q.db.QueryRowContext(ctx, getInfoForAuthor, id) var i GetInfoForAuthorRow err := row.Scan(&i.Bio, &i.BirthYear) return i, err } Passing a slice as a parameter to a query[](https://docs.sqlc.dev/en/v1.31.1/howto/select.html#passing-a-slice-as-a-parameter-to-a-query "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.31.1/howto/select.html#postgresql "Link to this heading") In PostgreSQL, [ANY](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.28.16) allows you to check if a value exists in an array expression. Queries using ANY with a single parameter will generate method signatures with slices as arguments. Use the postgres data types, eg: int, varchar, etc. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id \= ANY($1::int\[\]); The above SQL will generate the following code: package db import ( "context" "database/sql" "github.com/lib/pq" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const listAuthors \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id = ANY($1::int\[\]) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors, pq.Array(ids)) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } ### MySQL and SQLite[](https://docs.sqlc.dev/en/v1.31.1/howto/select.html#mysql-and-sqlite "Link to this heading") MySQL and SQLite differ from PostgreSQL in that placeholders must be generated based on the number of elements in the slice you pass in. Though trivial it is still something of a nuisance. The passed in slice must not be nil or empty or an error will be returned (ie not a panic). The placeholder insertion location is marked by the meta-function `sqlc.slice()` (which is similar to `sqlc.arg()` that you see documented under [Naming parameters](https://docs.sqlc.dev/en/v1.31.1/howto/named_parameters.html) ). To rephrase, the `sqlc.slice('param')` behaves identically to `sqlc.arg()` it terms of how it maps the explicit argument to the function signature, eg: * `sqlc.slice('ids')` maps to `ids []GoType` in the function signature * `sqlc.slice(cust_ids)` maps to `custIds []GoType` in the function signature (like `sqlc.arg()`, the parameter does not have to be quoted) This feature is not compatible with `emit_prepared_queries` statement found in the [Configuration file](https://docs.sqlc.dev/en/v1.31.1/reference/config.html) . CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id IN (sqlc.slice('ids')); The above SQL will generate the following code: package db import ( "context" "database/sql" "fmt" "strings" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } const listAuthorsByIDs \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id IN (/\*SLICE:ids\*/?) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int64) (\[\]Author, error) { sql := listAuthorsByIDs var queryParams \[\]interface{} if len(ids) \== 0 { return nil, fmt.Errorf("slice ids must have at least one element") } for \_, v := range ids { queryParams \= append(queryParams, v) } sql \= strings.Replace(sql, "/\*SLICE:ids\*/?", strings.Repeat(",?", len(ids))\[1:\], 1) rows, err := q.db.QueryContext(ctx, sql, queryParams...) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Retrieving rows — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Retrieving rows * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/howto/select.md) * * * Retrieving rows[](https://docs.sqlc.dev/en/v1.27.0/howto/select.html#retrieving-rows "Link to this heading") ============================================================================================================== To generate a database access method, annotate a query with a specific comment. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: GetAuthor :one SELECT \* FROM authors WHERE id \= $1; \-- name: ListAuthors :many SELECT \* FROM authors ORDER BY id; A few new pieces of code are generated beyond the `Author` struct. An interface for the underlying database is generated. The `*sql.DB` and `*sql.Tx` types satisfy this interface. The database access methods are added to a `Queries` struct, which is created using the `New` method. Note that the `*` in our query has been replaced with explicit column names. This change ensures that the query will never return unexpected data. Our query was annotated with `:one`, meaning that it should only return a single row. We scan the data from that one into a `Author` struct. Since the get query has a single parameter, the `GetAuthor` method takes a single `int` as an argument. Since the list query has no parameters, the `ListAuthors` method accepts no arguments. package db import ( "context" "database/sql" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getAuthor \= \`-- name: GetAuthor :one SELECT id, bio, birth\_year FROM authors WHERE id = $1 \` func (q \*Queries) GetAuthor(ctx context.Context, id int) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) var i Author err := row.Scan(&i.ID, &i.Bio, &i.BirthYear) return i, err } const listAuthors \= \`-- name: ListAuthors :many SELECT id, bio, birth\_year FROM authors ORDER BY id \` func (q \*Queries) ListAuthors(ctx context.Context) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } Selecting columns[](https://docs.sqlc.dev/en/v1.27.0/howto/select.html#selecting-columns "Link to this heading") ------------------------------------------------------------------------------------------------------------------ CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id \= $1; \-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id \= $1; When selecting a single column, only that value is returned. The `GetBioForAuthor` method takes a single `int` as an argument and returns a `string` and an `error`. When selecting multiple columns, a row record (method-specific struct) is returned. In this case, `GetInfoForAuthor` returns a struct with two fields: `Bio` and `BirthYear`. If a query result has no row records, a zero value and an `ErrNoRows` error are returned instead of a zero value and `nil`. For instance, when the `GetBioForAuthor` result has no rows, it will return `""` and `ErrNoRows`. package db import ( "context" "database/sql" ) type DBTX interface { QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const getBioForAuthor \= \`-- name: GetBioForAuthor :one SELECT bio FROM authors WHERE id = $1 \` func (q \*Queries) GetBioForAuthor(ctx context.Context, id int) (string, error) { row := q.db.QueryRowContext(ctx, getBioForAuthor, id) var i string err := row.Scan(&i) return i, err } const getInfoForAuthor \= \`-- name: GetInfoForAuthor :one SELECT bio, birth\_year FROM authors WHERE id = $1 \` type GetInfoForAuthorRow struct { Bio string BirthYear int } func (q \*Queries) GetInfoForAuthor(ctx context.Context, id int) (GetInfoForAuthorRow, error) { row := q.db.QueryRowContext(ctx, getInfoForAuthor, id) var i GetInfoForAuthorRow err := row.Scan(&i.Bio, &i.BirthYear) return i, err } Passing a slice as a parameter to a query[](https://docs.sqlc.dev/en/v1.27.0/howto/select.html#passing-a-slice-as-a-parameter-to-a-query "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ### PostgreSQL[](https://docs.sqlc.dev/en/v1.27.0/howto/select.html#postgresql "Link to this heading") In PostgreSQL, [ANY](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.28.16) allows you to check if a value exists in an array expression. Queries using ANY with a single parameter will generate method signatures with slices as arguments. Use the postgres data types, eg: int, varchar, etc. CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id \= ANY($1::int\[\]); The above SQL will generate the following code: package db import ( "context" "database/sql" "github.com/lib/pq" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } const listAuthors \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id = ANY($1::int\[\]) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int) (\[\]Author, error) { rows, err := q.db.QueryContext(ctx, listAuthors, pq.Array(ids)) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } ### MySQL and SQLite[](https://docs.sqlc.dev/en/v1.27.0/howto/select.html#mysql-and-sqlite "Link to this heading") MySQL and SQLite differ from PostgreSQL in that placeholders must be generated based on the number of elements in the slice you pass in. Though trivial it is still something of a nuisance. The passed in slice must not be nil or empty or an error will be returned (ie not a panic). The placeholder insertion location is marked by the meta-function `sqlc.slice()` (which is similar to `sqlc.arg()` that you see documented under [Naming parameters](https://docs.sqlc.dev/en/v1.27.0/howto/named_parameters.html) ). To rephrase, the `sqlc.slice('param')` behaves identically to `sqlc.arg()` it terms of how it maps the explicit argument to the function signature, eg: * `sqlc.slice('ids')` maps to `ids []GoType` in the function signature * `sqlc.slice(cust_ids)` maps to `custIds []GoType` in the function signature (like `sqlc.arg()`, the parameter does not have to be quoted) This feature is not compatible with `emit_prepared_queries` statement found in the [Configuration file](https://docs.sqlc.dev/en/v1.27.0/reference/config.html) . CREATE TABLE authors ( id SERIAL PRIMARY KEY, bio text NOT NULL, birth\_year int NOT NULL ); \-- name: ListAuthorsByIDs :many SELECT \* FROM authors WHERE id IN (sqlc.slice('ids')); The above SQL will generate the following code: package db import ( "context" "database/sql" "fmt" "strings" ) type Author struct { ID int Bio string BirthYear int } type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (\*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (\*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) \*sql.Row } func New(db DBTX) \*Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q \*Queries) WithTx(tx \*sql.Tx) \*Queries { return &Queries{ db: tx, } } const listAuthorsByIDs \= \`-- name: ListAuthorsByIDs :many SELECT id, bio, birth\_year FROM authors WHERE id IN (/\*SLICE:ids\*/?) \` func (q \*Queries) ListAuthorsByIDs(ctx context.Context, ids \[\]int64) (\[\]Author, error) { sql := listAuthorsByIDs var queryParams \[\]interface{} if len(ids) \== 0 { return nil, fmt.Errorf("slice ids must have at least one element") } for \_, v := range ids { queryParams \= append(queryParams, v) } sql \= strings.Replace(sql, "/\*SLICE:ids\*/?", strings.Repeat(",?", len(ids))\[1:\], 1) rows, err := q.db.QueryContext(ctx, sql, queryParams...) if err != nil { return nil, err } defer rows.Close() var items \[\]Author for rows.Next() { var i Author if err := rows.Scan(&i.ID, &i.Bio, &i.BirthYear); err != nil { return nil, err } items \= append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } --- # Using sqlc in CI/CD — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Using sqlc in CI/CD * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/howto/ci-cd.md.txt) * * * Using sqlc in CI/CD[](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html#using-sqlc-in-ci-cd "Link to this heading") ===================================================================================================================== If your project has more than a single developer, we suggest running `sqlc` as part of your CI/CD pipeline. The four subcommands you’ll want to run are `diff`, `vet`, `verify` and `push` `sqlc diff` ensures that your generated code is up to date. New developers to a project may forget to run `sqlc generate` after adding a query or updating a schema. They also might edit generated code. `sqlc diff` will catch both errors by comparing the expected output from `sqlc generate` to what’s on disk. % sqlc diff \--- a/postgresql/query.sql.go +++ b/postgresql/query.sql.go @@ -55,7 +55,7 @@ const listAuthors = \`-- name: ListAuthors :many SELECT id, name, bio FROM authors \-ORDER BY name +ORDER BY bio \` `sqlc vet` runs a set of lint rules against your SQL queries. These rules are helpful in catching anti-patterns before they make it into production. Please see the [vet](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html) documentation for a complete guide to adding lint rules for your project. `sqlc verify` ensures that schema changes do not break production. Existing queries are checked against new schema changes for correctness. Please see the [verify](https://docs.sqlc.dev/en/v1.31.0/howto/verify.html) documentation for a complete guide. `sqlc push` pushes your database schema, queries and configuration to sqlc Cloud. These archives are used by `verify` to catch breaking changes to your database schema. Learn more about uploading projects [here](https://docs.sqlc.dev/en/v1.31.0/howto/push.html) General setup[](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html#general-setup "Link to this heading") --------------------------------------------------------------------------------------------------------- Install `sqlc` using the [suggested instructions](https://docs.sqlc.dev/en/v1.31.0/overview/install.html) . Create three steps in your pipeline for `sqlc diff`, `sqlc vet`, and `sqlc verify`. Run `sqlc push` after merge on your `main` branch. GitHub Actions[](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html#github-actions "Link to this heading") ----------------------------------------------------------------------------------------------------------- We provide the [setup-sqlc](https://github.com/marketplace/actions/setup-sqlc) GitHub Action to install `sqlc`. The action uses the built-in [tool-cache](https://github.com/actions/toolkit/blob/main/packages/tool-cache/README.md) to speed up the installation process. ### diff[](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html#diff "Link to this heading") The following GitHub Workflow configuration runs `sqlc diff` on every push. name: sqlc on: \[push\] jobs: diff: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.0' \- run: sqlc diff ### vet[](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html#vet "Link to this heading") The following GitHub Workflow configuration runs [sqlc vet](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html) on every push. You can use `sqlc vet` without a database connection, but you’ll need one if your `sqlc` configuration references the built-in `sqlc/db-prepare` lint rule. name: sqlc on: \[push\] jobs: vet: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.0' \# Start a PostgreSQL server \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc vet env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable ### push[](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html#push "Link to this heading") Note Pushing a project is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. The following GitHub Workflow configuration runs [sqlc push](https://docs.sqlc.dev/en/v1.31.0/howto/push.html) on every push to `main`. Create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . name: sqlc on: \[push\] jobs: push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.0' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} ### verify[](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html#verify "Link to this heading") Note Verify database migrations is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. name: sqlc on: \[push\] jobs: verify: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.0' \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc verify env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.0' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} --- # Using sqlc in CI/CD — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Using sqlc in CI/CD * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/howto/ci-cd.md.txt) * * * Using sqlc in CI/CD[](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html#using-sqlc-in-ci-cd "Link to this heading") ===================================================================================================================== If your project has more than a single developer, we suggest running `sqlc` as part of your CI/CD pipeline. The four subcommands you’ll want to run are `diff`, `vet`, `verify` and `push` `sqlc diff` ensures that your generated code is up to date. New developers to a project may forget to run `sqlc generate` after adding a query or updating a schema. They also might edit generated code. `sqlc diff` will catch both errors by comparing the expected output from `sqlc generate` to what’s on disk. % sqlc diff \--- a/postgresql/query.sql.go +++ b/postgresql/query.sql.go @@ -55,7 +55,7 @@ const listAuthors = \`-- name: ListAuthors :many SELECT id, name, bio FROM authors \-ORDER BY name +ORDER BY bio \` `sqlc vet` runs a set of lint rules against your SQL queries. These rules are helpful in catching anti-patterns before they make it into production. Please see the [vet](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html) documentation for a complete guide to adding lint rules for your project. `sqlc verify` ensures that schema changes do not break production. Existing queries are checked against new schema changes for correctness. Please see the [verify](https://docs.sqlc.dev/en/v1.31.1/howto/verify.html) documentation for a complete guide. `sqlc push` pushes your database schema, queries and configuration to sqlc Cloud. These archives are used by `verify` to catch breaking changes to your database schema. Learn more about uploading projects [here](https://docs.sqlc.dev/en/v1.31.1/howto/push.html) General setup[](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html#general-setup "Link to this heading") --------------------------------------------------------------------------------------------------------- Install `sqlc` using the [suggested instructions](https://docs.sqlc.dev/en/v1.31.1/overview/install.html) . Create three steps in your pipeline for `sqlc diff`, `sqlc vet`, and `sqlc verify`. Run `sqlc push` after merge on your `main` branch. GitHub Actions[](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html#github-actions "Link to this heading") ----------------------------------------------------------------------------------------------------------- We provide the [setup-sqlc](https://github.com/marketplace/actions/setup-sqlc) GitHub Action to install `sqlc`. The action uses the built-in [tool-cache](https://github.com/actions/toolkit/blob/main/packages/tool-cache/README.md) to speed up the installation process. ### diff[](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html#diff "Link to this heading") The following GitHub Workflow configuration runs `sqlc diff` on every push. name: sqlc on: \[push\] jobs: diff: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc diff ### vet[](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html#vet "Link to this heading") The following GitHub Workflow configuration runs [sqlc vet](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html) on every push. You can use `sqlc vet` without a database connection, but you’ll need one if your `sqlc` configuration references the built-in `sqlc/db-prepare` lint rule. name: sqlc on: \[push\] jobs: vet: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \# Start a PostgreSQL server \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc vet env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable ### push[](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html#push "Link to this heading") Note Pushing a project is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. The following GitHub Workflow configuration runs [sqlc push](https://docs.sqlc.dev/en/v1.31.1/howto/push.html) on every push to `main`. Create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . name: sqlc on: \[push\] jobs: push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} ### verify[](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html#verify "Link to this heading") Note Verify database migrations is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. name: sqlc on: \[push\] jobs: verify: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc verify env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.31.1' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} --- # Configuration — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Configuration * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/config.md.txt) * * * Configuration[](https://docs.sqlc.dev/en/latest/reference/config.html#configuration "Link to this heading") ============================================================================================================= The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This file must be in the directory where the `sqlc` command is run. Version 2[](https://docs.sqlc.dev/en/latest/reference/config.html#version-2 "Link to this heading") ----------------------------------------------------------------------------------------------------- version: "2" cloud: project: "" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" database: managed: true rules: \- sqlc/db-prepare \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" ### sql[](https://docs.sqlc.dev/en/latest/reference/config.html#sql "Link to this heading") Each mapping in the `sql` collection has the following keys: * `name`: * An human-friendly identifier for this query set. Optional. * `engine`: * One of `postgresql`, `mysql` or `sqlite`. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `codegen`: * A collection of mappings to configure code generators. See [codegen](https://docs.sqlc.dev/en/latest/reference/config.html#codegen) for the supported keys. * `gen`: * A mapping to configure built-in code generators. See [gen](https://docs.sqlc.dev/en/latest/reference/config.html#gen) for the supported keys. * `database`: * A mapping to configure database connections. See [database](https://docs.sqlc.dev/en/latest/reference/config.html#database) for the supported keys. * `rules`: * A collection of rule names to run via `sqlc vet`. See [rules](https://docs.sqlc.dev/en/latest/reference/config.html#rules) for configuration options. * `analyzer`: * A mapping to configure query analysis. See [analyzer](https://docs.sqlc.dev/en/latest/reference/config.html#analyzer) for the supported keys. * `strict_function_checks` * If true, return an error if a called SQL function does not exist. Defaults to `false`. * `strict_order_by` * If true, return an error if a order by column is ambiguous. Defaults to `true`. ### codegen[](https://docs.sqlc.dev/en/latest/reference/config.html#codegen "Link to this heading") The `codegen` mapping supports the following keys: * `out`: * Output directory for generated code. * `plugin`: * The name of the plugin. Must be defined in the `plugins` collection. * `options`: * A mapping of plugin-specific options. version: '2' plugins: \- name: py wasm: url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2 sql: \- schema: "schema.sql" queries: "query.sql" engine: postgresql codegen: \- out: src/authors plugin: py options: package: authors emit\_sync\_querier: true emit\_async\_querier: true query\_parameter\_limit: 5 ### database[](https://docs.sqlc.dev/en/latest/reference/config.html#database "Link to this heading") The `database` mapping supports the following keys: * `managed`: * If true, connect to a [managed database](https://docs.sqlc.dev/en/latest/howto/managed-databases.html) . Defaults to `false`. * `uri`: * Database connection URI The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql database: uri: postgresql://postgres:${PG\_PASSWORD}@localhost:5432/authors gen: go: package: authors out: postgresql ### analyzer[](https://docs.sqlc.dev/en/latest/reference/config.html#analyzer "Link to this heading") The `analyzer` mapping supports the following keys: * `database`: * If false, do not use the configured database for query analysis. Defaults to `true`. ### gen[](https://docs.sqlc.dev/en/latest/reference/config.html#gen "Link to this heading") The `gen` mapping supports the following keys: #### go[](https://docs.sqlc.dev/en/latest/reference/config.html#go "Link to this heading") * `package`: * The package name to use for the generated code. Defaults to `out` basename. * `out`: * Output directory for generated code. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `sql_driver`: * Either `github.com/jackc/pgx/v4`, `github.com/jackc/pgx/v5`, `github.com/lib/pq` or `github.com/go-sql-driver/mysql`. No defaults. Required if query annotation `:copyfrom` is used. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Currently only supported for PostgreSQL if `sql_package` is `pgx/v4` or `pgx/v5`, and for SQLite. Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `emit_sql_as_comment`: * If true, emits the SQL statement as a code-block comment above the generated function, appending to any existing comments. Defaults to `false`. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `initialisms`: * An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. * `json_tags_id_uppercase`: * If true, “Id” in json tags will be uppercase. If false, will be camelcase. Defaults to `false` * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * The number of positional arguments that will be generated for Go functions. To always emit a parameter struct, set this to `0`. Defaults to `1`. * `rename`: * Customize the name of generated struct fields. See [Renaming fields](https://docs.sqlc.dev/en/latest/howto/rename.html) for usage information. * `overrides`: * A collection of configurations to override sqlc’s default Go type choices. See [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for usage information. ##### overrides[](https://docs.sqlc.dev/en/latest/reference/config.html#overrides "Link to this heading") See [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) for an in-depth guide to using type overrides. #### kotlin[](https://docs.sqlc.dev/en/latest/reference/config.html#kotlin "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/latest/guides/migrating-to-sqlc-gen-kotlin.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. #### python[](https://docs.sqlc.dev/en/latest/reference/config.html#python "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/latest/guides/migrating-to-sqlc-gen-python.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. * `emit_sync_querier`: * If true, generate a class with synchronous methods. Defaults to `false`. * `emit_async_querier`: * If true, generate a class with asynchronous methods. Defaults to `false`. * `emit_pydantic_models`: * If true, generate classes that inherit from `pydantic.BaseModel`. Otherwise, define classes using the `dataclass` decorator. Defaults to `false`. #### json[](https://docs.sqlc.dev/en/latest/reference/config.html#json "Link to this heading") * `out`: * Output directory for the generated JSON. * `filename`: * Filename for the generated JSON document. Defaults to `codegen_request.json`. * `indent`: * Indent string to use in the JSON document. Defaults to   . ### plugins[](https://docs.sqlc.dev/en/latest/reference/config.html#plugins "Link to this heading") Each mapping in the `plugins` collection has the following keys: * `name`: * The name of this plugin. Required * `env` * A list of environment variables to pass to the plugin. By default, no environment variables are passed. * `process`: A mapping with a single `cmd` key * `cmd`: * The executable to call when using this plugin * `format`: * The format expected. Supports `json` and `protobuf` formats. Defaults to `protobuf`. * `wasm`: A mapping with a two keys `url` and `sha256` * `url`: * The URL to fetch the WASM file. Supports the `https://` or `file://` schemes. * `sha256` * The SHA256 checksum for the downloaded file. version: "2" plugins: \- name: "py" wasm: url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm" sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2" \- name: "js" env: \- PATH process: cmd: "sqlc-gen-json" ### rules[](https://docs.sqlc.dev/en/latest/reference/config.html#rules "Link to this heading") Each mapping in the `rules` collection has the following keys: * `name`: * The name of this rule. Required * `rule`: * A [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Required. * `message`: * An optional message shown when this rule evaluates to `true`. See the [vet](https://docs.sqlc.dev/en/latest/howto/vet.html) documentation for a list of built-in rules and help writing custom rules. version: "2" sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Global overrides[](https://docs.sqlc.dev/en/latest/reference/config.html#global-overrides "Link to this heading") Sometimes, the same configuration must be done across various specifications of code generation. Then a global definition for type overriding and field renaming can be done using the `overrides` mapping the following manner: version: "2" overrides: go: rename: id: "Identifier" overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" With the previous configuration, whenever a struct field is generated from a table column that is called `id`, it will generated as `Identifier`. Also, whenever there is a nullable `timestamp with time zone` column in a Postgres table, it will be generated as `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in the regular type overrides. This field is only used when there are multiple definitions using multiple engines. Otherwise, the value of the `engine` key defaults to the engine that is currently being used. Currently, type overrides and field renaming, both global and regular, are only fully supported in Go. Version 1[](https://docs.sqlc.dev/en/latest/reference/config.html#version-1 "Link to this heading") ----------------------------------------------------------------------------------------------------- version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" emit\_db\_tags: false emit\_prepared\_queries: true emit\_interface: false emit\_exact\_table\_names: false emit\_empty\_slices: false emit\_exported\_queries: false emit\_json\_tags: true emit\_result\_struct\_pointers: false emit\_params\_struct\_pointers: false emit\_methods\_with\_db\_argument: false emit\_pointers\_for\_null\_types: false emit\_enum\_valid\_method: false emit\_all\_enum\_values: false build\_tags: "some\_tag" json\_tags\_case\_style: "camel" omit\_unused\_structs: false output\_batch\_file\_name: "batch.go" output\_db\_file\_name: "db.go" output\_models\_file\_name: "models.go" output\_querier\_file\_name: "querier.go" output\_copyfrom\_file\_name: "copyfrom.go" query\_parameter\_limit: 1 ### packages[](https://docs.sqlc.dev/en/latest/reference/config.html#packages "Link to this heading") Each mapping in the `packages` collection has the following keys: * `name`: * The package name to use for the generated code. Defaults to `path` basename. * `path`: * Output directory for generated code. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `engine`: * Either `postgresql` or `mysql`. Defaults to `postgresql`. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `overrides`: * A list of type override configurations. See the [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html) guide for details. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true and `sql_package` is set to `pgx/v4` or `pgx/v5`, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * Positional arguments that will be generated in Go functions (`>= 0`). To always emit a parameter struct, you would need to set it to `0`. Defaults to `1`. ### overrides[](https://docs.sqlc.dev/en/latest/reference/config.html#id1 "Link to this heading") See the version 1 configuration section of the [Overriding types](https://docs.sqlc.dev/en/latest/howto/overrides.html#version-1-configuration) guide for details. ### rename[](https://docs.sqlc.dev/en/latest/reference/config.html#rename "Link to this heading") Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "1" packages: \[...\] rename: spotify\_url: "SpotifyURL" --- # generate - Generating code — sqlc 1.29.0 documentation * [](https://docs.sqlc.dev/en/v1.29.0/index.html) * `generate` - Generating code * [View page source](https://docs.sqlc.dev/en/v1.29.0/_sources/howto/generate.md.txt) * * * `generate` - Generating code[](https://docs.sqlc.dev/en/v1.29.0/howto/generate.html#generate-generating-code "Link to this heading") ====================================================================================================================================== `sqlc generate` parses SQL, analyzes the results, and outputs code. Your schema and queries are stored in separate SQL files. The paths to these files live in a `sqlc.yaml` configuration file. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" gen: go: package: "tutorial" out: "tutorial" sql\_package: "pgx/v5" We’ve written extensive docs on [retrieving](https://docs.sqlc.dev/en/v1.29.0/howto/select.html) , [inserting](https://docs.sqlc.dev/en/v1.29.0/howto/insert.html) , [updating](https://docs.sqlc.dev/en/v1.29.0/howto/update.html) , and [deleting](https://docs.sqlc.dev/en/v1.29.0/howto/delete.html) rows. By default, sqlc runs its analysis using a built-in query analysis engine. While fast, this engine can’t handle some complex queries and type-inference. You can configure sqlc to use a database connection for enhanced analysis using metadata from that database. The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. Enhanced analysis with managed databases[](https://docs.sqlc.dev/en/v1.29.0/howto/generate.html#enhanced-analysis-with-managed-databases "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------------ With [managed databases](https://docs.sqlc.dev/en/v1.29.0/howto/managed-databases.html) configured, `generate` will automatically create a hosted ephemeral database with your schema and use that database to improve its query analysis. And sqlc will cache its analysis locally on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with an up-to-date schema. Here’s a minimal working configuration: version: "2" servers: \- engine: postgresql uri: "postgres://locahost:5432/postgres?sslmode=disable" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: managed: true gen: go: out: "db" sql\_package: "pgx/v5" Enhanced analysis using your own database[](https://docs.sqlc.dev/en/v1.29.0/howto/generate.html#enhanced-analysis-using-your-own-database "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can opt-in to database-backed analysis using your own database, by providing a `uri` in your sqlc [database](https://docs.sqlc.dev/en/v1.29.0/reference/config.html#database) configuration. The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: "2" sql: \- engine: "postgresql" queries: "query.sql" schema: "schema.sql" database: uri: "postgres://postgres:${PG\_PASSWORD}@localhost:5432/postgres" gen: go: out: "db" sql\_package: "pgx/v5" Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary tables and objects before running `sqlc generate`. --- # Configuration — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Configuration * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/config.md.txt) * * * Configuration[](https://docs.sqlc.dev/en/stable/reference/config.html#configuration "Link to this heading") ============================================================================================================= The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This file must be in the directory where the `sqlc` command is run. Version 2[](https://docs.sqlc.dev/en/stable/reference/config.html#version-2 "Link to this heading") ----------------------------------------------------------------------------------------------------- version: "2" cloud: project: "" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" database: managed: true rules: \- sqlc/db-prepare \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" ### sql[](https://docs.sqlc.dev/en/stable/reference/config.html#sql "Link to this heading") Each mapping in the `sql` collection has the following keys: * `name`: * An human-friendly identifier for this query set. Optional. * `engine`: * One of `postgresql`, `mysql` or `sqlite`. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `codegen`: * A collection of mappings to configure code generators. See [codegen](https://docs.sqlc.dev/en/stable/reference/config.html#codegen) for the supported keys. * `gen`: * A mapping to configure built-in code generators. See [gen](https://docs.sqlc.dev/en/stable/reference/config.html#gen) for the supported keys. * `database`: * A mapping to configure database connections. See [database](https://docs.sqlc.dev/en/stable/reference/config.html#database) for the supported keys. * `rules`: * A collection of rule names to run via `sqlc vet`. See [rules](https://docs.sqlc.dev/en/stable/reference/config.html#rules) for configuration options. * `analyzer`: * A mapping to configure query analysis. See [analyzer](https://docs.sqlc.dev/en/stable/reference/config.html#analyzer) for the supported keys. * `strict_function_checks` * If true, return an error if a called SQL function does not exist. Defaults to `false`. * `strict_order_by` * If true, return an error if a order by column is ambiguous. Defaults to `true`. ### codegen[](https://docs.sqlc.dev/en/stable/reference/config.html#codegen "Link to this heading") The `codegen` mapping supports the following keys: * `out`: * Output directory for generated code. * `plugin`: * The name of the plugin. Must be defined in the `plugins` collection. * `options`: * A mapping of plugin-specific options. version: '2' plugins: \- name: py wasm: url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2 sql: \- schema: "schema.sql" queries: "query.sql" engine: postgresql codegen: \- out: src/authors plugin: py options: package: authors emit\_sync\_querier: true emit\_async\_querier: true query\_parameter\_limit: 5 ### database[](https://docs.sqlc.dev/en/stable/reference/config.html#database "Link to this heading") The `database` mapping supports the following keys: * `managed`: * If true, connect to a [managed database](https://docs.sqlc.dev/en/stable/howto/managed-databases.html) . Defaults to `false`. * `uri`: * Database connection URI The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql database: uri: postgresql://postgres:${PG\_PASSWORD}@localhost:5432/authors gen: go: package: authors out: postgresql ### analyzer[](https://docs.sqlc.dev/en/stable/reference/config.html#analyzer "Link to this heading") The `analyzer` mapping supports the following keys: * `database`: * If false, do not use the configured database for query analysis. Defaults to `true`. ### gen[](https://docs.sqlc.dev/en/stable/reference/config.html#gen "Link to this heading") The `gen` mapping supports the following keys: #### go[](https://docs.sqlc.dev/en/stable/reference/config.html#go "Link to this heading") * `package`: * The package name to use for the generated code. Defaults to `out` basename. * `out`: * Output directory for generated code. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `sql_driver`: * Either `github.com/jackc/pgx/v4`, `github.com/jackc/pgx/v5`, `github.com/lib/pq` or `github.com/go-sql-driver/mysql`. No defaults. Required if query annotation `:copyfrom` is used. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Currently only supported for PostgreSQL if `sql_package` is `pgx/v4` or `pgx/v5`, and for SQLite. Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `emit_sql_as_comment`: * If true, emits the SQL statement as a code-block comment above the generated function, appending to any existing comments. Defaults to `false`. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `initialisms`: * An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. * `json_tags_id_uppercase`: * If true, “Id” in json tags will be uppercase. If false, will be camelcase. Defaults to `false` * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * The number of positional arguments that will be generated for Go functions. To always emit a parameter struct, set this to `0`. Defaults to `1`. * `rename`: * Customize the name of generated struct fields. See [Renaming fields](https://docs.sqlc.dev/en/stable/howto/rename.html) for usage information. * `overrides`: * A collection of configurations to override sqlc’s default Go type choices. See [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for usage information. ##### overrides[](https://docs.sqlc.dev/en/stable/reference/config.html#overrides "Link to this heading") See [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) for an in-depth guide to using type overrides. #### kotlin[](https://docs.sqlc.dev/en/stable/reference/config.html#kotlin "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/stable/guides/migrating-to-sqlc-gen-kotlin.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. #### python[](https://docs.sqlc.dev/en/stable/reference/config.html#python "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/stable/guides/migrating-to-sqlc-gen-python.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. * `emit_sync_querier`: * If true, generate a class with synchronous methods. Defaults to `false`. * `emit_async_querier`: * If true, generate a class with asynchronous methods. Defaults to `false`. * `emit_pydantic_models`: * If true, generate classes that inherit from `pydantic.BaseModel`. Otherwise, define classes using the `dataclass` decorator. Defaults to `false`. #### json[](https://docs.sqlc.dev/en/stable/reference/config.html#json "Link to this heading") * `out`: * Output directory for the generated JSON. * `filename`: * Filename for the generated JSON document. Defaults to `codegen_request.json`. * `indent`: * Indent string to use in the JSON document. Defaults to   . ### plugins[](https://docs.sqlc.dev/en/stable/reference/config.html#plugins "Link to this heading") Each mapping in the `plugins` collection has the following keys: * `name`: * The name of this plugin. Required * `env` * A list of environment variables to pass to the plugin. By default, no environment variables are passed. * `process`: A mapping with a single `cmd` key * `cmd`: * The executable to call when using this plugin * `format`: * The format expected. Supports `json` and `protobuf` formats. Defaults to `protobuf`. * `wasm`: A mapping with a two keys `url` and `sha256` * `url`: * The URL to fetch the WASM file. Supports the `https://` or `file://` schemes. * `sha256` * The SHA256 checksum for the downloaded file. version: "2" plugins: \- name: "py" wasm: url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm" sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2" \- name: "js" env: \- PATH process: cmd: "sqlc-gen-json" ### rules[](https://docs.sqlc.dev/en/stable/reference/config.html#rules "Link to this heading") Each mapping in the `rules` collection has the following keys: * `name`: * The name of this rule. Required * `rule`: * A [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Required. * `message`: * An optional message shown when this rule evaluates to `true`. See the [vet](https://docs.sqlc.dev/en/stable/howto/vet.html) documentation for a list of built-in rules and help writing custom rules. version: "2" sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Global overrides[](https://docs.sqlc.dev/en/stable/reference/config.html#global-overrides "Link to this heading") Sometimes, the same configuration must be done across various specifications of code generation. Then a global definition for type overriding and field renaming can be done using the `overrides` mapping the following manner: version: "2" overrides: go: rename: id: "Identifier" overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" With the previous configuration, whenever a struct field is generated from a table column that is called `id`, it will generated as `Identifier`. Also, whenever there is a nullable `timestamp with time zone` column in a Postgres table, it will be generated as `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in the regular type overrides. This field is only used when there are multiple definitions using multiple engines. Otherwise, the value of the `engine` key defaults to the engine that is currently being used. Currently, type overrides and field renaming, both global and regular, are only fully supported in Go. Version 1[](https://docs.sqlc.dev/en/stable/reference/config.html#version-1 "Link to this heading") ----------------------------------------------------------------------------------------------------- version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" emit\_db\_tags: false emit\_prepared\_queries: true emit\_interface: false emit\_exact\_table\_names: false emit\_empty\_slices: false emit\_exported\_queries: false emit\_json\_tags: true emit\_result\_struct\_pointers: false emit\_params\_struct\_pointers: false emit\_methods\_with\_db\_argument: false emit\_pointers\_for\_null\_types: false emit\_enum\_valid\_method: false emit\_all\_enum\_values: false build\_tags: "some\_tag" json\_tags\_case\_style: "camel" omit\_unused\_structs: false output\_batch\_file\_name: "batch.go" output\_db\_file\_name: "db.go" output\_models\_file\_name: "models.go" output\_querier\_file\_name: "querier.go" output\_copyfrom\_file\_name: "copyfrom.go" query\_parameter\_limit: 1 ### packages[](https://docs.sqlc.dev/en/stable/reference/config.html#packages "Link to this heading") Each mapping in the `packages` collection has the following keys: * `name`: * The package name to use for the generated code. Defaults to `path` basename. * `path`: * Output directory for generated code. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `engine`: * Either `postgresql` or `mysql`. Defaults to `postgresql`. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `overrides`: * A list of type override configurations. See the [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html) guide for details. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true and `sql_package` is set to `pgx/v4` or `pgx/v5`, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * Positional arguments that will be generated in Go functions (`>= 0`). To always emit a parameter struct, you would need to set it to `0`. Defaults to `1`. ### overrides[](https://docs.sqlc.dev/en/stable/reference/config.html#id1 "Link to this heading") See the version 1 configuration section of the [Overriding types](https://docs.sqlc.dev/en/stable/howto/overrides.html#version-1-configuration) guide for details. ### rename[](https://docs.sqlc.dev/en/stable/reference/config.html#rename "Link to this heading") Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "1" packages: \[...\] rename: spotify\_url: "SpotifyURL" --- # Using sqlc in CI/CD — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Using sqlc in CI/CD * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/howto/ci-cd.md.txt) * * * Using sqlc in CI/CD[](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html#using-sqlc-in-ci-cd "Link to this heading") ===================================================================================================================== If your project has more than a single developer, we suggest running `sqlc` as part of your CI/CD pipeline. The four subcommands you’ll want to run are `diff`, `vet`, `verify` and `push` `sqlc diff` ensures that your generated code is up to date. New developers to a project may forget to run `sqlc generate` after adding a query or updating a schema. They also might edit generated code. `sqlc diff` will catch both errors by comparing the expected output from `sqlc generate` to what’s on disk. % sqlc diff \--- a/postgresql/query.sql.go +++ b/postgresql/query.sql.go @@ -55,7 +55,7 @@ const listAuthors = \`-- name: ListAuthors :many SELECT id, name, bio FROM authors \-ORDER BY name +ORDER BY bio \` `sqlc vet` runs a set of lint rules against your SQL queries. These rules are helpful in catching anti-patterns before they make it into production. Please see the [vet](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html) documentation for a complete guide to adding lint rules for your project. `sqlc verify` ensures that schema changes do not break production. Existing queries are checked against new schema changes for correctness. Please see the [verify](https://docs.sqlc.dev/en/v1.30.0/howto/verify.html) documentation for a complete guide. `sqlc push` pushes your database schema, queries and configuration to sqlc Cloud. These archives are used by `verify` to catch breaking changes to your database schema. Learn more about uploading projects [here](https://docs.sqlc.dev/en/v1.30.0/howto/push.html) General setup[](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html#general-setup "Link to this heading") --------------------------------------------------------------------------------------------------------- Install `sqlc` using the [suggested instructions](https://docs.sqlc.dev/en/v1.30.0/overview/install.html) . Create three steps in your pipeline for `sqlc diff`, `sqlc vet`, and `sqlc verify`. Run `sqlc push` after merge on your `main` branch. GitHub Actions[](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html#github-actions "Link to this heading") ----------------------------------------------------------------------------------------------------------- We provide the [setup-sqlc](https://github.com/marketplace/actions/setup-sqlc) GitHub Action to install `sqlc`. The action uses the built-in [tool-cache](https://github.com/actions/toolkit/blob/main/packages/tool-cache/README.md) to speed up the installation process. ### diff[](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html#diff "Link to this heading") The following GitHub Workflow configuration runs `sqlc diff` on every push. name: sqlc on: \[push\] jobs: diff: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.30.0' \- run: sqlc diff ### vet[](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html#vet "Link to this heading") The following GitHub Workflow configuration runs [sqlc vet](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html) on every push. You can use `sqlc vet` without a database connection, but you’ll need one if your `sqlc` configuration references the built-in `sqlc/db-prepare` lint rule. name: sqlc on: \[push\] jobs: vet: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.30.0' \# Start a PostgreSQL server \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc vet env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable ### push[](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html#push "Link to this heading") Note Pushing a project is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. The following GitHub Workflow configuration runs [sqlc push](https://docs.sqlc.dev/en/v1.30.0/howto/push.html) on every push to `main`. Create an auth token via the [dashboard](https://dashboard.sqlc.dev/) . name: sqlc on: \[push\] jobs: push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.30.0' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} ### verify[](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html#verify "Link to this heading") Note Verify database migrations is powered by [sqlc Cloud](https://dashboard.sqlc.dev/) . Sign up for [free](https://dashboard.sqlc.dev/) today. name: sqlc on: \[push\] jobs: verify: runs-on: ubuntu-latest steps: \- uses: actions/checkout@v3 \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.30.0' \- uses: sqlc-dev/action-setup-postgres@master with: postgres-version: "16" id: postgres \- run: sqlc verify env: POSTGRESQL\_SERVER\_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} push: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} steps: \- uses: sqlc-dev/setup-sqlc@v3 with: sqlc-version: '1.30.0' \- run: sqlc push env: SQLC\_AUTH\_TOKEN: ${{ secrets.SQLC\_AUTH\_TOKEN }} --- # Configuration — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Configuration * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/config.md.txt) * * * Configuration[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#configuration "Link to this heading") ============================================================================================================== The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This file must be in the directory where the `sqlc` command is run. Version 2[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#version-2 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "2" cloud: project: "" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" database: managed: true rules: \- sqlc/db-prepare \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" ### sql[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#sql "Link to this heading") Each mapping in the `sql` collection has the following keys: * `name`: * An human-friendly identifier for this query set. Optional. * `engine`: * One of `postgresql`, `mysql` or `sqlite`. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `codegen`: * A collection of mappings to configure code generators. See [codegen](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#codegen) for the supported keys. * `gen`: * A mapping to configure built-in code generators. See [gen](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#gen) for the supported keys. * `database`: * A mapping to configure database connections. See [database](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database) for the supported keys. * `rules`: * A collection of rule names to run via `sqlc vet`. See [rules](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#rules) for configuration options. * `analyzer`: * A mapping to configure query analysis. See [analyzer](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#analyzer) for the supported keys. * `strict_function_checks` * If true, return an error if a called SQL function does not exist. Defaults to `false`. * `strict_order_by` * If true, return an error if a order by column is ambiguous. Defaults to `true`. ### codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#codegen "Link to this heading") The `codegen` mapping supports the following keys: * `out`: * Output directory for generated code. * `plugin`: * The name of the plugin. Must be defined in the `plugins` collection. * `options`: * A mapping of plugin-specific options. version: '2' plugins: \- name: py wasm: url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2 sql: \- schema: "schema.sql" queries: "query.sql" engine: postgresql codegen: \- out: src/authors plugin: py options: package: authors emit\_sync\_querier: true emit\_async\_querier: true query\_parameter\_limit: 5 ### database[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database "Link to this heading") The `database` mapping supports the following keys: * `managed`: * If true, connect to a [managed database](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html) . Defaults to `false`. * `uri`: * Database connection URI The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql database: uri: postgresql://postgres:${PG\_PASSWORD}@localhost:5432/authors gen: go: package: authors out: postgresql ### analyzer[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#analyzer "Link to this heading") The `analyzer` mapping supports the following keys: * `database`: * If false, do not use the configured database for query analysis. Defaults to `true`. ### gen[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#gen "Link to this heading") The `gen` mapping supports the following keys: #### go[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#go "Link to this heading") * `package`: * The package name to use for the generated code. Defaults to `out` basename. * `out`: * Output directory for generated code. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `sql_driver`: * Either `github.com/jackc/pgx/v4`, `github.com/jackc/pgx/v5`, `github.com/lib/pq` or `github.com/go-sql-driver/mysql`. No defaults. Required if query annotation `:copyfrom` is used. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Currently only supported for PostgreSQL if `sql_package` is `pgx/v4` or `pgx/v5`, and for SQLite. Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `emit_sql_as_comment`: * If true, emits the SQL statement as a code-block comment above the generated function, appending to any existing comments. Defaults to `false`. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `initialisms`: * An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. * `json_tags_id_uppercase`: * If true, “Id” in json tags will be uppercase. If false, will be camelcase. Defaults to `false` * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * The number of positional arguments that will be generated for Go functions. To always emit a parameter struct, set this to `0`. Defaults to `1`. * `rename`: * Customize the name of generated struct fields. See [Renaming fields](https://docs.sqlc.dev/en/v1.31.0/howto/rename.html) for usage information. * `overrides`: * A collection of configurations to override sqlc’s default Go type choices. See [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for usage information. ##### overrides[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#overrides "Link to this heading") See [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) for an in-depth guide to using type overrides. #### kotlin[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#kotlin "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.31.0/guides/migrating-to-sqlc-gen-kotlin.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. #### python[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#python "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.31.0/guides/migrating-to-sqlc-gen-python.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. * `emit_sync_querier`: * If true, generate a class with synchronous methods. Defaults to `false`. * `emit_async_querier`: * If true, generate a class with asynchronous methods. Defaults to `false`. * `emit_pydantic_models`: * If true, generate classes that inherit from `pydantic.BaseModel`. Otherwise, define classes using the `dataclass` decorator. Defaults to `false`. #### json[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#json "Link to this heading") * `out`: * Output directory for the generated JSON. * `filename`: * Filename for the generated JSON document. Defaults to `codegen_request.json`. * `indent`: * Indent string to use in the JSON document. Defaults to   . ### plugins[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#plugins "Link to this heading") Each mapping in the `plugins` collection has the following keys: * `name`: * The name of this plugin. Required * `env` * A list of environment variables to pass to the plugin. By default, no environment variables are passed. * `process`: A mapping with a single `cmd` key * `cmd`: * The executable to call when using this plugin * `format`: * The format expected. Supports `json` and `protobuf` formats. Defaults to `protobuf`. * `wasm`: A mapping with a two keys `url` and `sha256` * `url`: * The URL to fetch the WASM file. Supports the `https://` or `file://` schemes. * `sha256` * The SHA256 checksum for the downloaded file. version: "2" plugins: \- name: "py" wasm: url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm" sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2" \- name: "js" env: \- PATH process: cmd: "sqlc-gen-json" ### rules[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#rules "Link to this heading") Each mapping in the `rules` collection has the following keys: * `name`: * The name of this rule. Required * `rule`: * A [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Required. * `message`: * An optional message shown when this rule evaluates to `true`. See the [vet](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html) documentation for a list of built-in rules and help writing custom rules. version: "2" sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Global overrides[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#global-overrides "Link to this heading") Sometimes, the same configuration must be done across various specifications of code generation. Then a global definition for type overriding and field renaming can be done using the `overrides` mapping the following manner: version: "2" overrides: go: rename: id: "Identifier" overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" With the previous configuration, whenever a struct field is generated from a table column that is called `id`, it will generated as `Identifier`. Also, whenever there is a nullable `timestamp with time zone` column in a Postgres table, it will be generated as `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in the regular type overrides. This field is only used when there are multiple definitions using multiple engines. Otherwise, the value of the `engine` key defaults to the engine that is currently being used. Currently, type overrides and field renaming, both global and regular, are only fully supported in Go. Version 1[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#version-1 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" emit\_db\_tags: false emit\_prepared\_queries: true emit\_interface: false emit\_exact\_table\_names: false emit\_empty\_slices: false emit\_exported\_queries: false emit\_json\_tags: true emit\_result\_struct\_pointers: false emit\_params\_struct\_pointers: false emit\_methods\_with\_db\_argument: false emit\_pointers\_for\_null\_types: false emit\_enum\_valid\_method: false emit\_all\_enum\_values: false build\_tags: "some\_tag" json\_tags\_case\_style: "camel" omit\_unused\_structs: false output\_batch\_file\_name: "batch.go" output\_db\_file\_name: "db.go" output\_models\_file\_name: "models.go" output\_querier\_file\_name: "querier.go" output\_copyfrom\_file\_name: "copyfrom.go" query\_parameter\_limit: 1 ### packages[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#packages "Link to this heading") Each mapping in the `packages` collection has the following keys: * `name`: * The package name to use for the generated code. Defaults to `path` basename. * `path`: * Output directory for generated code. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `engine`: * Either `postgresql` or `mysql`. Defaults to `postgresql`. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `overrides`: * A list of type override configurations. See the [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html) guide for details. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true and `sql_package` is set to `pgx/v4` or `pgx/v5`, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * Positional arguments that will be generated in Go functions (`>= 0`). To always emit a parameter struct, you would need to set it to `0`. Defaults to `1`. ### overrides[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#id1 "Link to this heading") See the version 1 configuration section of the [Overriding types](https://docs.sqlc.dev/en/v1.31.0/howto/overrides.html#version-1-configuration) guide for details. ### rename[](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#rename "Link to this heading") Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "1" packages: \[...\] rename: spotify\_url: "SpotifyURL" --- # Configuration — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Configuration * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/config.md.txt) * * * Configuration[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#configuration "Link to this heading") ============================================================================================================== The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This file must be in the directory where the `sqlc` command is run. Version 2[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#version-2 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "2" cloud: project: "" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" database: managed: true rules: \- sqlc/db-prepare \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" ### sql[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#sql "Link to this heading") Each mapping in the `sql` collection has the following keys: * `name`: * An human-friendly identifier for this query set. Optional. * `engine`: * One of `postgresql`, `mysql` or `sqlite`. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `codegen`: * A collection of mappings to configure code generators. See [codegen](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#codegen) for the supported keys. * `gen`: * A mapping to configure built-in code generators. See [gen](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#gen) for the supported keys. * `database`: * A mapping to configure database connections. See [database](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database) for the supported keys. * `rules`: * A collection of rule names to run via `sqlc vet`. See [rules](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#rules) for configuration options. * `analyzer`: * A mapping to configure query analysis. See [analyzer](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#analyzer) for the supported keys. * `strict_function_checks` * If true, return an error if a called SQL function does not exist. Defaults to `false`. * `strict_order_by` * If true, return an error if a order by column is ambiguous. Defaults to `true`. ### codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#codegen "Link to this heading") The `codegen` mapping supports the following keys: * `out`: * Output directory for generated code. * `plugin`: * The name of the plugin. Must be defined in the `plugins` collection. * `options`: * A mapping of plugin-specific options. version: '2' plugins: \- name: py wasm: url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2 sql: \- schema: "schema.sql" queries: "query.sql" engine: postgresql codegen: \- out: src/authors plugin: py options: package: authors emit\_sync\_querier: true emit\_async\_querier: true query\_parameter\_limit: 5 ### database[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database "Link to this heading") The `database` mapping supports the following keys: * `managed`: * If true, connect to a [managed database](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html) . Defaults to `false`. * `uri`: * Database connection URI The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql database: uri: postgresql://postgres:${PG\_PASSWORD}@localhost:5432/authors gen: go: package: authors out: postgresql ### analyzer[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#analyzer "Link to this heading") The `analyzer` mapping supports the following keys: * `database`: * If false, do not use the configured database for query analysis. Defaults to `true`. ### gen[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#gen "Link to this heading") The `gen` mapping supports the following keys: #### go[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#go "Link to this heading") * `package`: * The package name to use for the generated code. Defaults to `out` basename. * `out`: * Output directory for generated code. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `sql_driver`: * Either `github.com/jackc/pgx/v4`, `github.com/jackc/pgx/v5`, `github.com/lib/pq` or `github.com/go-sql-driver/mysql`. No defaults. Required if query annotation `:copyfrom` is used. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Currently only supported for PostgreSQL if `sql_package` is `pgx/v4` or `pgx/v5`, and for SQLite. Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `emit_sql_as_comment`: * If true, emits the SQL statement as a code-block comment above the generated function, appending to any existing comments. Defaults to `false`. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `initialisms`: * An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. * `json_tags_id_uppercase`: * If true, “Id” in json tags will be uppercase. If false, will be camelcase. Defaults to `false` * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * The number of positional arguments that will be generated for Go functions. To always emit a parameter struct, set this to `0`. Defaults to `1`. * `rename`: * Customize the name of generated struct fields. See [Renaming fields](https://docs.sqlc.dev/en/v1.31.1/howto/rename.html) for usage information. * `overrides`: * A collection of configurations to override sqlc’s default Go type choices. See [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for usage information. ##### overrides[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#overrides "Link to this heading") See [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) for an in-depth guide to using type overrides. #### kotlin[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#kotlin "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.31.1/guides/migrating-to-sqlc-gen-kotlin.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. #### python[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#python "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.31.1/guides/migrating-to-sqlc-gen-python.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. * `emit_sync_querier`: * If true, generate a class with synchronous methods. Defaults to `false`. * `emit_async_querier`: * If true, generate a class with asynchronous methods. Defaults to `false`. * `emit_pydantic_models`: * If true, generate classes that inherit from `pydantic.BaseModel`. Otherwise, define classes using the `dataclass` decorator. Defaults to `false`. #### json[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#json "Link to this heading") * `out`: * Output directory for the generated JSON. * `filename`: * Filename for the generated JSON document. Defaults to `codegen_request.json`. * `indent`: * Indent string to use in the JSON document. Defaults to   . ### plugins[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#plugins "Link to this heading") Each mapping in the `plugins` collection has the following keys: * `name`: * The name of this plugin. Required * `env` * A list of environment variables to pass to the plugin. By default, no environment variables are passed. * `process`: A mapping with a single `cmd` key * `cmd`: * The executable to call when using this plugin * `format`: * The format expected. Supports `json` and `protobuf` formats. Defaults to `protobuf`. * `wasm`: A mapping with a two keys `url` and `sha256` * `url`: * The URL to fetch the WASM file. Supports the `https://` or `file://` schemes. * `sha256` * The SHA256 checksum for the downloaded file. version: "2" plugins: \- name: "py" wasm: url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm" sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2" \- name: "js" env: \- PATH process: cmd: "sqlc-gen-json" ### rules[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#rules "Link to this heading") Each mapping in the `rules` collection has the following keys: * `name`: * The name of this rule. Required * `rule`: * A [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Required. * `message`: * An optional message shown when this rule evaluates to `true`. See the [vet](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html) documentation for a list of built-in rules and help writing custom rules. version: "2" sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Global overrides[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#global-overrides "Link to this heading") Sometimes, the same configuration must be done across various specifications of code generation. Then a global definition for type overriding and field renaming can be done using the `overrides` mapping the following manner: version: "2" overrides: go: rename: id: "Identifier" overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" With the previous configuration, whenever a struct field is generated from a table column that is called `id`, it will generated as `Identifier`. Also, whenever there is a nullable `timestamp with time zone` column in a Postgres table, it will be generated as `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in the regular type overrides. This field is only used when there are multiple definitions using multiple engines. Otherwise, the value of the `engine` key defaults to the engine that is currently being used. Currently, type overrides and field renaming, both global and regular, are only fully supported in Go. Version 1[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#version-1 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" emit\_db\_tags: false emit\_prepared\_queries: true emit\_interface: false emit\_exact\_table\_names: false emit\_empty\_slices: false emit\_exported\_queries: false emit\_json\_tags: true emit\_result\_struct\_pointers: false emit\_params\_struct\_pointers: false emit\_methods\_with\_db\_argument: false emit\_pointers\_for\_null\_types: false emit\_enum\_valid\_method: false emit\_all\_enum\_values: false build\_tags: "some\_tag" json\_tags\_case\_style: "camel" omit\_unused\_structs: false output\_batch\_file\_name: "batch.go" output\_db\_file\_name: "db.go" output\_models\_file\_name: "models.go" output\_querier\_file\_name: "querier.go" output\_copyfrom\_file\_name: "copyfrom.go" query\_parameter\_limit: 1 ### packages[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#packages "Link to this heading") Each mapping in the `packages` collection has the following keys: * `name`: * The package name to use for the generated code. Defaults to `path` basename. * `path`: * Output directory for generated code. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `engine`: * Either `postgresql` or `mysql`. Defaults to `postgresql`. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `overrides`: * A list of type override configurations. See the [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html) guide for details. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true and `sql_package` is set to `pgx/v4` or `pgx/v5`, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Defaults to `false`. Nullable enum columns also follow this setting unless `emit_pointers_for_null_enum_types` is set. * `emit_pointers_for_null_enum_types`: * Overrides `emit_pointers_for_null_types` for nullable enum columns only. When `true`, nullable enum columns are emitted as pointers (ie. `*UserRole`). When `false`, nullable enum columns use the generated `NullUserRole` wrapper struct even if `emit_pointers_for_null_types` is true. Set this to `false` to keep the pre-v1.31 behavior when upgrading. Only applies to PostgreSQL with `sql_package` `pgx/v4` or `pgx/v5`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * Positional arguments that will be generated in Go functions (`>= 0`). To always emit a parameter struct, you would need to set it to `0`. Defaults to `1`. ### overrides[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#id1 "Link to this heading") See the version 1 configuration section of the [Overriding types](https://docs.sqlc.dev/en/v1.31.1/howto/overrides.html#version-1-configuration) guide for details. ### rename[](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#rename "Link to this heading") Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "1" packages: \[...\] rename: spotify\_url: "SpotifyURL" --- # Configuration — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Configuration * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/config.md.txt) * * * Configuration[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#configuration "Link to this heading") ============================================================================================================== The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This file must be in the directory where the `sqlc` command is run. Version 2[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#version-2 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "2" cloud: project: "" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" database: managed: true rules: \- sqlc/db-prepare \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" ### sql[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#sql "Link to this heading") Each mapping in the `sql` collection has the following keys: * `name`: * An human-friendly identifier for this query set. Optional. * `engine`: * One of `postgresql`, `mysql` or `sqlite`. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `codegen`: * A collection of mappings to configure code generators. See [codegen](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#codegen) for the supported keys. * `gen`: * A mapping to configure built-in code generators. See [gen](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#gen) for the supported keys. * `database`: * A mapping to configure database connections. See [database](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database) for the supported keys. * `rules`: * A collection of rule names to run via `sqlc vet`. See [rules](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#rules) for configuration options. * `analyzer`: * A mapping to configure query analysis. See [analyzer](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#analyzer) for the supported keys. * `strict_function_checks` * If true, return an error if a called SQL function does not exist. Defaults to `false`. * `strict_order_by` * If true, return an error if a order by column is ambiguous. Defaults to `true`. ### codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#codegen "Link to this heading") The `codegen` mapping supports the following keys: * `out`: * Output directory for generated code. * `plugin`: * The name of the plugin. Must be defined in the `plugins` collection. * `options`: * A mapping of plugin-specific options. version: '2' plugins: \- name: py wasm: url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2 sql: \- schema: "schema.sql" queries: "query.sql" engine: postgresql codegen: \- out: src/authors plugin: py options: package: authors emit\_sync\_querier: true emit\_async\_querier: true query\_parameter\_limit: 5 ### database[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database "Link to this heading") The `database` mapping supports the following keys: * `managed`: * If true, connect to a [managed database](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html) . Defaults to `false`. * `uri`: * Database connection URI The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql database: uri: postgresql://postgres:${PG\_PASSWORD}@localhost:5432/authors gen: go: package: authors out: postgresql ### analyzer[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#analyzer "Link to this heading") The `analyzer` mapping supports the following keys: * `database`: * If false, do not use the configured database for query analysis. Defaults to `true`. ### gen[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#gen "Link to this heading") The `gen` mapping supports the following keys: #### go[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#go "Link to this heading") * `package`: * The package name to use for the generated code. Defaults to `out` basename. * `out`: * Output directory for generated code. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `sql_driver`: * Either `github.com/jackc/pgx/v4`, `github.com/jackc/pgx/v5`, `github.com/lib/pq` or `github.com/go-sql-driver/mysql`. No defaults. Required if query annotation `:copyfrom` is used. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Currently only supported for PostgreSQL if `sql_package` is `pgx/v4` or `pgx/v5`, and for SQLite. Defaults to `false`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `emit_sql_as_comment`: * If true, emits the SQL statement as a code-block comment above the generated function, appending to any existing comments. Defaults to `false`. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `initialisms`: * An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. * `json_tags_id_uppercase`: * If true, “Id” in json tags will be uppercase. If false, will be camelcase. Defaults to `false` * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * The number of positional arguments that will be generated for Go functions. To always emit a parameter struct, set this to `0`. Defaults to `1`. * `rename`: * Customize the name of generated struct fields. See [Renaming fields](https://docs.sqlc.dev/en/v1.30.0/howto/rename.html) for usage information. * `overrides`: * A collection of configurations to override sqlc’s default Go type choices. See [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for usage information. ##### overrides[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#overrides "Link to this heading") See [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) for an in-depth guide to using type overrides. #### kotlin[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#kotlin "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.30.0/guides/migrating-to-sqlc-gen-kotlin.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. #### python[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#python "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.30.0/guides/migrating-to-sqlc-gen-python.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. * `emit_sync_querier`: * If true, generate a class with synchronous methods. Defaults to `false`. * `emit_async_querier`: * If true, generate a class with asynchronous methods. Defaults to `false`. * `emit_pydantic_models`: * If true, generate classes that inherit from `pydantic.BaseModel`. Otherwise, define classes using the `dataclass` decorator. Defaults to `false`. #### json[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#json "Link to this heading") * `out`: * Output directory for the generated JSON. * `filename`: * Filename for the generated JSON document. Defaults to `codegen_request.json`. * `indent`: * Indent string to use in the JSON document. Defaults to   . ### plugins[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#plugins "Link to this heading") Each mapping in the `plugins` collection has the following keys: * `name`: * The name of this plugin. Required * `env` * A list of environment variables to pass to the plugin. By default, no environment variables are passed. * `process`: A mapping with a single `cmd` key * `cmd`: * The executable to call when using this plugin * `format`: * The format expected. Supports `json` and `protobuf` formats. Defaults to `protobuf`. * `wasm`: A mapping with a two keys `url` and `sha256` * `url`: * The URL to fetch the WASM file. Supports the `https://` or `file://` schemes. * `sha256` * The SHA256 checksum for the downloaded file. version: "2" plugins: \- name: "py" wasm: url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm" sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2" \- name: "js" env: \- PATH process: cmd: "sqlc-gen-json" ### rules[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#rules "Link to this heading") Each mapping in the `rules` collection has the following keys: * `name`: * The name of this rule. Required * `rule`: * A [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Required. * `message`: * An optional message shown when this rule evaluates to `true`. See the [vet](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html) documentation for a list of built-in rules and help writing custom rules. version: "2" sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Global overrides[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#global-overrides "Link to this heading") Sometimes, the same configuration must be done across various specifications of code generation. Then a global definition for type overriding and field renaming can be done using the `overrides` mapping the following manner: version: "2" overrides: go: rename: id: "Identifier" overrides: \- db\_type: "pg\_catalog.timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" With the previous configuration, whenever a struct field is generated from a table column that is called `id`, it will generated as `Identifier`. Also, whenever there is a nullable `timestamp with time zone` column in a Postgres table, it will be generated as `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in the regular type overrides. This field is only used when there are multiple definitions using multiple engines. Otherwise, the value of the `engine` key defaults to the engine that is currently being used. Currently, type overrides and field renaming, both global and regular, are only fully supported in Go. Version 1[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#version-1 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" emit\_db\_tags: false emit\_prepared\_queries: true emit\_interface: false emit\_exact\_table\_names: false emit\_empty\_slices: false emit\_exported\_queries: false emit\_json\_tags: true emit\_result\_struct\_pointers: false emit\_params\_struct\_pointers: false emit\_methods\_with\_db\_argument: false emit\_pointers\_for\_null\_types: false emit\_enum\_valid\_method: false emit\_all\_enum\_values: false build\_tags: "some\_tag" json\_tags\_case\_style: "camel" omit\_unused\_structs: false output\_batch\_file\_name: "batch.go" output\_db\_file\_name: "db.go" output\_models\_file\_name: "models.go" output\_querier\_file\_name: "querier.go" output\_copyfrom\_file\_name: "copyfrom.go" query\_parameter\_limit: 1 ### packages[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#packages "Link to this heading") Each mapping in the `packages` collection has the following keys: * `name`: * The package name to use for the generated code. Defaults to `path` basename. * `path`: * Output directory for generated code. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `engine`: * Either `postgresql` or `mysql`. Defaults to `postgresql`. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `overrides`: * A list of type override configurations. See the [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html) guide for details. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true and `sql_package` is set to `pgx/v4` or `pgx/v5`, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Defaults to `false`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * Positional arguments that will be generated in Go functions (`>= 0`). To always emit a parameter struct, you would need to set it to `0`. Defaults to `1`. ### overrides[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#id1 "Link to this heading") See the version 1 configuration section of the [Overriding types](https://docs.sqlc.dev/en/v1.30.0/howto/overrides.html#version-1-configuration) guide for details. ### rename[](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#rename "Link to this heading") Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "1" packages: \[...\] rename: spotify\_url: "SpotifyURL" --- # Configuration — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Configuration * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/config.md) * * * Configuration[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#configuration "Link to this heading") ============================================================================================================== The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This file must be in the directory where the `sqlc` command is run. Version 2[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#version-2 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "2" cloud: project: "" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" database: managed: true rules: \- sqlc/db-prepare \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" ### sql[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#sql "Link to this heading") Each mapping in the `sql` collection has the following keys: * `name`: * An human-friendly identifier for this query set. Optional. * `engine`: * One of `postgresql`, `mysql` or `sqlite`. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `codegen`: * A collection of mappings to configure code generators. See [codegen](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#codegen) for the supported keys. * `gen`: * A mapping to configure built-in code generators. See [gen](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#gen) for the supported keys. * `database`: * A mapping to configure database connections. See [database](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database) for the supported keys. * `rules`: * A collection of rule names to run via `sqlc vet`. See [rules](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#rules) for configuration options. * `analyzer`: * A mapping to configure query analysis. See [analyzer](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#analyzer) for the supported keys. * `strict_function_checks` * If true, return an error if a called SQL function does not exist. Defaults to `false`. * `strict_order_by` * If true, return an error if a order by column is ambiguous. Defaults to `true`. ### codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#codegen "Link to this heading") The `codegen` mapping supports the following keys: * `out`: * Output directory for generated code. * `plugin`: * The name of the plugin. Must be defined in the `plugins` collection. * `options`: * A mapping of plugin-specific options. version: '2' plugins: \- name: py wasm: url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2 sql: \- schema: "schema.sql" queries: "query.sql" engine: postgresql codegen: \- out: src/authors plugin: py options: package: authors emit\_sync\_querier: true emit\_async\_querier: true query\_parameter\_limit: 5 ### database[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database "Link to this heading") The `database` mapping supports the following keys: * `managed`: * If true, connect to a [managed database](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html) . Defaults to `false`. * `uri`: * Database connection URI The `uri` string can contain references to environment variables using the `${...}` syntax. In the following example, the connection string will have the value of the `PG_PASSWORD` environment variable set as its password. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql database: uri: postgresql://postgres:${PG\_PASSWORD}@localhost:5432/authors gen: go: package: authors out: postgresql ### analyzer[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#analyzer "Link to this heading") The `analyzer` mapping supports the following keys: * `database`: * If false, do not use the configured database for query analysis. Defaults to `true`. ### gen[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#gen "Link to this heading") The `gen` mapping supports the following keys: #### go[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#go "Link to this heading") * `package`: * The package name to use for the generated code. Defaults to `out` basename. * `out`: * Output directory for generated code. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Currently only supported for PostgreSQL if `sql_package` is `pgx/v4` or `pgx/v5`, and for SQLite. Defaults to `false`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `emit_sql_as_comment`: * If true, emits the SQL statement as a code-block comment above the generated function, appending to any existing comments. Defaults to `false`. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `initialisms`: * An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. * `json_tags_id_uppercase`: * If true, “Id” in json tags will be uppercase. If false, will be camelcase. Defaults to `false` * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * The number of positional arguments that will be generated for Go functions. To always emit a parameter struct, set this to `0`. Defaults to `1`. * `rename`: * Customize the name of generated struct fields. See [Renaming fields](https://docs.sqlc.dev/en/v1.27.0/howto/rename.html) for usage information. * `overrides`: * It is a collection of definitions that dictates which types are used to map a database types. ##### overrides[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#overrides "Link to this heading") See [Overriding types](https://docs.sqlc.dev/en/v1.27.0/howto/overrides.html) for an in-depth guide to using type overrides. Each mapping of the `overrides` collection has the following keys: * `db_type`: * The PostgreSQL or MySQL type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use the pg\_catalog prefixed names where available. Can’t be used if the `column` key is defined. * `column`: * In case the type overriding should be done on specific a column of a table instead of a type. `column` should be of the form `table.column` but you can be even more specific by specifying `schema.table.column` or `catalog.schema.table.column`. Can’t be used if the `db_type` key is defined. * `go_type`: * A fully qualified name to a Go type to use in the generated code. * `go_struct_tag`: * A reflect-style struct tag to use in the generated code, e.g. `a:"b" x:"y,z"`. If you want general json/db tags for all fields, use `emit_db_tags` and/or `emit_json_tags` instead. * `nullable`: * If `true`, use this type when a column is nullable. Defaults to `false`. For more complicated import paths, the `go_type` can also be an object with the following keys: * `import`: * The import path for the package where the type is defined. * `package`: * The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name. * `type`: * The type name itself, without any package prefix. * `pointer`: * If set to `true`, generated code will use pointers to the type rather than the type itself. * `slice`: * If set to `true`, generated code will use a slice of the type rather than the type itself. #### kotlin[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#kotlin "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.27.0/guides/migrating-to-sqlc-gen-kotlin.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. #### python[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#python "Link to this heading") > Removed in v1.17.0 and replaced by the [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) > plugin. Follow the [migration guide](https://docs.sqlc.dev/en/v1.27.0/guides/migrating-to-sqlc-gen-python.html) > to switch. * `package`: * The package name to use for the generated code. * `out`: * Output directory for generated code. * `emit_exact_table_names`: * If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`. * `emit_sync_querier`: * If true, generate a class with synchronous methods. Defaults to `false`. * `emit_async_querier`: * If true, generate a class with asynchronous methods. Defaults to `false`. * `emit_pydantic_models`: * If true, generate classes that inherit from `pydantic.BaseModel`. Otherwise, define classes using the `dataclass` decorator. Defaults to `false`. #### json[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#json "Link to this heading") * `out`: * Output directory for the generated JSON. * `filename`: * Filename for the generated JSON document. Defaults to `codegen_request.json`. * `indent`: * Indent string to use in the JSON document. Defaults to   . ### plugins[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#plugins "Link to this heading") Each mapping in the `plugins` collection has the following keys: * `name`: * The name of this plugin. Required * `env` * A list of environment variables to pass to the plugin. By default, no environment variables are passed. * `process`: A mapping with a single `cmd` key * `cmd`: * The executable to call when using this plugin * `wasm`: A mapping with a two keys `url` and `sha256` * `url`: * The URL to fetch the WASM file. Supports the `https://` or `file://` schemes. * `sha256` * The SHA256 checksum for the downloaded file. version: "2" plugins: \- name: "py" wasm: url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm" sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2" \- name: "js" env: \- PATH process: cmd: "sqlc-gen-json" ### rules[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#rules "Link to this heading") Each mapping in the `rules` collection has the following keys: * `name`: * The name of this rule. Required * `rule`: * A [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Required. * `message`: * An optional message shown when this rule evaluates to `true`. See the [vet](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html) documentation for a list of built-in rules and help writing custom rules. version: "2" sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ### Global overrides[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#global-overrides "Link to this heading") Sometimes, the same configuration must be done across various specifications of code generation. Then a global definition for type overriding and field renaming can be done using the `overrides` mapping the following manner: version: "2" overrides: go: rename: id: "Identifier" overrides: \- db\_type: "timestamptz" nullable: true engine: "postgresql" go\_type: import: "gopkg.in/guregu/null.v4" package: "null" type: "Time" sql: \- schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" \- schema: "mysql/schema.sql" queries: "mysql/query.sql" engine: "mysql" gen: go: package: "authors" out: "mysql" With the previous configuration, whenever a struct field is generated from a table column that is called `id`, it will generated as `Identifier`. Also, whenever there is a nullable `timestamp with time zone` column in a Postgres table, it will be generated as `null.Time`. Note that the mapping for global type overrides has a field called `engine` that is absent in the regular type overrides. This field is only used when there are multiple definitions using multiple engines. Otherwise, the value of the `engine` key defaults to the engine that is currently being used. Currently, type overrides and field renaming, both global and regular, are only fully supported in Go. Version 1[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#version-1 "Link to this heading") ------------------------------------------------------------------------------------------------------ version: "1" packages: \- name: "db" path: "internal/db" queries: "./sql/query/" schema: "./sql/schema/" engine: "postgresql" emit\_db\_tags: false emit\_prepared\_queries: true emit\_interface: false emit\_exact\_table\_names: false emit\_empty\_slices: false emit\_exported\_queries: false emit\_json\_tags: true emit\_result\_struct\_pointers: false emit\_params\_struct\_pointers: false emit\_methods\_with\_db\_argument: false emit\_pointers\_for\_null\_types: false emit\_enum\_valid\_method: false emit\_all\_enum\_values: false build\_tags: "some\_tag" json\_tags\_case\_style: "camel" omit\_unused\_structs: false output\_batch\_file\_name: "batch.go" output\_db\_file\_name: "db.go" output\_models\_file\_name: "models.go" output\_querier\_file\_name: "querier.go" output\_copyfrom\_file\_name: "copyfrom.go" query\_parameter\_limit: 1 ### packages[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#packages "Link to this heading") Each mapping in the `packages` collection has the following keys: * `name`: * The package name to use for the generated code. Defaults to `path` basename. * `path`: * Output directory for generated code. * `queries`: * Directory of SQL queries or path to single SQL file; or a list of paths. * `schema`: * Directory of SQL migrations or path to single SQL file; or a list of paths. * `engine`: * Either `postgresql` or `mysql`. Defaults to `postgresql`. * `sql_package`: * Either `pgx/v4`, `pgx/v5` or `database/sql`. Defaults to `database/sql`. * `emit_db_tags`: * If true, add DB tags to generated structs. Defaults to `false`. * `emit_prepared_queries`: * If true, include support for prepared queries. Defaults to `false`. * `emit_interface`: * If true, output a `Querier` interface in the generated package. Defaults to `false`. * `emit_exact_table_names`: * If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`. * `emit_empty_slices`: * If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`. * `emit_exported_queries`: * If true, autogenerated SQL statement can be exported to be accessed by another package. * `emit_json_tags`: * If true, add JSON tags to generated structs. Defaults to `false`. * `emit_result_struct_pointers`: * If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`. * `emit_params_struct_pointers`: * If true, parameters are passed as pointers to structs. Defaults to `false`. * `emit_methods_with_db_argument`: * If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`. * `emit_pointers_for_null_types`: * If true and `sql_package` is set to `pgx/v4` or `pgx/v5`, generated types for nullable columns are emitted as pointers (ie. `*string`) instead of `database/sql` null types (ie. `NullString`). Defaults to `false`. * `emit_enum_valid_method`: * If true, generate a Valid method on enum types, indicating whether a string is a valid enum value. * `emit_all_enum_values`: * If true, emit a function per enum type that returns all valid enum values. * `build_tags`: * If set, add a `//go:build ` directive at the beginning of each generated Go file. * `json_tags_case_style`: * `camel` for camelCase, `pascal` for PascalCase, `snake` for snake\_case or `none` to use the column name in the DB. Defaults to `none`. * `omit_unused_structs`: * If `true`, sqlc won’t generate table and enum structs that aren’t used in queries for a given package. Defaults to `false`. * `output_batch_file_name`: * Customize the name of the batch file. Defaults to `batch.go`. * `output_db_file_name`: * Customize the name of the db file. Defaults to `db.go`. * `output_models_file_name`: * Customize the name of the models file. Defaults to `models.go`. * `output_querier_file_name`: * Customize the name of the querier file. Defaults to `querier.go`. * `output_copyfrom_file_name`: * Customize the name of the copyfrom file. Defaults to `copyfrom.go`. * `output_files_suffix`: * If specified the suffix will be added to the name of the generated files. * `query_parameter_limit`: * Positional arguments that will be generated in Go functions (`>= 0`). To always emit a parameter struct, you would need to set it to `0`. Defaults to `1`. ### overrides[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#id1 "Link to this heading") The default mapping of PostgreSQL/MySQL types to Go types only uses packages outside the standard library when it must. For example, the `uuid` PostgreSQL type is mapped to `github.com/google/uuid`. If a different Go package for UUIDs is required, specify the package in the `overrides` array. In this case, I’m going to use the `github.com/gofrs/uuid` instead. version: "1" packages: \[...\] overrides: \- go\_type: "github.com/gofrs/uuid.UUID" db\_type: "uuid" Each override document has the following keys: * `db_type`: * The PostgreSQL or MySQL type to override. Find the full list of supported types in [postgresql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/postgresql_type.go#L12) or [mysql\_type.go](https://github.com/sqlc-dev/sqlc/blob/main/internal/codegen/golang/mysql_type.go#L12) . Note that for Postgres you must use the pg\_catalog prefixed names where available. * `go_type`: * A fully qualified name to a Go type to use in the generated code. * `go_struct_tag`: * A reflect-style struct tag to use in the generated code, e.g. `a:"b" x:"y,z"`. If you want general json/db tags for all fields, use `emit_db_tags` and/or `emit_json_tags` instead. * `nullable`: * If true, use this type when a column is nullable. Defaults to `false`. Note that a single `db_type` override configuration applies to either nullable or non-nullable columns, but not both. If you want a single `go_type` to override in both cases, you’ll need to specify two overrides. For more complicated import paths, the `go_type` can also be an object. version: "1" packages: \[...\] overrides: \- db\_type: "uuid" go\_type: import: "a/b/v2" package: "b" type: "MyType" #### Per-Column Type Overrides[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#per-column-type-overrides "Link to this heading") Sometimes you would like to override the Go type used in model or query generation for a specific field of a table and not on a type basis as described in the previous section. This may be configured by specifying the `column` property in the override definition. `column` should be of the form `table.column` but you can be even more specific by specifying `schema.table.column` or `catalog.schema.table.column`. version: "1" packages: \[...\] overrides: \- column: "authors.id" go\_type: "github.com/segmentio/ksuid.KSUID" #### Package Level Overrides[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#package-level-overrides "Link to this heading") Overrides can be configured globally, as demonstrated in the previous sections, or they can be configured per-package which scopes the override behavior to just a single package: version: "1" packages: \- overrides: \[...\] ### rename[](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#rename "Link to this heading") Struct field names are generated from column names using a simple algorithm: split the column name on underscores and capitalize the first letter of each part. account \-> Account spotify\_url \-> SpotifyUrl app\_id \-> AppID If you’re not happy with a field’s generated name, use the `rename` mapping to pick a new name. The keys are column names and the values are the struct field name to use. version: "1" packages: \[...\] rename: spotify\_url: "SpotifyURL" --- # Changelog — sqlc 1.27.0 documentation * [](https://docs.sqlc.dev/en/v1.27.0/index.html) * Changelog * [Edit on GitHub](https://github.com/sqlc-dev/sqlc/blob/v1.27.0/docs/reference/changelog.md) * * * Changelog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#changelog "Link to this heading") ========================================================================================================= All notable changes to this project will be documented in this file. [1.27.0](https://github.com/sqlc-dev/sqlc/releases/tag/1.27.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-27-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-08-05 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#bug-fixes "Link to this heading") * (dbmanager) Add leading slash to db uri path rewrite (#3493) * (verify) Include database engine in request (#3522) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#features "Link to this heading") * (golang) Add initialisms configuration (#3308) * (compiler) Support subqueries in the FROM clause (second coming) (#3310) * Managed databases with any accessible server (#3421) * (vet) Use new dbmanager client (#3423) * (verify) Update verify to work with managed databases (#3425) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#documentation "Link to this heading") * Fix typo in config (#3358) * Resolve a typo in configuration keys (#3349) * Add sponsorship information to README (#3413) * Update the language-support to include C# (#3408) * Add migration guide for hosted managed databases (#3417) * Fix readme links (#3424) * Update the managed db and verify documentation (#3426) * Add sponsor image (#3428) * Add Ruby as supported language (#3487) * Update migrating-to-sqlc-gen-kotlin.md (#3454) * Fix typo in comment (#3316) * Fix deprecated build tag format (#3361) ### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#testing "Link to this heading") * (endtoend) Re-use databases when possible (#3315) * Enabled MySQL database (#3318) * Remove internal/sqltest/hosted package (#3521) [1.26.0](https://github.com/sqlc-dev/sqlc/releases/tag/1.26.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-26-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-03-28 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#release-notes "Link to this heading") This release is mainly a bug fix release. It also includes an [important security fix](https://github.com/sqlc-dev/sqlc/issues/3194) for users using output plugins. ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#changes "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id3 "Link to this heading") * (docker) Use distroless base image instead of scratch (#3111) * (generate) Ensure files are created inside output directory (#3195) * (mysql) BREAKING: Use `int16` for MySQL `SMALLINT` and `YEAR` (#3106) * (mysql) BREAKING: Use `int8` for MySQL TINYINT (#3298) * (mysql) Variables not resolving in ORDER BY statements (#3115) * (opts) Validate SQL package and driver options (#3241) * (postgres/batch) Ignore query\_parameter\_limit for batches * (scripts) Remove deprecated test output regeneration script (#3105) * (sqlite) Correctly skip unknown statements (#3239) #### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id4 "Link to this heading") * (postgres) Add instructions for PostGIS/GEOS (#3182) * Improve details on TEXT (#3247) #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id5 "Link to this heading") * (generate) Avoid generating empty Go imports (#3135) * (mysql) Add NEXTVAL() to the MySQL catalog (#3147) * (mysql) Support json.RawMessage for LOAD DATA INFILE (#3099) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#build "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 to 5.5.5 (#3259) * (deps) Bump modernc.org/sqlite to 1.29.5 (#3200) * (deps) Bump github.com/go-sql-driver/mysql to 1.8.0 (#3257) * (deps) Bump github.com/tetratelabs/wazero to 1.7.0 (#3096) * (deps) Bump github.com/pganalyze/pg\_query\_go to v5 (#3096) [1.25.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.25.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-25-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-01-03 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id7 "Link to this heading") #### Add tags to push and verify[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#add-tags-to-push-and-verify "Link to this heading") You can add tags when [pushing](https://docs.sqlc.dev/en/v1.27.0/howto/push.html) schema and queries to [sqlc Cloud](https://dashboard.sqlc.dev/) . Tags operate like git tags, meaning you can overwrite previously-pushed tag values. We suggest tagging pushes to associate them with something relevant from your environment, e.g. a git tag or branch name. $ sqlc push --tag v1.0.0 Once you’ve created a tag, you can refer to it when [verifying](https://docs.sqlc.dev/en/v1.27.0/howto/verify.html) changes, allowing you to compare the existing schema against a known set of previous queries. $ sqlc verify --against v1.0.0 #### C-ya, `cgo`[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#c-ya-cgo "Link to this heading") Over the last month, we’ve switched out a few different modules to remove our reliance on [cgo](https://go.dev/blog/cgo) . Previously, we needed cgo for three separate functions: * Parsing PostgreSQL queries with [pganalyze/pg\_query\_go](https://github.com/pganalyze/pg_query_go) * Running SQLite databases with [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) * Executing WASM / WASI code with [bytecodealliance/wasmtime-go](https://github.com/bytecodealliance/wasmtime-go) With the help of the community, we found cgo-free alternatives for each module: * Parsing PostgreSQL queries, now using [wasilibs/go-pgquery](https://github.com/wasilibs/go-pgquery) * Running SQLite databases, now using [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) * Executing WASM / WASI code, now using [tetratelabs/wazero](https://github.com/tetratelabs/wazero) For the first time, Windows users can enjoy full PostgreSQL support without using [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) . It’s a Christmas miracle! If you run into any issues with the updated dependencies, please [open an issue](https://github.com/sqlc-dev/sqlc/issues) . ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id8 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id9 "Link to this heading") * (codegen) Wrong yaml annotation in go codegen options for output\_querier\_file\_name (#3006) * (codegen) Use derived ArrayDims instead of deprecated attndims (#3032) * (codegen) Take the maximum array dimensions (#3034) * (compiler) Skip analysis of queries without a `name` annotation (#3072) * (codegen/golang) Don’t import `"strings"` for `sqlc.slice()` with pgx (#3073) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id10 "Link to this heading") * Add name to query set configuration (#3011) * Add a sidebar link for `push`, add Go plugin link (#3023) * Update banner for sqlc-gen-typescript (#3036) * Add strict\_order\_by in doc (#3044) * Re-order the migration tools list (#3064) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id11 "Link to this heading") * (analyzer) Return zero values when encountering unexpected ast nodes (#3069) * (codegen/go) add omit\_sqlc\_version to Go code generation (#3019) * (codgen/go) Add `emit_sql_as_comment` option to Go code plugin (#2735) * (plugins) Use wazero instead of wasmtime (#3042) * (push) Add tag support (#3074) * (sqlite) Support emit\_pointers\_for\_null\_types (#3026) ### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id12 "Link to this heading") * (endtoend) Enable for more build targets (#3041) * (endtoend) Run MySQL and PostgreSQL locally on the runner (#3095) * (typescript) Test against sqlc-gen-typescript (#3046) * Add tests for omit\_sqlc\_version (#3020) * Split schema and query for test (#3094) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id13 "Link to this heading") * (deps) Bump idna from 3.4 to 3.6 in /docs (#3010) * (deps) Bump sphinx-rtd-theme from 1.3.0 to 2.0.0 in /docs (#3016) * (deps) Bump golang from 1.21.4 to 1.21.5 (#3043) * (deps) Bump actions/setup-go from 4 to 5 (#3047) * (deps) Bump github.com/jackc/pgx/v5 from 5.5.0 to 5.5.1 (#3050) * (deps) Upgrade to latest version of github.com/wasilibs/go-pgquery (#3052) * (deps) Bump google.golang.org/grpc from 1.59.0 to 1.60.0 (#3053) * (deps) Bump babel from 2.13.1 to 2.14.0 in /docs (#3055) * (deps) Bump actions/upload-artifact from 3 to 4 (#3061) * (deps) Bump modernc.org/sqlite from 1.27.0 to 1.28.0 (#3062) * (deps) Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#3068) * (deps) Bump google.golang.org/grpc from 1.60.0 to 1.60.1 (#3070) * (deps) Bump google.golang.org/protobuf from 1.31.0 to 1.32.0 (#3079) * (deps) Bump github.com/tetratelabs/wazero from 1.5.0 to 1.6.0 (#3096) * (sqlite) Update to antlr 4.13.1 (#3086) * (sqlite) Disable modernc for WASM (#3048) * (sqlite) Switch from mattn/go-sqlite3 to modernc.org/sqlite (#3040) [1.24.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.24.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-24-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-11-22 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id15 "Link to this heading") #### Verifying database schema changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#verifying-database-schema-changes "Link to this heading") Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. #### Rename `upload` command to `push`[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#rename-upload-command-to-push "Link to this heading") We’ve renamed the `upload` sub-command to `push`. We changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. We also add annotations to each push. By default, we include these environment variables if they are present: GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA Like upload, `push` should be run when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. #### MySQL support in `createdb`[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#mysql-support-in-createdb "Link to this heading") The `createdb` command, added in the last release, now supports MySQL. If you have a cloud project configured, you can use `sqlc createdb` to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html#with-other-tools) documentation. #### Plugin interface refactor[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#plugin-interface-refactor "Link to this heading") This release includes a refactored plugin interface to better support future functionality. Plugins now support different methods via a gRPC service interface, allowing plugins to support different functionality in a backwards-compatible way. By using gRPC interfaces, we can even (theoretically) support [remote plugins](https://github.com/sqlc-dev/sqlc/pull/2938) , but that’s something for another day. ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id16 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id17 "Link to this heading") * (engine/sqlite) Support CASE expr (#2926) * (engine/sqlite) Support -> and ->> operators (#2927) * (vet) Add a nil pointer check to prevent db/prepare panic (#2934) * (compiler) Prevent panic when compiler is nil (#2942) * (codegen/golang) Move more Go-specific config validation into the plugin (#2951) * (compiler) No panic on full-qualified column names (#2956) * (docs) Better discussion of type override nuances (#2972) * (codegen) Never generate return structs for :exec (#2976) * (generate) Update help text for generate to be more generic (#2981) * (generate) Return an error instead of generating duplicate Go names (#2962) * (codegen/golang) Pull opts into its own package (#2920) * (config) Make some struct and field names less confusing (#2922) #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id18 "Link to this heading") * (codegen) Remove Go specific overrides from codegen proto (#2929) * (plugin) Use gRPC interface for codegen plugin communication (#2930) * (plugin) Calculate SHA256 if it does not exist (#2935) * (sqlc-gen-go) Add script to mirror code to sqlc-gen-go (#2952) * (createdb) Add support for MySQL (#2980) * (verify) Add new command to verify queries and migrations (#2986) #### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id19 "Link to this heading") * (ci) New workflow for sqlc-gen-python (#2936) * (ci) Rely on go.mod to determine which Go version to use (#2971) * (tests) Add glob pattern tests to sqlpath.Glob (#2995) * (examples) Use hosted MySQL databases for tests (#2982) * (docs) Clean up a little, update LICENSE and README (#2941) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id20 "Link to this heading") * (deps) Bump babel from 2.13.0 to 2.13.1 in /docs (#2911) * (deps) Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2944) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.17 to 1.14.18 (#2945) * (deps) Bump golang.org/x/sync from 0.4.0 to 0.5.0 (#2946) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2947) * (deps) Change github.com/pingcap/tidb/parser to github.com/pingcap/tidb/pkg/parser * (deps) Bump github.com/google/cel-go from 0.18.1 to 0.18.2 (#2969) * (deps) Bump urllib3 from 2.0.7 to 2.1.0 in /docs (#2975) * (buf) Change root of Buf module (#2987) * (deps) Bump certifi from 2023.7.22 to 2023.11.17 in /docs (#2993) * (ci) Bump Go version from 1.21.3 to 1.21.4 in workflows and Dockerfile (#2961) [1.23.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.23.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-23-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-10-24 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id22 "Link to this heading") #### Database-backed query analysis[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#database-backed-query-analysis "Link to this heading") With a [database connection](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database) configured, `sqlc generate` will gather metadata from that database to support its query analysis. Turning this on resolves a [large number of issues](https://github.com/sqlc-dev/sqlc/issues?q=is%3Aissue+label%3Aanalyzer) in the backlog related to type inference and more complex queries. The easiest way to try it out is with [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html) . The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. #### New `createdb` command[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#new-createdb-command "Link to this heading") When you have a cloud project configured, you can use the new `sqlc createdb` command to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html#with-other-tools) documentation. #### Support for pgvector[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#support-for-pgvector "Link to this heading") If you’re using [pgvector](https://github.com/pgvector/pgvector) , say goodbye to custom overrides! sqlc now generates code using [pgvector-go](https://github.com/pgvector/pgvector-go#pgx) as long as you’re using `pgx`. The pgvector extension is also available in [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html) . #### Go build tags[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#go-build-tags "Link to this heading") With the new `emit_build_tags` configuration parameter you can set build tags for sqlc to add at the top of generated source files. ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id23 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id24 "Link to this heading") * (codegen) Correct column names in :copyfrom (#2838) * (compiler) Search SELECT and UPDATE the same way (#2841) * (dolphin) Support more UNIONs for MySQL (#2843) * (compiler) Account for parameters without parents (#2844) * (postgresql) Remove temporary pool config (#2851) * (golang) Escape reserved keywords (#2849) * (mysql) Handle simplified CASE statements (#2852) * (engine/dolphin) Support enum in ALTER definition (#2680) * (mysql) Add, drop, rename and change enum values (#2853) * (config) Validate `database` config in all cases (#2856) * (compiler) Use correct func signature for `CommentSyntax` on windows (#2867) * (codegen/go) Prevent filtering of embedded struct fields (#2868) * (compiler) Support functions with OUT params (#2865) * (compiler) Pull in array information from analyzer (#2864) * (analyzer) Error on unexpanded star expression (#2882) * (vet) Remove rollback statements from DDL (#2895) #### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id25 "Link to this heading") * Add stable anchors to changelog (#2784) * Fix typo in v1.22.0 changelog (#2796) * Add sqlc upload to CI / CD guide (#2797) * Fix broken link, add clarity to plugins doc (#2813) * Add clarity and reference to JSON tags (#2819) * Replace form with dashboard link (#2840) * (examples) Update examples to use pgx/v5 (#2863) * Use docker compose v2 and update MYSQL\_DATABASE env var (#2870) * Update getting started guides, use pgx for Postgres guide (#2891) * Use managed databases in PostgreSQL getting started guide (#2892) * Update managed databases doc to discuss codegen (#2897) * Add managed dbs to CI/CD and vet guides (#2896) * Document database-backed query analyzer (#2904) #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id26 "Link to this heading") * (codegen) Support setting Go build tags (#2012) (#2807) * (generate) Reorder codegen handlers to prefer plugins (#2814) * (devenv) Add vscode settings.json with auto newline (#2834) * (cmd) Support sqlc.yml configuration file (#2828) * (analyzer) Analyze queries using a running PostgreSQL database (#2805) * (sql/ast) Render AST to SQL (#2815) * (codegen) Include plugin information (#2846) * (postgresql) Add ALTER VIEW … SET SCHEMA (#2855) * (compiler) Parse query parameter metadata from comments (#2850) * (postgresql) Support system columns on tables (#2871) * (compiler) Support LEFT JOIN on aliased table (#2873) * Improve messaging for common cloud config and rpc errors (#2885) * Abort compiler when rpc fails as unauthenticated (#2887) * (codegen) Add support for pgvector and pgvector-go (#2888) * (analyzer) Cache query analysis (#2889) * (createdb) Create ephemeral databases (#2894) * (debug) Add databases=managed debug option (#2898) * (config) Remove managed database validation (#2901) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#miscellaneous-tasks "Link to this heading") * (endtoend) Fix test output for do tests (#2782) #### Refactor[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#refactor "Link to this heading") * (codegen) Remove golang and json settings from plugin proto (#2822) * (codegen) Removed deprecated code and improved speed (#2899) #### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id27 "Link to this heading") * (endtoend) Split shema and queries (#2803) * Fix a few incorrect testcases (#2804) * (analyzer) Add more database analyzer test cases (#2854) * Add more analyzer test cases (#2866) * Add more test cases for new analyzer (#2879) * (endtoend) Enabled managed-db tests in CI (#2883) * Enabled pgvector tests for managed dbs (#2893) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id28 "Link to this heading") * (deps) Bump packaging from 23.1 to 23.2 in /docs (#2791) * (deps) Bump urllib3 from 2.0.5 to 2.0.6 in /docs (#2798) * (deps) Bump babel from 2.12.1 to 2.13.0 in /docs (#2799) * (deps) Bump golang.org/x/sync from 0.3.0 to 0.4.0 (#2810) * (deps) Bump golang from 1.21.1 to 1.21.2 (#2811) * (deps) Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (#2826) * (deps) Bump golang from 1.21.2 to 1.21.3 (#2824) * (deps) Bump google.golang.org/grpc from 1.58.2 to 1.58.3 (#2825) * (deps) Bump golang.org/x/net from 0.12.0 to 0.17.0 (#2836) * (deps) Bump urllib3 from 2.0.6 to 2.0.7 in /docs (#2872) * (deps) Bump google.golang.org/grpc from 1.58.3 to 1.59.0 (#2876) * (deps) Upgrade wasmtime-go from 13.0.0 to 14.0.0 (#2900) #### Ci[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#ci "Link to this heading") * Bump go version in workflows (#2835) [1.22.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.22.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-22-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-26 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id30 "Link to this heading") #### Managed databases for `sqlc vet`[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#managed-databases-for-sqlc-vet "Link to this heading") If you’re using [sqlc vet](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html) to write rules that require access to a running database, `sqlc` can now start and manage that database for you. PostgreSQL support is available today, with MySQL on the way. When you turn on managed databases, `sqlc` will use your schema to create a template database that it can copy to make future runs of `sqlc vet` very performant. This feature relies on configuration obtained via [sqlc Cloud](https://dashboard.sqlc.dev/) . Read more in the [managed databases](https://docs.sqlc.dev/en/v1.27.0/howto/managed-databases.html) documentation. ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id31 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id32 "Link to this heading") * (codegen/golang) Refactor imports code to match templates (#2709) * (codegen/golang) Support name type (#2715) * (wasm) Move Runner struct to shared file (#2725) * (engine/sqlite) Fix grammer to avoid missing join\_constraint (#2732) * (convert) Support YAML anchors in plugin options (#2733) * (mysql) Disallow time.Time in mysql :copyfrom queries, not all queries (#2768) * (engine/sqlite) Fix convert process for VALUES (#2737) #### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id33 "Link to this heading") * Clarify nullable override behavior (#2753) * Add managed databases to sidebar (#2764) * Pull renaming and type overrides into separate sections (#2774) * Update the docs banner for managed dbs (#2775) #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id34 "Link to this heading") * (config) Enables the configuration of copyfrom.go similar to quierer and friends (#2727) * (vet) Run rules against a managed database (#2751) * (upload) Point upload command at new endpoint (#2772) * (compiler) Support DO statements (#2777) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id35 "Link to this heading") * (endtoend) Skip tests missing secrets (#2763) * Skip certain tests on PRs (#2769) #### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id36 "Link to this heading") * (endtoend) Verify all schemas in endtoend (#2744) * (examples) Use a hosted database for example testing (#2749) * (endtoend) Pull region from environment (#2750) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id37 "Link to this heading") * (deps) Bump golang from 1.21.0 to 1.21.1 (#2711) * (deps) Bump google.golang.org/grpc from 1.57.0 to 1.58.1 (#2743) * (deps) Bump wasmtime-go from v12 to v13 (#2756) * (windows) Downgrade to mingw 11.2.0 (#2757) * (deps) Bump urllib3 from 2.0.4 to 2.0.5 in /docs (#2747) * (deps) Bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#2758) * (deps) Bump github.com/google/cel-go from 0.18.0 to 0.18.1 (#2778) #### Ci[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id38 "Link to this heading") * Bump go version to latest in ci workflows (#2722) [1.21.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.21.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-21-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-06 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id40 "Link to this heading") This is primarily a bugfix release, along with some documentation and testing improvements. #### MySQL engine improvements[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#mysql-engine-improvements "Link to this heading") `sqlc` previously didn’t know how to parse a `CALL` statement when using the MySQL engine, which meant it was impossible to use sqlc with stored procedures in MySQL databases. Additionally, `sqlc` now supports `IS [NOT] NULL` in queries. And `LIMIT` and `OFFSET` clauses now work with `UNION`. #### SQLite engine improvements[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sqlite-engine-improvements "Link to this heading") GitHub user [@orisano](https://github.com/orisano) continues to bring bugfixes and improvements to `sqlc`’s SQLite engine. See the “Changes” section below for the full list. #### Plugin access to environment variables[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#plugin-access-to-environment-variables "Link to this heading") If you’re authoring a [sqlc plugin](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#../guides/plugins.html) , you can now configure sqlc to pass your plugin the values of specific environment variables. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id41 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id42 "Link to this heading") * Myriad string formatting changes (#2558) * (engine/sqlite) Support quoted identifier (#2556) * (engine/sqlite) Fix compile error (#2564) * (engine/sqlite) Fixed detection of column alias without AS (#2560) * (ci) Bump go version to 1.20.7 (#2568) * Remove references to deprecated `--experimental` flag (#2567) * (postgres) Fixed a problem with array dimensions disappearing when using “ALTER TABLE ADD COLUMN” (#2572) * Remove GitHub sponsor integration (#2574) * (docs) Improve discussion of prepared statements support (#2604) * (docs) Remove multidimensional array qualification in datatypes.md (#2619) * (config) Go struct tag parsing (#2606) * (compiler) Fix to not scan children under ast.RangeSubselect when retrieving table listing (#2573) * (engine/sqlite) Support NOT IN (#2587) * (codegen/golang) Fixed detection of the used package (#2597) * (engine/dolphin) Fixed problem that LIMIT OFFSET cannot be used with `UNION ALL` (#2613) * (compiler) Support identifiers with schema (#2579) * (compiler) Fix column expansion to work with quoted non-keyword identifiers (#2576) * (codegen/go) Compare define type in codegen (#2263) (#2578) * (engine/sqlite) Fix ast when using compound operator (#2673) * (engine/sqlite) Fix to handle join clauses correctly (#2674) * (codegen) Use correct Go types for bit strings and cid/oid/tid/xid with pgx/v4 (#2668) * (endtoend) Ensure all SQL works against PostgreSQL (#2684) #### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id43 "Link to this heading") * Update Docker installation instructions (#2552) * Missing emit\_pointers\_for\_null\_types configuration option in version 2 (#2682) (#2683) * Fix typo (#2697) * Document sqlc.\* macros (#2698) * (mysql) Document parseTimet=true requirement (#2699) * Add atlas to the list of supported migration frameworks (#2700) * Minor updates to insert howto (#2701) #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id44 "Link to this heading") * (endtoend/testdata) Added two sqlite `CAST` tests and rearranged postgres tests for same (#2551) * (docs) Add a reference to type overriding in datatypes.md (#2557) * (engine/sqlite) Support COLLATE for sqlite WHERE clause (#2554) * (mysql) Add parser support for IS \[NOT\] NULL (#2651) * (engine/dolphin) Support CALL statement (#2614) * (codegen) Allow plugins to access environment variables (#2669) * (config) Add JSON schema files for configs (#2703) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id45 "Link to this heading") * Ignore Vim swap files (#2616) * Fix typo (#2696) #### Refactor[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id46 "Link to this heading") * (astutils) Remove redundant nil check in `Walk` (#2660) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id47 "Link to this heading") * (deps) Bump wasmtime from v8.0.0 to v11.0.0 (#2553) * (deps) Bump golang from 1.20.6 to 1.20.7 (#2563) * (deps) Bump chardet from 5.1.0 to 5.2.0 in /docs (#2562) * (deps) Bump github.com/pganalyze/pg\_query\_go/v4 (#2583) * (deps) Bump golang from 1.20.7 to 1.21.0 (#2596) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.2 to 5.4.3 (#2582) * (deps) Bump pygments from 2.15.1 to 2.16.1 in /docs (#2584) * (deps) Bump sphinxcontrib-applehelp from 1.0.4 to 1.0.7 in /docs (#2620) * (deps) Bump sphinxcontrib-qthelp from 1.0.3 to 1.0.6 in /docs (#2622) * (deps) Bump github.com/google/cel-go from 0.17.1 to 0.17.6 (#2650) * (deps) Bump sphinxcontrib-serializinghtml in /docs (#2641) * Upgrade from Go 1.20 to Go 1.21 (#2665) * (deps) Bump sphinxcontrib-devhelp from 1.0.2 to 1.0.5 in /docs (#2621) * (deps) Bump github.com/bytecodealliance/wasmtime-go from v11.0.0 to v12.0.0 (#2666) * (deps) Bump sphinx-rtd-theme from 1.2.2 to 1.3.0 in /docs (#2670) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.1 to 2.0.4 in /docs (#2671) * (deps) Bump github.com/google/cel-go from 0.17.6 to 0.18.0 (#2691) * (deps) Bump actions/checkout from 3 to 4 (#2694) * (deps) Bump pytz from 2023.3 to 2023.3.post1 in /docs (#2695) * (devenv) Bump go from 1.20.7 to 1.21.0 (#2702) [1.20.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.20.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#v1-20-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-31 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id49 "Link to this heading") #### `kyleconroy/sqlc` is now `sqlc-dev/sqlc`[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#kyleconroy-sqlc-is-now-sqlc-dev-sqlc "Link to this heading") We’ve completed our migration to the [sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc) repository. All existing links and installation instructions will continue to work. If you’re using the `go` tool to install `sqlc`, you’ll need to use the new import path to get v1.20.0 (and all future versions). \# INCORRECT: old import path go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.20.0 \# CORRECT: new import path go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.20.0 We designed the upgrade process to be as smooth as possible. If you run into any issues, please [file a bug report](https://github.com/sqlc-dev/sqlc/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=BUG_REPORT.yml) via GitHub. #### Use `EXPLAIN ...` output in lint rules[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#use-explain-output-in-lint-rules "Link to this heading") `sqlc vet` can now run `EXPLAIN` on your queries and include the results for use in your lint rules. For example, this rule checks that `SELECT` queries use an index. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- has-index rules: \- name: has-index rule: \> query.sql.startsWith("SELECT") && !(postgresql.explain.plan.plans.all(p, has(p.index\_name) || p.plans.all(p, has(p.index\_name)))) The expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.27.0/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. #### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; #### Bulk insert for MySQL[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#bulk-insert-for-mysql "Link to this heading") _Developed by [@Jille](https://github.com/Jille) _ MySQL now supports the `:copyfrom` query annotation. The generated code uses the [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) command to insert data quickly and efficiently. Use caution with this feature. Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use `SHOW WARNINGS` to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } `LOAD DATA` support must be enabled in the MySQL server. #### CAST support for MySQL[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#cast-support-for-mysql "Link to this heading") _Developed by [@ryanpbrewster](https://github.com/ryanpbrewster) and [@RadhiFadlillah](https://github.com/RadhiFadlillah) _ `sqlc` now understands `CAST` calls in MySQL queries, offering greater flexibility when generating code for complex queries. CREATE TABLE foo (bar BOOLEAN NOT NULL); \-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo; package querytest import ( "context" ) const selectColumnCast \= \`-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo \` func (q \*Queries) SelectColumnCast(ctx context.Context) (\[\]int64, error) { ... } #### SQLite improvements[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sqlite-improvements "Link to this heading") A slew of fixes landed for our SQLite implementation, bringing it closer to parity with MySQL and PostgreSQL. We want to thank [@orisano](https://github.com/orisano) for their continued dedication to improving `sqlc`’s SQLite support. ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id50 "Link to this heading") #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id51 "Link to this heading") * (debug) Add debug flag and docs for dumping vet rule variables (#2521) * (mysql) :copyfrom support via LOAD DATA INFILE (#2545) * (mysql) Implement cast function parser (#2473) * (postgresql) Add support for PostgreSQL multi-dimensional arrays (#2338) * (sql/catalog) Support ALTER TABLE IF EXISTS (#2542) * (sqlite) Virtual tables and fts5 supported (#2531) * (vet) Add default query parameters for explain queries (#2543) * (vet) Add output from `EXPLAIN ...` for queries to the CEL program environment (#2489) * (vet) Introduce a query annotation to opt out of sqlc vet rules (#2474) * Parse comment lines starting with `@symbol` as boolean flags associated with a query (#2464) #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id52 "Link to this heading") * (codegen/golang) Fix sqlc.embed to work with pq.Array (#2544) * (compiler) Correctly validate alias in order/group by clauses for joins (#2537) * (engine/sqlite) Added function to convert cast node (#2470) * (engine/sqlite) Fix join\_operator rule (#2434) * (engine/sqlite) Fix table\_alias rules (#2465) * (engine/sqlite) Fixed IN operator precedence (#2428) * (engine/sqlite) Fixed to be able to find relation from WITH clause (#2444) * (engine/sqlite) Lowercase ast.ResTarget.Name (#2433) * (engine/sqlite) Put logging statement behind debug flag (#2488) * (engine/sqlite) Support for repeated table\_option (#2482) * (mysql) Generate unsigned param (#2522) * (sql/catalog) Support pg\_dump output (#2508) * (sqlite) Code generation for sqlc.slice (#2431) * (vet) Clean up unnecessary `prepareable()` func and a var name (#2509) * (vet) Query.cmd was always set to “:” (#2525) * (vet) Report an error when a query is unpreparable, close prepared statement connection (#2486) * (vet) Split vet messages out of codegen.proto (#2511) #### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id53 "Link to this heading") * Add a description to the document for cases when a query result has no rows (#2462) * Update copyright and author (#2490) * Add example sqlc.yaml for migration parsing (#2479) * Small updates (#2506) * Point GitHub links to new repository location (#2534) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id54 "Link to this heading") * Rename kyleconroy/sqlc to sqlc-dev/sqlc (#2523) * (proto) Reformat protos using `buf format -w` (#2536) * Update FEATURE\_REQUEST.yml to include SQLite engine option * Finish migration to sqlc-dev/sqlc (#2548) * (compiler) Remove some duplicate code (#2546) #### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id55 "Link to this heading") * Add profiles to docker compose (#2503) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id56 "Link to this heading") * Run all supported versions of MySQL / PostgreSQL (#2463) * (deps) Bump pygments from 2.7.4 to 2.15.0 in /docs (#2485) * (deps) Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2483) * (deps) Bump github.com/google/cel-go from 0.16.0 to 0.17.1 (#2484) * (docs) Check Python dependencies via dependabot (#2497) * (deps) Bump idna from 2.10 to 3.4 in /docs (#2499) * (deps) Bump packaging from 20.9 to 23.1 in /docs (#2498) * (deps) Bump pygments from 2.15.0 to 2.15.1 in /docs (#2500) * (deps) Bump certifi from 2022.12.7 to 2023.7.22 in /docs (#2504) * (deps) Bump sphinx from 4.4.0 to 6.1.0 in /docs (#2505) * Add psql and mysqlsh to devenv (#2507) * (deps) Bump urllib3 from 1.26.5 to 2.0.4 in /docs (#2516) * (deps) Bump chardet from 4.0.0 to 5.1.0 in /docs (#2517) * (deps) Bump snowballstemmer from 2.1.0 to 2.2.0 in /docs (#2519) * (deps) Bump pytz from 2021.1 to 2023.3 in /docs (#2520) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.0 to 2.0.1 in /docs (#2518) * (deps) Bump pyparsing from 2.4.7 to 3.1.0 in /docs (#2530) * (deps) Bump alabaster from 0.7.12 to 0.7.13 in /docs (#2526) * (docs) Ignore updates for sphinx (#2532) * (deps) Bump babel from 2.9.1 to 2.12.1 in /docs (#2527) * (deps) Bump sphinxcontrib-applehelp from 1.0.2 to 1.0.4 in /docs (#2533) * (deps) Bump google.golang.org/grpc from 1.56.2 to 1.57.0 (#2535) * (deps) Bump pyparsing from 3.1.0 to 3.1.1 in /docs (#2547) [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id57 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id58 "Link to this heading") * Fix to traverse Sel in ast.In (#2414) * (compiler) Validate UNION … ORDER BY (#2446) * (golang) Prevent duplicate enum output (#2447) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id59 "Link to this heading") * Replace codegen, test and docs references to github.com/tabbed repos (#2418) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id60 "Link to this heading") * (deps) Bump google.golang.org/grpc from 1.56.1 to 1.56.2 (#2415) * (deps) Bump golang from 1.20.5 to 1.20.6 (#2437) * Pin Go to 1.20.6 (#2441) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.1 to 5.4.2 (#2436) [1.19.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id61 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-06 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id62 "Link to this heading") #### sqlc vet[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sqlc-vet "Link to this heading") [`sqlc vet`](https://docs.sqlc.dev/en/v1.27.0/howto/vet.html) runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.27.0/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, an error is reported using the given message. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ##### Database connectivity[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#database-connectivity "Link to this heading") `vet` also marks the first time that `sqlc` can connect to a live, running database server. We’ll expand this functionality over time, but for now it powers the `sqlc/db-prepare` built-in rule. When a [database](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#config.html#database) is configured, the `sqlc/db-preapre` rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Please note that `sqlc` does not manage or migrate your database. Use your migration tool of choice to create the necessary database tables and objects before running `sqlc vet`. #### Omit unused structs[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#omit-unused-structs "Link to this heading") Added a new configuration parameter `omit_unused_structs` which, when set to true, filters out table and enum structs that aren’t used in queries for a given package. #### Suggested CI/CD setup[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#suggested-ci-cd-setup "Link to this heading") With the addition of `sqlc diff` and `sqlc vet`, we encourage users to run sqlc in your CI/CD pipelines. See our [suggested CI/CD setup](https://docs.sqlc.dev/en/v1.27.0/howto/ci-cd.html) for more information. #### Simplified plugin development[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#simplified-plugin-development "Link to this heading") The [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) and [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) plugins have been updated use the upcoming [WASI](https://wasi.dev/) support in [Go 1.21](https://tip.golang.org/doc/go1.21#wasip1) . Building these plugins no longer requires [TinyGo](https://tinygo.org/) . ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id63 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id64 "Link to this heading") * Pointers overrides skip imports in generated query files (#2240) * CASE-ELSE clause is not properly parsed when a value is constant (#2238) * Fix toSnakeCase to handle input in CamelCase format (#2245) * Add location info to sqlite ast (#2298) * Add override tags to result struct (#1867) (#1887) * Override types of aliased columns and named parameters (#1884) * Resolve duplicate fields generated when inheriting multiple tables (#2089) * Check column references in ORDER BY (#1411) (#1915) * MySQL slice shadowing database/sql import (#2332) * Don’t defer rows.Close() if pgx.BatchResults.Query() failed (#2362) * Fix type overrides not working with sqlc.slice (#2351) * Type overrides on columns for parameters inside an IN clause (#2352) * Broken interaction between query\_parameter\_limit and pq.Array() (#2383) * (codegen/golang) Bring :execlastid in line with the rest (#2378) #### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id65 "Link to this heading") * Update changelog.md with some minor edits (#2235) * Add F# community plugin (#2295) * Add a ReadTheDocs config file (#2327) * Update query\_parameter\_limit documentation (#2374) * Add launch announcement banner #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id66 "Link to this heading") * PostgreSQL capture correct line and column numbers for parse error (#2289) * Add supporting COMMENT ON VIEW (#2249) * To allow spaces between function name and arguments of functions to be rewritten (#2250) * Add support for pgx/v5 emit\_pointers\_for\_null\_types flag (#2269) * (mysql) Support unsigned integers (#1746) * Allow use of table and column aliases for table functions returning unknown types (#2156) * Support “LIMIT ?” in UPDATE and DELETE for MySQL (#2365) * (internal/codegen/golang) Omit unused structs from output (#2369) * Improve default names for BETWEEN ? AND ? to have prefixes from\_ and to\_ (#2366) * (cmd/sqlc) Add the vet subcommand (#2344) * (sqlite) Add support for UPDATE/DELETE with a LIMIT clause (#2384) * Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) (#2373) * (cmd/vet) Prepare queries against a database (#2387) * (cmd/vet) Prepare queries for MySQL (#2388) * (cmd/vet) Prepare SQLite queries (#2389) * (cmd/vet) Simplify environment variable substiution (#2393) * (cmd/vet) Add built-in db-prepare rule * Add compiler support for NOTIFY and LISTEN (PostgreSQL) (#2363) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id67 "Link to this heading") * A few small staticcheck fixes (#2361) * Remove a bunch of dead code (#2360) * (scripts/regenerate) Should also update stderr.txt (#2379) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id68 "Link to this heading") * (deps) Bump requests from 2.25.1 to 2.31.0 in /docs (#2283) * (deps) Bump golang from 1.20.3 to 1.20.4 (#2256) * (deps) Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#2265) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 (#2293) * (deps) Bump golang.org/x/sync from 0.1.0 to 0.2.0 (#2266) * (deps) Bump golang from 1.20.4 to 1.20.5 (#2301) * Configure dependencies via devenv.sh (#2319) * Configure dependencies via devenv.sh (#2326) * (deps) Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#2328) * (deps) Bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#2333) * (deps) Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 (#2370) * (deps) Bump actions/checkout from 2 to 3 (#2357) * Run govulncheck on all builds (#2372) * (deps) Bump google.golang.org/grpc from 1.56.0 to 1.56.1 (#2358) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#cmd-sqlc "Link to this heading") * Show helpful output on missing subcommand (#2345) #### Codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#codegen "Link to this heading") * Use catalog’s default schema (#2310) * (go) Add tests for tables with dashes (#2312) * (go) Strip invalid characters from table and column names (#2314) * (go) Support JSON tags for nullable enum structs (#2121) #### Internal/config[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-config "Link to this heading") * Support golang overrides for slices (#2339) #### Kotlin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#kotlin "Link to this heading") * Use latest version of sqlc-gen-kotlin (#2356) #### Postgres[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#postgres "Link to this heading") * Column merging for table inheritence (#2315) #### Protos[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#protos "Link to this heading") * Add missing field name (#2354) #### Python[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#python "Link to this heading") * Use latest version of sqlc-gen-python (#2355) #### Remote[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#remote "Link to this heading") * Use user-id/password auth (#2262) #### Sqlite[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sqlite "Link to this heading") * Fixed sqlite column type override (#1986) [1.18.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.18.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id69 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-04-27 ### Release notes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id70 "Link to this heading") #### Remote code generation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#remote-code-generation "Link to this heading") _Developed by [@andrewmbenton](https://github.com/andrewmbenton) _ At its core, sqlc is powered by SQL engines, which include parsers, formatters, analyzers and more. While our goal is to support each engine on each operating system, it’s not always possible. For example, the PostgreSQL engine does not work on Windows. To bridge that gap, we’re announcing remote code generation, currently in private alpha. To join the private alpha, [sign up for the waitlist](https://docs.google.com/forms/d/e/1FAIpQLScDWrGtTgZWKt3mdlF5R2XCX6tL1pMkB4yuZx5yq684tTNN1Q/viewform?usp=sf_link) . Remote code generation works like local code generation, except the heavy lifting is performed in a consistent cloud environment. WASM-based plugins are supported in the remote environment, but process-based plugins are not. To configure remote generation, add a `cloud` block in `sqlc.json`. { "version": "2", "cloud": { "organization": "", "project": "", }, ... } You’ll also need to set the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\= When the `cloud` configuration block exists, `sqlc generate` will default to remote code generation. If you’d like to generate code locally without removing the `cloud` block from your config, pass the `--no-remote` option. sqlc generate \--no-remote Remote generation is off by default and requires an opt-in to use. #### sqlc.embed[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sqlc-embed "Link to this heading") _Developed by [@nickjackson](https://github.com/nickjackson) _ Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ) CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ) We want to select the student record and the highest score they got on a test. Here’s how we’d usually do that: \-- name: HighScore :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT students.\*, high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; When using Go, sqlc will produce a struct like this: type HighScoreRow struct { ID int64 Name sql.NullString Age sql.NullInt32 HighScore int32 } With embedding, the struct will contain a model for the table instead of a flattened list of columns. \-- name: HighScoreEmbed :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT sqlc.embed(students), high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; type HighScoreRow struct { Student Student HighScore int32 } #### sqlc.slice[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sqlc-slice "Link to this heading") _Developed by Paul Cameron and Jille Timmermans_ The MySQL Go driver does not support passing slices to the IN operator. The `sqlc.slice` function generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) func (q \*Queries) SelectStudents(ctx context.Context, ages \[\]int32) (\[\]Student, error) { This feature is only supported in MySQL and cannot be used with prepared queries. #### Batch operation improvements[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#batch-operation-improvements "Link to this heading") When using batches with pgx, the error returned when a batch is closed is exported by the generated package. This change allows for cleaner error handling using `errors.Is`. errors.Is(err, generated\_package.ErrBatchAlreadyClosed) Previously, you would have had to check match on the error message itself. err.Error() \== "batch already closed" The generated code for batch operations always lived in `batch.go`. This file name can now be configured via the `output_batch_file_name` configuration option. #### Configurable query parameter limits for Go[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#configurable-query-parameter-limits-for-go "Link to this heading") By default, sqlc will limit Go functions to a single parameter. If a query includes more than one parameter, the generated method will use an argument struct instead of positional arguments. This behavior can now be changed via the `query_parameter_limit` configuration option. If set to `0`, every genreated method will use a argument struct. ### Changes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id71 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id72 "Link to this heading") * Prevent variable redeclaration in single param conflict for pgx (#2058) * Retrieve Larg/Rarg join query after inner join (#2051) * Rename argument when conflicted to imported package (#2048) * Pgx closed batch return pointer if need #1959 (#1960) * Correct singularization of “waves” (#2194) * Honor Package level renames in v2 yaml config (#2001) * (mysql) Prevent UPDATE … JOIN panic #1590 (#2154) * Mysql delete join panic (#2197) * Missing import with pointer overrides, solves #2168 #2125 (#2217) #### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id73 "Link to this heading") * (config.md) Add `sqlite` as engine option (#2164) * Add first pass at pgx documentation (#2174) * Add missed configuration option (#2188) * `specifies parameter ":one" without containing a RETURNING clause` (#2173) #### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id74 "Link to this heading") * Add `sqlc.embed` to allow model re-use (#1615) * (Go) Add query\_parameter\_limit conf to codegen (#1558) * Add remote execution for codegen (#2214) #### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id75 "Link to this heading") * Skip tests if required plugins are missing (#2104) * Add tests for reanme fix in v2 (#2196) * Regenerate batch output for filename tests * Remove remote test (#2232) * Regenerate test output #### Bin/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#bin-sqlc "Link to this heading") * Add SQLCTMPDIR environment variable (#2189) #### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id76 "Link to this heading") * (deps) Bump github.com/antlr/antlr4/runtime/Go/antlr (#2109) * (deps) Bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 (#2119) * (deps) Bump golang from 1.20.1 to 1.20.2 (#2135) * (deps) Bump google.golang.org/protobuf from 1.28.1 to 1.29.0 (#2137) * (deps) Bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#2143) * (deps) Bump golang from 1.20.2 to 1.20.3 (#2192) * (deps) Bump actions/setup-go from 3 to 4 (#2150) * (deps) Bump google.golang.org/protobuf from 1.29.1 to 1.30.0 (#2151) * (deps) Bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#2193) * (deps) Bump github.com/lib/pq from 1.10.7 to 1.10.8 (#2211) * (deps) Bump github.com/lib/pq from 1.10.8 to 1.10.9 (#2229) * (deps) Bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 (#2228) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id77 "Link to this heading") * Remove –experimental flag (#2170) * Add option to disable process-based plugins (#2180) * Bump version to v1.18.0 #### Codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id78 "Link to this heading") * Correctly generate CopyFrom columns for single-column copyfroms (#2185) #### Config[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#config "Link to this heading") * Add top-level cloud configuration (#2204) #### Engine/postgres[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#engine-postgres "Link to this heading") * Upgrade to pg\_query\_go/v4 (#2114) #### Ext/wasm[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#ext-wasm "Link to this heading") * Check exit code on returned error (#2223) #### Parser[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#parser "Link to this heading") * Generate correct types for `SELECT NOT EXISTS` (#1972) #### Sqlite[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id79 "Link to this heading") * Add support for CREATE TABLE … STRICT (#2175) #### Wasm[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#wasm "Link to this heading") * Upgrade to wasmtime v8.0.0 (#2222) [1.17.2](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.2) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id80 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id81 "Link to this heading") * Fix build on Windows (#2102) [1.17.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.1) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id82 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id83 "Link to this heading") * Prefer to use \[\]T over pgype.Array\[T\] (#2090) * Revert changes to Dockerfile (#2091) * Do not throw error when IF NOT EXISTS is used on ADD COLUMN (#2092) ### MySQL[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#mysql "Link to this heading") * Add `float` support to MySQL (#2097) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id84 "Link to this heading") * (deps) Bump golang from 1.20.0 to 1.20.1 (#2082) [1.17.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id85 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id86 "Link to this heading") * Initialize generated code outside function (#1850) * (engine/mysql) Take into account column’s charset to distinguish text/blob, (var)char/(var)binary (#776) (#1895) * The enum Value method returns correct type (#1996) * Documentation for Inserting Rows (#2034) * Add import statements even if only pointer types exist (#2046) * Search from Rexpr if not found from Lexpr (#2056) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id87 "Link to this heading") * Change ENTRYPOINT to CMD (#1943) * Update samples for HOW-TO GUIDES (#1953) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id88 "Link to this heading") * Add the diff command (#1963) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id89 "Link to this heading") * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.15 to 1.14.16 (#1913) * (deps) Bump github.com/spf13/cobra from 1.6.0 to 1.6.1 (#1909) * Fix devcontainer (#1942) * Run sqlc-pg-gen via GitHub Actions (#1944) * Move large arrays out of functions (#1947) * Fix conflicts from pointer configuration (#1950) * (deps) Bump github.com/go-sql-driver/mysql from 1.6.0 to 1.7.0 (#1988) * (deps) Bump github.com/jackc/pgtype from 1.12.0 to 1.13.0 (#1978) * (deps) Bump golang from 1.19.3 to 1.19.4 (#1992) * (deps) Bump certifi from 2020.12.5 to 2022.12.7 in /docs (#1993) * (deps) Bump golang from 1.19.4 to 1.19.5 (#2016) * (deps) Bump golang from 1.19.5 to 1.20.0 (#2045) * (deps) Bump github.com/jackc/pgtype from 1.13.0 to 1.14.0 (#2062) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.0 (#2063) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#cmd "Link to this heading") * Generate packages in parallel (#2026) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id90 "Link to this heading") * Bump version to v1.17.0 ### Codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id91 "Link to this heading") * Remove built-in Kotlin support (#1935) * Remove built-in Python support (#1936) ### Internal/codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-codegen "Link to this heading") * Cache pattern matching compilations (#2028) ### Mysql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id92 "Link to this heading") * Add datatype tests (#1948) * Fix blob tests (#1949) ### Plugins[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#plugins "Link to this heading") * Upgrade to wasmtime 3.0.1 (#2009) ### Sqlite[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id93 "Link to this heading") * Supported between expr (#1958) (#1967) ### Tools[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#tools "Link to this heading") * Regenerate scripts skips dirs that contains diff exec command (#1987) ### Wasm[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id94 "Link to this heading") * Upgrade to wasmtime 5.0.0 (#2065) [1.16.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.16.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id95 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-11-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id96 "Link to this heading") * (validate) Sqlc.arg & sqlc.narg are not “missing” (#1814) * Emit correct comment for nullable enums (#1819) * 🐛 Correctly switch `coalesce()` result `.NotNull` value (#1664) * Prevent batch infinite loop with arg length (#1794) * Support version 2 in error message (#1839) * Handle empty column list in postgresql (#1843) * Batch imports filter queries, update cmds having ret type (#1842) * Named params contribute to batch parameter count (#1841) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id97 "Link to this heading") * Add a getting started guide for SQLite (#1798) * Various readability improvements (#1854) * Add documentation for codegen plugins (#1904) * Update migration guides with links (#1933) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id98 "Link to this heading") * Add HAVING support to MySQL (#1806) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id99 "Link to this heading") * Upgrade wasmtime version (#1827) * Bump wasmtime version to v1.0.0 (#1869) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id100 "Link to this heading") * (deps) Bump github.com/jackc/pgconn from 1.12.1 to 1.13.0 (#1785) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.13 to 1.14.15 (#1799) * (deps) Bump github.com/jackc/pgx/v4 from 4.16.1 to 4.17.0 (#1786) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.0 to 4.17.1 (#1825) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1826) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.1 to 4.17.2 (#1831) * (deps) Bump golang from 1.19.0 to 1.19.1 (#1834) * (deps) Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#1838) * (deps) Bump github.com/lib/pq from 1.10.6 to 1.10.7 (#1835) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1857) * (deps) Bump github.com/spf13/cobra from 1.5.0 to 1.6.0 (#1893) * (deps) Bump golang from 1.19.1 to 1.19.3 (#1920) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id101 "Link to this heading") * Bump to v1.16.0 ### Codgen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#codgen "Link to this heading") * Include serialized codegen options (#1890) ### Compiler[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#compiler "Link to this heading") * Move Kotlin parameter logic into codegen (#1910) ### Examples[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#examples "Link to this heading") * Port Python examples to WASM plugin (#1903) ### Pg-gen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#pg-gen "Link to this heading") * Make sqlc-pg-gen the complete source of truth for pg\_catalog.go (#1809) * Implement information\_schema shema (#1815) ### Python[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id102 "Link to this heading") * Port all Python tests to sqlc-gen-python (#1907) * Upgrade to sqlc-gen-python v1.0.0 (#1932) [1.15.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.15.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id103 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-08-07 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id104 "Link to this heading") * (mysql) Typo (#1700) * (postgresql) Add quotes for CamelCase columns (#1729) * Cannot parse SQLite upsert statement (#1732) * (sqlite) Regenerate test output for builtins (#1735) * (wasm) Version modules by wasmtime version (#1734) * Missing imports (#1637) * Missing slice import for querier (#1773) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id105 "Link to this heading") * Add process-based plugin docs (#1669) * Add links to downloads.sqlc.dev (#1681) * Update transactions how to example (#1775) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id106 "Link to this heading") * More SQL Syntax Support for SQLite (#1687) * (sqlite) Promote SQLite support to beta (#1699) * Codegen plugins, powered by WASM (#1684) * Set user-agent for plugin downloads (#1707) * Null enums types (#1485) * (sqlite) Support stdlib functions (#1712) * (sqlite) Add support for returning (#1741) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id107 "Link to this heading") * Add tests for quoting columns (#1733) * Remove catalog tests (#1762) ### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id108 "Link to this heading") * Add tests for fixing slice imports (#1736) * Add test cases for returning (#1737) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id109 "Link to this heading") * Upgrade to Go 1.19 (#1780) * Upgrade to go-wasmtime 0.39.0 (#1781) ### Plugins[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id110 "Link to this heading") * (wasm) Change default cache location (#1709) * (wasm) Change the SHA-256 config key (#1710) [1.14.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.14.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id111 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-06-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id112 "Link to this heading") * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) * (compiler) Fix left join nullability with table aliases (#1491) * Regenerate testdata for CREATE TABLE AS (#1516) * (bundler) Only close multipart writer once (#1528) * (endtoend) Regenerate testdata for exex\_lastid * (pgx) Copyfrom imports (#1626) * Validate sqlc function arguments (#1633) * Fixed typo `sql.narg` in doc (#1668) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id113 "Link to this heading") * (golang) Add Enum.Valid and AllEnumValues (#1613) * (sqlite) Start expanding support (#1410) * (pgx) Add support for batch operations (#1437) * (sqlite) Add support for delete statements (#1447) * (codegen) Insert comments in interfaces (#1458) * (sdk) Add the plugin SDK package (#1463) * Upload projects (#1436) * Add sqlc version to generated Kotlin code (#1512) * Add sqlc version to generated Go code (#1513) * Pass sqlc version in codegen request (#1514) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * Run sqlc with docker on windows cmd (#1557) * Add JSON “codegen” output (#1565) * Add sqlc.narg() for nullable named params (#1536) * Process-based codegen plugins (#1578) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id114 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id115 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) * (sql/catalog) Improve Readability (#1595) * Add basic fuzzing for config / overrides (#1500) [1.13.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.13.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id116 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-03-31 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id117 "Link to this heading") * (compiler) Fix left join nullability with table aliases (#1491) * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id118 "Link to this heading") * (cli) Upload projects (#1436) * (codegen) Add sqlc version to generated Go code (#1513) * (codegen) Add sqlc version to generated Kotlin code (#1512) * (codegen) Insert comments in interfaces (#1458) * (codegen) Pass sqlc version in codegen request (#1514) * (pgx) Add support for batch operations (#1437) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * (sdk) Add the plugin SDK package (#1463) * (sqlite) Add support for delete statements (#1447) * (sqlite) Start expanding support (#1410) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id119 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id120 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) ### Config[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id121 "Link to this heading") * Add basic fuzzing for config / overrides (#1500) [1.12.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.12.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id122 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-02-05 ### Bug[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#bug "Link to this heading") * ALTER TABLE SET SCHEMA (#1409) ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id123 "Link to this heading") * Update ANTLR v4 go.mod entry (#1336) * Check delete statements for CTEs (#1329) * Fix validation of GROUP BY on field aliases (#1348) * Fix imports when non-copyfrom queries needed imports that copyfrom queries didn’t (#1386) * Remove extra comment newline (#1395) * Enable strict function checking (#1405) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id124 "Link to this heading") * Bump version to 1.11.0 (#1308) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id125 "Link to this heading") * Inheritance (#1339) * Generate query code using ASTs instead of templates (#1338) * Add support for CREATE TABLE a ( LIKE b ) (#1355) * Add support for sql.NullInt16 (#1376) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id126 "Link to this heading") * Add tests for :exec{result,rows} (#1344) * Delete template-based codegen (#1345) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id127 "Link to this heading") * Bump github.com/jackc/pgx/v4 from 4.14.0 to 4.14.1 (#1316) * Bump golang from 1.17.3 to 1.17.4 (#1331) * Bump golang from 1.17.4 to 1.17.5 (#1337) * Bump github.com/spf13/cobra from 1.2.1 to 1.3.0 (#1343) * Remove devel Docker build * Bump golang from 1.17.5 to 1.17.6 (#1369) * Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 (#1382) * Format all Go code (#1387) [1.11.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.11.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id128 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-11-24 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id129 "Link to this heading") * Update incorrect signatures (#1180) * Correct aggregate func sig (#1182) * Jsonb\_build\_object (#1211) * Case-insensitive identifiers (#1216) * Incorrect handling of meta (#1228) * Detect invalid INSERT expression (#1231) * Respect alias name for coalesce (#1232) * Mark nullable when casting NULL (#1233) * Support nullable fields in joins for MySQL engine (#1249) * Fix between expression handling of table references (#1268) * Support nullable fields in joins on same table (#1270) * Fix missing binds in ORDER BY (#1273) * Set RV for TargetList items on updates (#1252) * Fix MySQL parser for query without trailing semicolon (#1282) * Validate table alias references (#1283) * Add support for MySQL ON DUPLICATE KEY UPDATE (#1286) * Support references to columns in joined tables in UPDATE statements (#1289) * Add validation for GROUP BY clause column references (#1285) * Prevent variable redeclaration in single param conflict (#1298) * Use common params struct field for same named params (#1296) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id130 "Link to this heading") * Replace deprecated go get with go install (#1181) * Fix package name referenced in tutorial (#1202) * Add environment variables (#1264) * Add go.17+ install instructions (#1280) * Warn about golang-migrate file order (#1302) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id131 "Link to this heading") * Instrument compiler via runtime/trace (#1258) * Add MySQL support for BETWEEN arguments (#1265) ### Refactor[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id132 "Link to this heading") * Move from io/ioutil to io and os package (#1164) ### Styling[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#styling "Link to this heading") * Apply gofmt to sample code (#1261) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id133 "Link to this heading") * Bump golang from 1.17.0 to 1.17.1 (#1173) * Bump eskatos/gradle-command-action from 1 to 2 (#1220) * Bump golang from 1.17.1 to 1.17.2 (#1227) * Bump github.com/pganalyze/pg\_query\_go/v2 (#1234) * Bump actions/checkout from 2.3.4 to 2.3.5 (#1238) * Bump babel from 2.9.0 to 2.9.1 in /docs (#1245) * Bump golang from 1.17.2 to 1.17.3 (#1272) * Bump actions/checkout from 2.3.5 to 2.4.0 (#1267) * Bump github.com/lib/pq from 1.10.3 to 1.10.4 (#1278) * Bump github.com/jackc/pgx/v4 from 4.13.0 to 4.14.0 (#1303) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id134 "Link to this heading") * Bump version to v1.11.0 [1.10.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.10.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id135 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-09-07 ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id136 "Link to this heading") * Fix invalid language support table (#1161) * Add a getting started guide for MySQL (#1163) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id137 "Link to this heading") * Bump golang from 1.16.7 to 1.17.0 (#1129) * Bump github.com/lib/pq from 1.10.2 to 1.10.3 (#1160) ### Ci[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id138 "Link to this heading") * Upgrade Go to 1.17 (#1130) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id139 "Link to this heading") * Bump version to v1.10.0 (#1165) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#codegen-golang "Link to this heading") * Consolidate import logic (#1139) * Add pgx support for range types (#1146) * Use pgtype for hstore when using pgx (#1156) ### Codgen/golang[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#codgen-golang "Link to this heading") * Use p\[gq\]type for network address types (#1142) ### Endtoend[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#endtoend "Link to this heading") * Run `go test` in CI (#1134) ### Engine/mysql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#engine-mysql "Link to this heading") * Add support for LIKE (#1162) ### Golang[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#golang "Link to this heading") * Output NullUUID when necessary (#1137) [1.9.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.9.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id140 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-08-13 ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id141 "Link to this heading") * Update documentation (a bit) for v1.9.0 (#1117) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id142 "Link to this heading") * Bump golang from 1.16.6 to 1.16.7 (#1107) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id143 "Link to this heading") * Bump version to v1.9.0 (#1121) ### Compiler[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id144 "Link to this heading") * Add tests for COALESCE behavior (#1112) * Handle subqueries in SELECT statements (#1113) [1.8.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.8.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id145 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-05-03 ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id146 "Link to this heading") * Add language support Matrix (#920) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id147 "Link to this heading") * Add case style config option (#905) ### Python[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id148 "Link to this heading") * Eliminate runtime package and use sqlalchemy (#939) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id149 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.4 to 0.5.5 (#926) * Bump github.com/lib/pq from 1.9.0 to 1.10.0 (#931) * Bump golang from 1.16.0 to 1.16.1 (#935) * Bump golang from 1.16.1 to 1.16.2 (#942) * Bump github.com/jackc/pgx/v4 from 4.10.1 to 4.11.0 (#956) * Bump github.com/go-sql-driver/mysql from 1.5.0 to 1.6.0 (#961) * Bump github.com/pganalyze/pg\_query\_go/v2 (#965) * Bump urllib3 from 1.26.3 to 1.26.4 in /docs (#968) * Bump golang from 1.16.2 to 1.16.3 (#963) * Bump github.com/lib/pq from 1.10.0 to 1.10.1 (#980) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id150 "Link to this heading") * Add the –experimental flag (#929) * Fix sqlc init (#959) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id151 "Link to this heading") * Bump version to v1.7.1-devel (#913) * Bump version to v1.8.0 ### Codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id152 "Link to this heading") * Generate valid enum names for symbols (#972) ### Postgresql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#postgresql "Link to this heading") * Support generated columns * Add test for PRIMARY KEY INCLUDE * Add tests for CREATE TABLE PARTITION OF * CREATE TRIGGER EXECUTE FUNCTION * Add support for renaming types (#971) ### Sql/ast[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sql-ast "Link to this heading") * Resolve return values from functions (#964) ### Workflows[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#workflows "Link to this heading") * Only run tests once (#924) [1.7.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.7.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id153 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-02-28 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id154 "Link to this heading") * Struct tag formatting (#833) ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id155 "Link to this heading") * Include all the existing Markdown files (#877) * Split docs into four sections (#882) * Reorganize and consolidate documentation * Add link to Windows download (#888) * Shorten the README (#889) ### Features[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id156 "Link to this heading") * Adding support for pgx/v4 * Adding support for pgx/v4 ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#readme "Link to this heading") * Add Go Report Card badge (#891) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id157 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.3 to 0.5.4 (#813) * Bump github.com/lib/pq from 1.8.0 to 1.9.0 (#820) * Bump golang from 1.15.5 to 1.15.6 (#822) * Bump github.com/jackc/pgx/v4 from 4.9.2 to 4.10.0 (#823) * Bump github.com/jackc/pgx/v4 from 4.10.0 to 4.10.1 (#839) * Bump golang from 1.15.6 to 1.15.7 (#855) * Bump golang from 1.15.7 to 1.15.8 (#881) * Bump github.com/spf13/cobra from 1.1.1 to 1.1.2 (#892) * Bump golang from 1.15.8 to 1.16.0 (#897) * Bump github.com/lfittl/pg\_query\_go from 1.0.1 to 1.0.2 (#901) * Bump github.com/spf13/cobra from 1.1.2 to 1.1.3 (#893) ### Catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#catalog "Link to this heading") * Improve alter column type (#818) ### Ci[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id158 "Link to this heading") * Uprade to Go 1.15 (#887) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id159 "Link to this heading") * Allow config file location to be specified (#863) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id160 "Link to this heading") * Bump to version v1.6.1-devel (#807) * Bump version to v1.7.0 (#912) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id161 "Link to this heading") * Make sure to import net package (#858) ### Compiler[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id162 "Link to this heading") * Support UNION query ### Dolphin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#dolphin "Link to this heading") * Generate bools for tinyint(1) * Support joins in update statements (#883) * Add support for union query ### Endtoend[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id163 "Link to this heading") * Add tests for INTERSECT and EXCEPT ### Go.mod[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#go-mod "Link to this heading") * Update to go 1.15 and run ‘go mod tidy’ (#808) ### Mysql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id164 "Link to this heading") * Compile tinyint(1) to bool (#873) ### Sql/ast[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id165 "Link to this heading") * Add enum values for SetOperation [1.6.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.6.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id166 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-11-23 ### Dolphin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id167 "Link to this heading") * Implement Rename (#651) * Skip processing view drops (#653) ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id168 "Link to this heading") * Update language / database support (#698) ### Astutils[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#astutils "Link to this heading") * Fix Params rewrite call (#674) ### Build[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id169 "Link to this heading") * Bump golang from 1.14 to 1.15.3 (#765) * Bump docker/build-push-action from v1 to v2.1.0 (#764) * Bump github.com/google/go-cmp from 0.4.0 to 0.5.2 (#766) * Bump github.com/spf13/cobra from 1.0.0 to 1.1.1 (#767) * Bump github.com/jackc/pgx/v4 from 4.6.0 to 4.9.2 (#768) * Bump github.com/lfittl/pg\_query\_go from 1.0.0 to 1.0.1 (#773) * Bump github.com/google/go-cmp from 0.5.2 to 0.5.3 (#783) * Bump golang from 1.15.3 to 1.15.5 (#782) * Bump github.com/lib/pq from 1.4.0 to 1.8.0 (#769) ### Catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id170 "Link to this heading") * Improve variadic argument support (#804) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id171 "Link to this heading") * Bump to version v1.6.0 (#806) ### Codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id172 "Link to this heading") * Fix errant database/sql imports (#789) ### Compiler[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id173 "Link to this heading") * Use engine-specific reserved keywords (#677) ### Dolphi[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#dolphi "Link to this heading") * Add list of builtin functions (#795) ### Dolphin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id174 "Link to this heading") * Update to the latest MySQL parser (#665) * Add ENUM() support (#676) * Add test for table aliasing (#684) * Add MySQL ddl\_create\_table test (#685) * Implete TRUNCATE table (#697) * Represent tinyint as int32 (#797) * Add support for coalesce (#802) * Add function signatures (#796) ### Endtoend[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id175 "Link to this heading") * Add MySQL json test (#692) * Add MySQL update set multiple test (#696) ### Examples[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id176 "Link to this heading") * Use generated enum constants in db\_test (#678) * Port ondeck to MySQL (#680) * Add MySQL authors example (#682) ### Internal/cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-cmd "Link to this heading") * Print correct config file on parse failure (#749) ### Kotlin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id177 "Link to this heading") * Remove runtime dependency (#774) ### Metadata[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#metadata "Link to this heading") * Support multiple comment prefixes (#683) ### Postgresql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id178 "Link to this heading") * Support string concat operator (#701) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sql-catalog "Link to this heading") * Add support for variadic functions (#798) [1.5.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.5.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id179 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-08-05 ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id180 "Link to this heading") * Build sqlc using Go 1.14 (#549) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id181 "Link to this heading") * Add debugging support (#573) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id182 "Link to this heading") * Bump version to v1.4.1-devel (#548) * Bump version to v1.5.0 ### Compiler[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id183 "Link to this heading") * Support calling functions with defaults (#635) * Skip func args without a paramRef (#636) * Return a single column from coalesce (#639) ### Config[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id184 "Link to this heading") * Add emit\_empty\_slices to version one (#552) ### Contrib[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#contrib "Link to this heading") * Add generated code for contrib ### Dinosql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#dinosql "Link to this heading") * Remove deprecated package (#554) ### Dolphin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id185 "Link to this heading") * Add support for column aliasing (#566) * Implement star expansion for subqueries (#619) * Implement exapansion with reserved words (#620) * Implement parameter refs (#621) * Implement limit and offest (#622) * Implement inserts (#623) * Implement delete (#624) * Implement simple update statements (#625) * Implement INSERT … SELECT (#626) * Use test driver instead of TiDB driver (#629) * Implement named parameters via sqlc.arg() (#632) ### Endtoend[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id186 "Link to this heading") * Add MySQL test for SELECT \* JOIN (#565) * Add MySQL test for inflection (#567) ### Engine[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#engine "Link to this heading") * Create engine package (#556) ### Equinox[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#equinox "Link to this heading") * Use the new equinox-io/setup action (#586) ### Examples[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id187 "Link to this heading") * Run tests for MySQL booktest (#627) ### Golang[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id188 "Link to this heading") * Add support for the money type (#561) * Generate correct types for int2 and int8 (#579) ### Internal[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal "Link to this heading") * Rm catalog, pg, postgres packages (#555) ### Mod[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#mod "Link to this heading") * Downgrade TiDB package to fix build (#603) ### Mysql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id189 "Link to this heading") * Upgrade to the latest vitess commit (#562) * Support to infer type of a duplicated arg (#615) * Allow some builtin functions to be nullable (#616) ### Postgresql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id190 "Link to this heading") * Generate all functions in pg\_catalog (#550) * Remove pg\_catalog schema from tests (#638) * Move contrib code to a package ### Sql/catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id191 "Link to this heading") * Fix comparison of pg\_catalog types (#637) ### Tools[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id192 "Link to this heading") * Generate functions for all of contrib ### Workflow[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#workflow "Link to this heading") * Migrate to equinox-io/setup-release-tool (#614) [1.4.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.4.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id193 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-06-17 ### Dockerfile[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#dockerfile "Link to this heading") * Add version build argument (#487) ### MySQL[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id194 "Link to this heading") * Prevent Panic when WHERE clause contains parenthesis. (#531) ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id195 "Link to this heading") * Document emit\_exact\_table\_names (#486) ### All[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#all "Link to this heading") * Remove the exp build tag (#507) ### Catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id196 "Link to this heading") * Support functions with table parameters (#541) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id197 "Link to this heading") * Bump to version 1.3.1-devel (#485) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id198 "Link to this heading") * Bump version to v1.4.0 (#547) ### Codegen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id199 "Link to this heading") * Add the new codegen packages (#513) * Add the :execresult query annotation (#542) ### Compiler[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id200 "Link to this heading") * Validate function calls (#505) * Port bottom of parseQuery (#510) * Don’t mutate table name (#517) * Enable experimental parser by default (#518) * Apply rename rules to enum constants (#523) * Temp fix for typecast function parameters (#530) ### Endtoend[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id201 "Link to this heading") * Standardize JSON formatting (#490) * Add per-test configuration files (#521) * Read expected stderr failures from disk (#527) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-dinosql "Link to this heading") * Check parameter style before ref (#488) * Remove unneeded column suffix (#492) * Support named function arguments (#494) ### Internal/postgresql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-postgresql "Link to this heading") * Fix NamedArgExpr rewrite (#491) ### Multierr[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#multierr "Link to this heading") * Move dinosql.ParserErr to a new package (#496) ### Named[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#named "Link to this heading") * Port parameter style validation to SQL (#504) ### Parser[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id202 "Link to this heading") * Support columns from subselect statements (#489) ### Rewrite[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#rewrite "Link to this heading") * Move parameter rewrite to package (#499) ### Sqlite[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id203 "Link to this heading") * Use convert functions instead of the listener (#519) ### Sqlpath[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sqlpath "Link to this heading") * Move ReadSQLFiles into a separate package (#495) ### Validation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#validation "Link to this heading") * Move query validation to separate package (#498) [1.3.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.3.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id204 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-05-12 ### Makefile[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#makefile "Link to this heading") * Update target (#449) ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id205 "Link to this heading") * Add Myles as a sponsor (#469) ### Testing[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id206 "Link to this heading") * Make sure all Go examples build (#480) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id207 "Link to this heading") * Bump version to v1.3.0 (#484) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id208 "Link to this heading") * Bump version to v1.2.1-devel (#442) ### Dinosql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id209 "Link to this heading") * Inline addFile (#446) * Add PostgreSQL support for TRUNCATE (#448) ### Gen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#gen "Link to this heading") * Emit json.RawMessage for JSON columns (#461) ### Go.mod[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id210 "Link to this heading") * Use latest lib/pq (#471) ### Parser[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id211 "Link to this heading") * Use same function to load SQL files (#483) ### Postgresql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id212 "Link to this heading") * Fix panic walking CreateTableAsStmt (#475) [1.2.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.2.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id213 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-04-07 ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id214 "Link to this heading") * Publish to Docker Hub (#422) ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id215 "Link to this heading") * Docker installation docs (#424) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id216 "Link to this heading") * Bump version to v1.1.1-devel (#407) * Bump version to v1.2.0 (#441) ### Gen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id217 "Link to this heading") * Add special case for “campus” (#435) * Properly quote reserved keywords on expansion (#436) ### Migrations[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#migrations "Link to this heading") * Move migration parsing to new package (#427) ### Parser[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id218 "Link to this heading") * Generate correct types for SELECT EXISTS (#411) [1.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.1.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id219 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-03-17 ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id220 "Link to this heading") * Add installation instructions (#350) * Add section on running tests (#357) * Fix typo (#371) ### Ast[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#ast "Link to this heading") * Add AST for ALTER TABLE ADD / DROP COLUMN (#376) * Add support for CREATE TYPE as ENUM (#388) * Add support for CREATE / DROP SCHEMA (#389) ### Astutils[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id221 "Link to this heading") * Apply changes to the ValuesList slice (#372) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id222 "Link to this heading") * Return v1.0.0 (#348) * Return next bug fix version (#349) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id223 "Link to this heading") * Bump version to v1.1.0 (#406) ### Compiler[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id224 "Link to this heading") * Wire up the experimental parsers ### Config[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id225 "Link to this heading") * Remove “emit\_single\_file” option (#367) ### Dolphin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id226 "Link to this heading") * Add experimental parser for MySQL ### Gen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id227 "Link to this heading") * Add option to emit single file for Go (#366) * Add support for the ltree extension (#385) ### Go.mod[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id228 "Link to this heading") * Add packages for MySQL and SQLite parsers ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id229 "Link to this heading") * Support Postgres macaddr type in Go (#358) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-endtoend "Link to this heading") * Remove %w (#354) ### Kotlin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id230 "Link to this heading") * Add Query class to support timeout and cancellation (#368) ### Postgresql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id231 "Link to this heading") * Add experimental parser for MySQL ### Sql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sql "Link to this heading") * Add generic SQL AST ### Sql/ast[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id232 "Link to this heading") * Port support for COMMENT ON (#391) * Implement DROP TYPE (#397) * Implement ALTER TABLE RENAME (#398) * Implement ALTER TABLE RENAME column (#399) * Implement ALTER TABLE SET SCHEMA (#400) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id233 "Link to this heading") * Port tests over from catalog pkg (#402) ### Sql/errors[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#sql-errors "Link to this heading") * Add a new errors package (#390) ### Sqlite[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id234 "Link to this heading") * Add experimental parser for SQLite [1.0.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.0.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id235 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-02-18 ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id236 "Link to this heading") * Add documentation for query commands (#270) * Add named parameter documentation (#332) ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id237 "Link to this heading") * Add sponsors section (#333) ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id238 "Link to this heading") * Remove parse subcommand (#322) ### Config[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id239 "Link to this heading") * Parse V2 config format * Add support for YAML (#336) ### Examples[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id240 "Link to this heading") * Add the jets and booktest examples (#237) * Move sqlc.json into examples folder (#238) * Add the authors example (#241) * Add build tag to authors tests (#319) ### Internal[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id241 "Link to this heading") * Allow CTE to be used with UPDATE (#268) * Remove the PackageMap from settings (#295) ### Internal/config[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id242 "Link to this heading") * Create new config package (#313) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id243 "Link to this heading") * Emit Querier interface (#240) * Strip leading “go-” or trailing “-go” from import (#262) * Overrides can now be basic types (#271) * Import needed types for Querier (#285) * Handle schema-scoped enums (#310) * Ignore golang-migrate rollbacks (#320) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id244 "Link to this heading") * Move more tests to the record/replay framework * Add update test for named params (#329) ### Internal/mysql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-mysql "Link to this heading") * Fix flaky test (#242) * Port tests to endtoend package (#315) ### Internal/parser[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-parser "Link to this heading") * Resolve nested CTEs (#324) * Error if last query is missing (#325) * Support joins with aliases (#326) * Remove print statement (#327) ### Internal/sqlc[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-sqlc "Link to this heading") * Add support for composite types (#311) ### Kotlin[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id245 "Link to this heading") * Support primitives * Arrays, enums, and dates * Generate examples * README for examples * Factor out db setup extension * Fix enums, use List instead of Array * Port Go tests for examples * Rewrite numbered params to positional params * Always use use, fix indents * Unbox query params ### Parser[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id246 "Link to this heading") * Attach range vars to insert params * Attach range vars to insert params (#342) * Remove dead code (#343) [0.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v0.1.0) [](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id247 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-01-07 ### Documentation[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id248 "Link to this heading") * Replace remaining references to DinoSQL with sqlc (#149) ### README[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id249 "Link to this heading") * Fix download links (#66) * Add LIMIT 1 to query that should return one (#99) ### Catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id250 "Link to this heading") * Support “ALTER TABLE … DROP CONSTRAINT …” (#34) * Differentiate functions with different argument types (#51) ### Ci[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id251 "Link to this heading") * Enable tests on pull requests ### Cmd[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id252 "Link to this heading") * Include filenames in error messages (#69) * Do not output any changes on error (#72) ### Dinosql/internal[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#dinosql-internal "Link to this heading") * Add lower and upper functions (#215) * Ignore alter sequence commands (#219) ### Gen[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id253 "Link to this heading") * Add DO NOT EDIT comments to generated code (#50) * Include all schemas when generating models (#90) * Prefix structs with schema name (#91) * Generate single import for uuid package (#98) * Use same import logic for all Go files * Pick correct struct to return for queries (#107) * Create consistent JSON tags (#110) * Add Close method to Queries struct (#127) * Ignore empty override settings (#128) * Turn SQL comments into Go comments (#136) ### Internal/catalog[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-catalog "Link to this heading") * Parse unnamed function arguments (#166) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id254 "Link to this heading") * Prepare() with no GoQueries still valid (#95) * Fix multiline comment rendering (#142) * Dereference alias nodes on walk (#158) * Ignore sql-migrate rollbacks (#160) * Sort imported packages (#165) * Add support for timestamptz (#169) * Error on missing queries (#180) * Use more database/sql null types (#182) * Support the pg\_temp schema (#183) * Override columns with array type (#184) * Implement robust expansion * Implement robust expansion (#186) * Add COMMENT ON support (#191) * Add DATE support * Add DATE support (#196) * Filter out invalid characters (#198) * Quote reserved keywords (#205) * Return parser errors first (#207) * Implement advisory locks (#212) * Error on duplicate query names (#221) * Fix incorrect enum names (#223) * Add support for numeric types * Add support for numeric types (#228) ### Internal/dinosql/testdata/ondeck[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#internal-dinosql-testdata-ondeck "Link to this heading") * Add Makefile (#156) ### Ondeck[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#ondeck "Link to this heading") * Move all tests to GitHub CI (#58) ### ParseQuery[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#parsequery "Link to this heading") * Return either a query or an error (#178) ### Parser[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#id255 "Link to this heading") * Use schema when resolving catalog refs (#82) * Support function calls in expressions (#104) * Correctly handle single files (#119) * Return error if missing RETURNING (#131) * Add support for mathmatical operators (#132) * Add support for simple case expressions (#134) * Error on mismatched INSERT input (#135) * Set IsArray on joined columns (#139) ### Pg[](https://docs.sqlc.dev/en/v1.27.0/reference/changelog.html#pg "Link to this heading") * Store functions in the catalog (#41) * Add location to errors (#73) --- # Changelog — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/latest/index.html) * Changelog * [View page source](https://docs.sqlc.dev/en/latest/_sources/reference/changelog.md.txt) * * * Changelog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#changelog "Link to this heading") ======================================================================================================== All notable changes to this project will be documented in this file. [1.31.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.31.1) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-31-1 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2026-04-22 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#bug-fixes "Link to this heading") * Remove go.mod replace directive that breaks `go install ...@latest` (#4401) * Downgrade github.com/ncruces/go-sqlite3 to v0.32.0 (#4400) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#build "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 (#4398) [1.31.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.31.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-31-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2026-04-19 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id3 "Link to this heading") * Strip psql meta-commands from schema files (#4390) * Emit pointers for nullable enum columns when `emit_pointers_for_null_types` is set (#4388) * Map xid8 to pgtype.Uint64 for pgx/v5 (#4387) * Rename `:one` return variable when it conflicts with a parameter (#4383) * Coerce SQLite JSONB output regardless of type casing (#4385) * Dedupe `sqlc.arg` parameters wrapped in a type cast for MySQL (#4384) * Preserve MySQL optimizer hints in generated query text (#4382) * Catch invalid `ON CONFLICT DO UPDATE` column references (#4366) * Replace manual loop with `copy()` builtin (#4166) * (native) Make MySQL connection check immediate on first attempt (#4254) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#documentation "Link to this heading") * Add link to community python plugin (#4157) * Add Claude Code remote environment setup instructions (#4246) * Add sqlc-gen-sqlx to community language support (#4371) * Add GitHub Topic to the plugins page (#4258) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#features "Link to this heading") * (sqlfile) Add `sqlfile.Split` (#4146) * (sqlite) Add database analyzer using ncruces/go-sqlite3 (#4199) * (ast) Implement comprehensive SQL AST formatting (#4205) * (mysql) Improve AST formatting and add DELETE JOIN support (#4206) * (sqlite) Add SQLite support to format tests (#4207) * (expander) Add star expander for `SELECT *` and `RETURNING *` (PostgreSQL, MySQL, SQLite) (#4203) * Add `SQLCEXPERIMENT` environment variable for experimental features (#4228) * Add native database support for e2e tests without Docker (#4236) * (postgresql) Add analyzerv2 experiment for database-only analysis (#4237) * Graduate parsecmd experiment (#4253) * Add parse subcommand with AST JSON output (#4240) * Add ClickHouse support to `sqlc parse` (#4267) * Add `sqlc-test-setup` command for database test environment setup (#4304) ### Refactor[](https://docs.sqlc.dev/en/latest/reference/changelog.html#refactor "Link to this heading") * (ast) Rename Formatter interface to Dialect (#4208) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id4 "Link to this heading") * Upgrade Go toolchain to 1.26.2 (#4378) * Upgrade Go version to 1.26.0 (#4312) * Remove github.com/jackc/pgx/v4 dependency (#4379) * Upgrade github.com/pingcap/tidb/pkg/parser (#4389) * Install PostgreSQL from theseus-rs/postgresql-binaries instead of apt (#4310) * Skip CI/RTD builds when the change is irrelevant (#4381) * (deps) 35 dependabot bumps (collapsed from individual entries) [1.30.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.30.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-30-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-09-01 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id6 "Link to this heading") * (compiler/mysql) Prevent panic in convertSetOprSelectList() (#4042) * Range subselect alias pointer dereference (#3711) * (codegen/golang) Don’t omit enums used as arrays (#4058) * (codegen/golang) Handle `go_struct_tag` for `db_type` overrides (#4055) * (engine/dolphin) Remove references to deprecated `pcast.ChangeStmt` (#4057) * Normalize identifier usage for table names (#4045) * (engine/sqlite) Fix parsing of INSERT DEFAULT VALUES syntax (#4010) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id7 "Link to this heading") * Fix parameter syntax inconsistency for MySQL and SQLite (#4036) * Use correct configuration to generate the given output for JSON type override (#4049) * Clean up and add to docs regarding type overrides (#4060) * Try a different admonition format (#4061) * Use the correct admonition format (#4062) * Add multi-worded table example for renaming (#4067) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id8 "Link to this heading") * (docs) Add link to Gleam/parrot (#4038) * (engine/dolphin) Implement MATCH\_AGAINST conversion in SQL AST (#1192, #3091) (#4070) * (engine/sqlite) Coerce jsonb columns to json before returning to Go code (#3968) ### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#testing "Link to this heading") * (endtoend) Skip process\_plugin\_sqlc\_gen\_json (#4075) * (endtoend) Use Docker to start database servers (#4076) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id9 "Link to this heading") * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3941) * (deps) Bump packaging (#3940) * (deps) Bump golang from 1.24.2 to 1.24.4 (#3983) * (deps) Bump golang from 1.24.4 to 1.24.5 (#4014) * (deps) Bump urllib3 from 2.4.0 to 2.5.0 in /docs (#3994) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3989) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4027) * (deps) Bump modernc.org/sqlite (#4032) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4018) * (deps) Bump certifi in /docs in the production-dependencies group (#4041) * (deps) Bump google.golang.org/protobuf (#4043) * (deps) Bump actions/checkout from 4 to 5 (#4059) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#4071) * (deps) Bump requests in /docs in the production-dependencies group (#4068) * Upgrade to Go 1.25 (#4074) * (deps) Bump golang from 1.24.5 to 1.25.0 (#4063) * (deps) Bump github.com/google/cel-go (#4080) [1.29.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.29.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-29-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-04-14 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id11 "Link to this heading") * (docs) Correct spelling and grammar (#3645) * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) * (pgx) Do not wrap nil error (#3913) * (migrations) Normalize case for migration statement for all cases (#3919) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id12 "Link to this heading") * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Add changelog for 1.28.0 (#3797) * Add PHP DBAL plugin (#3813) * Fix PostGIS function name (#3829) * Add Zig plugin (#3824) * Add link to tandemdude/sqlc-gen-java (#3819) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id13 "Link to this heading") * (docs) How-to use transactions with pgx (#3557) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) * (mysql) Add a test for VECTOR column type (#3734) * (cli) Bump version from 1.27.0 to 1.28.0 (#3798) * (codegen/golang) Add an option to wrap query errors that includes query name (#3876) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#miscellaneous-tasks "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) * Update sqlc-gen-java supported engines (#3843) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id14 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) * (deps) Bump golang.org/x/net from 0.30.0 to 0.33.0 (#3796) * (deps) Bump golang from 1.23.5 to 1.23.6 (#3822) * Use govulncheck action (#3831) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3817) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3826) * (deps) Bump golang from 1.23.6 to 1.24.0 (#3842) * (deps) Bump myst-parser (#3841) * (deps) Bump modernc.org/sqlite (#3846) * (deps) Bump golang from 1.24.0 to 1.24.1 (#3870) * (deps) Bump jinja2 in /docs in the production-dependencies group (#3872) * Upgrade to wazero@v1.9.0 (#3887) * Upgrade to Go 1.24.1 (#3892) * Upgrade to latest version of MySQL parser (#3893) * (deps) Bump pyparsing (#3890) * (deps) Bump golang.org/x/net from 0.33.0 to 0.37.0 (#3894) * (deps) Bump the production-dependencies group across 1 directory with 8 updates (#3896) * (deps) Bump github.com/jackc/pgx/v5 (#3898) * (deps) Bump the production-dependencies group (#3899) * (deps) Bump modernc.org/sqlite (#3905) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3914) * (deps) Bump urllib3 in /docs in the production-dependencies group (#3926) * (deps) Bump golang from 1.24.1 to 1.24.2 (#3915) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3923) * (deps) Upgrade github.com/wasilibs/go-pgquery (#3927) [1.28.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.28.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-28-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-01-20 ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id16 "Link to this heading") * (mysql) Add a test for VECTOR column type (#3734) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id17 "Link to this heading") * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id18 "Link to this heading") * How-to use transactions with pgx (#3557) * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Correct spelling and grammar (#3645) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id19 "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id20 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) [1.27.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.27.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-27-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-08-05 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id22 "Link to this heading") * (dbmanager) Add leading slash to db uri path rewrite (#3493) * (verify) Include database engine in request (#3522) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id23 "Link to this heading") * (golang) Add initialisms configuration (#3308) * (compiler) Support subqueries in the FROM clause (second coming) (#3310) * Managed databases with any accessible server (#3421) * (vet) Use new dbmanager client (#3423) * (verify) Update verify to work with managed databases (#3425) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id24 "Link to this heading") * Fix typo in config (#3358) * Resolve a typo in configuration keys (#3349) * Add sponsorship information to README (#3413) * Update the language-support to include C# (#3408) * Add migration guide for hosted managed databases (#3417) * Fix readme links (#3424) * Update the managed db and verify documentation (#3426) * Add sponsor image (#3428) * Add Ruby as supported language (#3487) * Update migrating-to-sqlc-gen-kotlin.md (#3454) * Fix typo in comment (#3316) * Fix deprecated build tag format (#3361) ### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id25 "Link to this heading") * (endtoend) Re-use databases when possible (#3315) * Enabled MySQL database (#3318) * Remove internal/sqltest/hosted package (#3521) [1.26.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.26.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-26-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-03-28 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#release-notes "Link to this heading") This release is mainly a bug fix release. It also includes an [important security fix](https://github.com/sqlc-dev/sqlc/issues/3194) for users using output plugins. ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#changes "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id27 "Link to this heading") * (docker) Use distroless base image instead of scratch (#3111) * (generate) Ensure files are created inside output directory (#3195) * (mysql) BREAKING: Use `int16` for MySQL `SMALLINT` and `YEAR` (#3106) * (mysql) BREAKING: Use `int8` for MySQL TINYINT (#3298) * (mysql) Variables not resolving in ORDER BY statements (#3115) * (opts) Validate SQL package and driver options (#3241) * (postgres/batch) Ignore query\_parameter\_limit for batches * (scripts) Remove deprecated test output regeneration script (#3105) * (sqlite) Correctly skip unknown statements (#3239) #### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id28 "Link to this heading") * (postgres) Add instructions for PostGIS/GEOS (#3182) * Improve details on TEXT (#3247) #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id29 "Link to this heading") * (generate) Avoid generating empty Go imports (#3135) * (mysql) Add NEXTVAL() to the MySQL catalog (#3147) * (mysql) Support json.RawMessage for LOAD DATA INFILE (#3099) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id30 "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 to 5.5.5 (#3259) * (deps) Bump modernc.org/sqlite to 1.29.5 (#3200) * (deps) Bump github.com/go-sql-driver/mysql to 1.8.0 (#3257) * (deps) Bump github.com/tetratelabs/wazero to 1.7.0 (#3096) * (deps) Bump github.com/pganalyze/pg\_query\_go to v5 (#3096) [1.25.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.25.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-25-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-01-03 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id32 "Link to this heading") #### Add tags to push and verify[](https://docs.sqlc.dev/en/latest/reference/changelog.html#add-tags-to-push-and-verify "Link to this heading") You can add tags when [pushing](https://docs.sqlc.dev/en/latest/howto/push.html) schema and queries to [sqlc Cloud](https://dashboard.sqlc.dev/) . Tags operate like git tags, meaning you can overwrite previously-pushed tag values. We suggest tagging pushes to associate them with something relevant from your environment, e.g. a git tag or branch name. $ sqlc push --tag v1.0.0 Once you’ve created a tag, you can refer to it when [verifying](https://docs.sqlc.dev/en/latest/howto/verify.html) changes, allowing you to compare the existing schema against a known set of previous queries. $ sqlc verify --against v1.0.0 #### C-ya, `cgo`[](https://docs.sqlc.dev/en/latest/reference/changelog.html#c-ya-cgo "Link to this heading") Over the last month, we’ve switched out a few different modules to remove our reliance on [cgo](https://go.dev/blog/cgo) . Previously, we needed cgo for three separate functions: * Parsing PostgreSQL queries with [pganalyze/pg\_query\_go](https://github.com/pganalyze/pg_query_go) * Running SQLite databases with [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) * Executing WASM / WASI code with [bytecodealliance/wasmtime-go](https://github.com/bytecodealliance/wasmtime-go) With the help of the community, we found cgo-free alternatives for each module: * Parsing PostgreSQL queries, now using [wasilibs/go-pgquery](https://github.com/wasilibs/go-pgquery) * Running SQLite databases, now using [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) * Executing WASM / WASI code, now using [tetratelabs/wazero](https://github.com/tetratelabs/wazero) For the first time, Windows users can enjoy full PostgreSQL support without using [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) . It’s a Christmas miracle! If you run into any issues with the updated dependencies, please [open an issue](https://github.com/sqlc-dev/sqlc/issues) . ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id33 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id34 "Link to this heading") * (codegen) Wrong yaml annotation in go codegen options for output\_querier\_file\_name (#3006) * (codegen) Use derived ArrayDims instead of deprecated attndims (#3032) * (codegen) Take the maximum array dimensions (#3034) * (compiler) Skip analysis of queries without a `name` annotation (#3072) * (codegen/golang) Don’t import `"strings"` for `sqlc.slice()` with pgx (#3073) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id35 "Link to this heading") * Add name to query set configuration (#3011) * Add a sidebar link for `push`, add Go plugin link (#3023) * Update banner for sqlc-gen-typescript (#3036) * Add strict\_order\_by in doc (#3044) * Re-order the migration tools list (#3064) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id36 "Link to this heading") * (analyzer) Return zero values when encountering unexpected ast nodes (#3069) * (codegen/go) add omit\_sqlc\_version to Go code generation (#3019) * (codgen/go) Add `emit_sql_as_comment` option to Go code plugin (#2735) * (plugins) Use wazero instead of wasmtime (#3042) * (push) Add tag support (#3074) * (sqlite) Support emit\_pointers\_for\_null\_types (#3026) ### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id37 "Link to this heading") * (endtoend) Enable for more build targets (#3041) * (endtoend) Run MySQL and PostgreSQL locally on the runner (#3095) * (typescript) Test against sqlc-gen-typescript (#3046) * Add tests for omit\_sqlc\_version (#3020) * Split schema and query for test (#3094) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id38 "Link to this heading") * (deps) Bump idna from 3.4 to 3.6 in /docs (#3010) * (deps) Bump sphinx-rtd-theme from 1.3.0 to 2.0.0 in /docs (#3016) * (deps) Bump golang from 1.21.4 to 1.21.5 (#3043) * (deps) Bump actions/setup-go from 4 to 5 (#3047) * (deps) Bump github.com/jackc/pgx/v5 from 5.5.0 to 5.5.1 (#3050) * (deps) Upgrade to latest version of github.com/wasilibs/go-pgquery (#3052) * (deps) Bump google.golang.org/grpc from 1.59.0 to 1.60.0 (#3053) * (deps) Bump babel from 2.13.1 to 2.14.0 in /docs (#3055) * (deps) Bump actions/upload-artifact from 3 to 4 (#3061) * (deps) Bump modernc.org/sqlite from 1.27.0 to 1.28.0 (#3062) * (deps) Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#3068) * (deps) Bump google.golang.org/grpc from 1.60.0 to 1.60.1 (#3070) * (deps) Bump google.golang.org/protobuf from 1.31.0 to 1.32.0 (#3079) * (deps) Bump github.com/tetratelabs/wazero from 1.5.0 to 1.6.0 (#3096) * (sqlite) Update to antlr 4.13.1 (#3086) * (sqlite) Disable modernc for WASM (#3048) * (sqlite) Switch from mattn/go-sqlite3 to modernc.org/sqlite (#3040) [1.24.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.24.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-24-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-11-22 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id40 "Link to this heading") #### Verifying database schema changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#verifying-database-schema-changes "Link to this heading") Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. #### Rename `upload` command to `push`[](https://docs.sqlc.dev/en/latest/reference/changelog.html#rename-upload-command-to-push "Link to this heading") We’ve renamed the `upload` sub-command to `push`. We changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. We also add annotations to each push. By default, we include these environment variables if they are present: GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA Like upload, `push` should be run when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. #### MySQL support in `createdb`[](https://docs.sqlc.dev/en/latest/reference/changelog.html#mysql-support-in-createdb "Link to this heading") The `createdb` command, added in the last release, now supports MySQL. If you have a cloud project configured, you can use `sqlc createdb` to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html#with-other-tools) documentation. #### Plugin interface refactor[](https://docs.sqlc.dev/en/latest/reference/changelog.html#plugin-interface-refactor "Link to this heading") This release includes a refactored plugin interface to better support future functionality. Plugins now support different methods via a gRPC service interface, allowing plugins to support different functionality in a backwards-compatible way. By using gRPC interfaces, we can even (theoretically) support [remote plugins](https://github.com/sqlc-dev/sqlc/pull/2938) , but that’s something for another day. ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id41 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id42 "Link to this heading") * (engine/sqlite) Support CASE expr (#2926) * (engine/sqlite) Support -> and ->> operators (#2927) * (vet) Add a nil pointer check to prevent db/prepare panic (#2934) * (compiler) Prevent panic when compiler is nil (#2942) * (codegen/golang) Move more Go-specific config validation into the plugin (#2951) * (compiler) No panic on full-qualified column names (#2956) * (docs) Better discussion of type override nuances (#2972) * (codegen) Never generate return structs for :exec (#2976) * (generate) Update help text for generate to be more generic (#2981) * (generate) Return an error instead of generating duplicate Go names (#2962) * (codegen/golang) Pull opts into its own package (#2920) * (config) Make some struct and field names less confusing (#2922) #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id43 "Link to this heading") * (codegen) Remove Go specific overrides from codegen proto (#2929) * (plugin) Use gRPC interface for codegen plugin communication (#2930) * (plugin) Calculate SHA256 if it does not exist (#2935) * (sqlc-gen-go) Add script to mirror code to sqlc-gen-go (#2952) * (createdb) Add support for MySQL (#2980) * (verify) Add new command to verify queries and migrations (#2986) #### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id44 "Link to this heading") * (ci) New workflow for sqlc-gen-python (#2936) * (ci) Rely on go.mod to determine which Go version to use (#2971) * (tests) Add glob pattern tests to sqlpath.Glob (#2995) * (examples) Use hosted MySQL databases for tests (#2982) * (docs) Clean up a little, update LICENSE and README (#2941) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id45 "Link to this heading") * (deps) Bump babel from 2.13.0 to 2.13.1 in /docs (#2911) * (deps) Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2944) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.17 to 1.14.18 (#2945) * (deps) Bump golang.org/x/sync from 0.4.0 to 0.5.0 (#2946) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2947) * (deps) Change github.com/pingcap/tidb/parser to github.com/pingcap/tidb/pkg/parser * (deps) Bump github.com/google/cel-go from 0.18.1 to 0.18.2 (#2969) * (deps) Bump urllib3 from 2.0.7 to 2.1.0 in /docs (#2975) * (buf) Change root of Buf module (#2987) * (deps) Bump certifi from 2023.7.22 to 2023.11.17 in /docs (#2993) * (ci) Bump Go version from 1.21.3 to 1.21.4 in workflows and Dockerfile (#2961) [1.23.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.23.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-23-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-10-24 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id47 "Link to this heading") #### Database-backed query analysis[](https://docs.sqlc.dev/en/latest/reference/changelog.html#database-backed-query-analysis "Link to this heading") With a [database connection](https://docs.sqlc.dev/en/latest/reference/config.html#database) configured, `sqlc generate` will gather metadata from that database to support its query analysis. Turning this on resolves a [large number of issues](https://github.com/sqlc-dev/sqlc/issues?q=is%3Aissue+label%3Aanalyzer) in the backlog related to type inference and more complex queries. The easiest way to try it out is with [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html) . The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. #### New `createdb` command[](https://docs.sqlc.dev/en/latest/reference/changelog.html#new-createdb-command "Link to this heading") When you have a cloud project configured, you can use the new `sqlc createdb` command to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html#with-other-tools) documentation. #### Support for pgvector[](https://docs.sqlc.dev/en/latest/reference/changelog.html#support-for-pgvector "Link to this heading") If you’re using [pgvector](https://github.com/pgvector/pgvector) , say goodbye to custom overrides! sqlc now generates code using [pgvector-go](https://github.com/pgvector/pgvector-go#pgx) as long as you’re using `pgx`. The pgvector extension is also available in [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html) . #### Go build tags[](https://docs.sqlc.dev/en/latest/reference/changelog.html#go-build-tags "Link to this heading") With the new `emit_build_tags` configuration parameter you can set build tags for sqlc to add at the top of generated source files. ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id48 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id49 "Link to this heading") * (codegen) Correct column names in :copyfrom (#2838) * (compiler) Search SELECT and UPDATE the same way (#2841) * (dolphin) Support more UNIONs for MySQL (#2843) * (compiler) Account for parameters without parents (#2844) * (postgresql) Remove temporary pool config (#2851) * (golang) Escape reserved keywords (#2849) * (mysql) Handle simplified CASE statements (#2852) * (engine/dolphin) Support enum in ALTER definition (#2680) * (mysql) Add, drop, rename and change enum values (#2853) * (config) Validate `database` config in all cases (#2856) * (compiler) Use correct func signature for `CommentSyntax` on windows (#2867) * (codegen/go) Prevent filtering of embedded struct fields (#2868) * (compiler) Support functions with OUT params (#2865) * (compiler) Pull in array information from analyzer (#2864) * (analyzer) Error on unexpanded star expression (#2882) * (vet) Remove rollback statements from DDL (#2895) #### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id50 "Link to this heading") * Add stable anchors to changelog (#2784) * Fix typo in v1.22.0 changelog (#2796) * Add sqlc upload to CI / CD guide (#2797) * Fix broken link, add clarity to plugins doc (#2813) * Add clarity and reference to JSON tags (#2819) * Replace form with dashboard link (#2840) * (examples) Update examples to use pgx/v5 (#2863) * Use docker compose v2 and update MYSQL\_DATABASE env var (#2870) * Update getting started guides, use pgx for Postgres guide (#2891) * Use managed databases in PostgreSQL getting started guide (#2892) * Update managed databases doc to discuss codegen (#2897) * Add managed dbs to CI/CD and vet guides (#2896) * Document database-backed query analyzer (#2904) #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id51 "Link to this heading") * (codegen) Support setting Go build tags (#2012) (#2807) * (generate) Reorder codegen handlers to prefer plugins (#2814) * (devenv) Add vscode settings.json with auto newline (#2834) * (cmd) Support sqlc.yml configuration file (#2828) * (analyzer) Analyze queries using a running PostgreSQL database (#2805) * (sql/ast) Render AST to SQL (#2815) * (codegen) Include plugin information (#2846) * (postgresql) Add ALTER VIEW … SET SCHEMA (#2855) * (compiler) Parse query parameter metadata from comments (#2850) * (postgresql) Support system columns on tables (#2871) * (compiler) Support LEFT JOIN on aliased table (#2873) * Improve messaging for common cloud config and rpc errors (#2885) * Abort compiler when rpc fails as unauthenticated (#2887) * (codegen) Add support for pgvector and pgvector-go (#2888) * (analyzer) Cache query analysis (#2889) * (createdb) Create ephemeral databases (#2894) * (debug) Add databases=managed debug option (#2898) * (config) Remove managed database validation (#2901) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id52 "Link to this heading") * (endtoend) Fix test output for do tests (#2782) #### Refactor[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id53 "Link to this heading") * (codegen) Remove golang and json settings from plugin proto (#2822) * (codegen) Removed deprecated code and improved speed (#2899) #### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id54 "Link to this heading") * (endtoend) Split shema and queries (#2803) * Fix a few incorrect testcases (#2804) * (analyzer) Add more database analyzer test cases (#2854) * Add more analyzer test cases (#2866) * Add more test cases for new analyzer (#2879) * (endtoend) Enabled managed-db tests in CI (#2883) * Enabled pgvector tests for managed dbs (#2893) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id55 "Link to this heading") * (deps) Bump packaging from 23.1 to 23.2 in /docs (#2791) * (deps) Bump urllib3 from 2.0.5 to 2.0.6 in /docs (#2798) * (deps) Bump babel from 2.12.1 to 2.13.0 in /docs (#2799) * (deps) Bump golang.org/x/sync from 0.3.0 to 0.4.0 (#2810) * (deps) Bump golang from 1.21.1 to 1.21.2 (#2811) * (deps) Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (#2826) * (deps) Bump golang from 1.21.2 to 1.21.3 (#2824) * (deps) Bump google.golang.org/grpc from 1.58.2 to 1.58.3 (#2825) * (deps) Bump golang.org/x/net from 0.12.0 to 0.17.0 (#2836) * (deps) Bump urllib3 from 2.0.6 to 2.0.7 in /docs (#2872) * (deps) Bump google.golang.org/grpc from 1.58.3 to 1.59.0 (#2876) * (deps) Upgrade wasmtime-go from 13.0.0 to 14.0.0 (#2900) #### Ci[](https://docs.sqlc.dev/en/latest/reference/changelog.html#ci "Link to this heading") * Bump go version in workflows (#2835) [1.22.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.22.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-22-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-26 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id57 "Link to this heading") #### Managed databases for `sqlc vet`[](https://docs.sqlc.dev/en/latest/reference/changelog.html#managed-databases-for-sqlc-vet "Link to this heading") If you’re using [sqlc vet](https://docs.sqlc.dev/en/latest/howto/vet.html) to write rules that require access to a running database, `sqlc` can now start and manage that database for you. PostgreSQL support is available today, with MySQL on the way. When you turn on managed databases, `sqlc` will use your schema to create a template database that it can copy to make future runs of `sqlc vet` very performant. This feature relies on configuration obtained via [sqlc Cloud](https://dashboard.sqlc.dev/) . Read more in the [managed databases](https://docs.sqlc.dev/en/latest/howto/managed-databases.html) documentation. ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id58 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id59 "Link to this heading") * (codegen/golang) Refactor imports code to match templates (#2709) * (codegen/golang) Support name type (#2715) * (wasm) Move Runner struct to shared file (#2725) * (engine/sqlite) Fix grammer to avoid missing join\_constraint (#2732) * (convert) Support YAML anchors in plugin options (#2733) * (mysql) Disallow time.Time in mysql :copyfrom queries, not all queries (#2768) * (engine/sqlite) Fix convert process for VALUES (#2737) #### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id60 "Link to this heading") * Clarify nullable override behavior (#2753) * Add managed databases to sidebar (#2764) * Pull renaming and type overrides into separate sections (#2774) * Update the docs banner for managed dbs (#2775) #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id61 "Link to this heading") * (config) Enables the configuration of copyfrom.go similar to quierer and friends (#2727) * (vet) Run rules against a managed database (#2751) * (upload) Point upload command at new endpoint (#2772) * (compiler) Support DO statements (#2777) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id62 "Link to this heading") * (endtoend) Skip tests missing secrets (#2763) * Skip certain tests on PRs (#2769) #### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id63 "Link to this heading") * (endtoend) Verify all schemas in endtoend (#2744) * (examples) Use a hosted database for example testing (#2749) * (endtoend) Pull region from environment (#2750) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id64 "Link to this heading") * (deps) Bump golang from 1.21.0 to 1.21.1 (#2711) * (deps) Bump google.golang.org/grpc from 1.57.0 to 1.58.1 (#2743) * (deps) Bump wasmtime-go from v12 to v13 (#2756) * (windows) Downgrade to mingw 11.2.0 (#2757) * (deps) Bump urllib3 from 2.0.4 to 2.0.5 in /docs (#2747) * (deps) Bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#2758) * (deps) Bump github.com/google/cel-go from 0.18.0 to 0.18.1 (#2778) #### Ci[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id65 "Link to this heading") * Bump go version to latest in ci workflows (#2722) [1.21.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.21.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-21-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-06 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id67 "Link to this heading") This is primarily a bugfix release, along with some documentation and testing improvements. #### MySQL engine improvements[](https://docs.sqlc.dev/en/latest/reference/changelog.html#mysql-engine-improvements "Link to this heading") `sqlc` previously didn’t know how to parse a `CALL` statement when using the MySQL engine, which meant it was impossible to use sqlc with stored procedures in MySQL databases. Additionally, `sqlc` now supports `IS [NOT] NULL` in queries. And `LIMIT` and `OFFSET` clauses now work with `UNION`. #### SQLite engine improvements[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sqlite-engine-improvements "Link to this heading") GitHub user [@orisano](https://github.com/orisano) continues to bring bugfixes and improvements to `sqlc`’s SQLite engine. See the “Changes” section below for the full list. #### Plugin access to environment variables[](https://docs.sqlc.dev/en/latest/reference/changelog.html#plugin-access-to-environment-variables "Link to this heading") If you’re authoring a [sqlc plugin](https://docs.sqlc.dev/en/latest/reference/changelog.html#../guides/plugins.html) , you can now configure sqlc to pass your plugin the values of specific environment variables. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id68 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id69 "Link to this heading") * Myriad string formatting changes (#2558) * (engine/sqlite) Support quoted identifier (#2556) * (engine/sqlite) Fix compile error (#2564) * (engine/sqlite) Fixed detection of column alias without AS (#2560) * (ci) Bump go version to 1.20.7 (#2568) * Remove references to deprecated `--experimental` flag (#2567) * (postgres) Fixed a problem with array dimensions disappearing when using “ALTER TABLE ADD COLUMN” (#2572) * Remove GitHub sponsor integration (#2574) * (docs) Improve discussion of prepared statements support (#2604) * (docs) Remove multidimensional array qualification in datatypes.md (#2619) * (config) Go struct tag parsing (#2606) * (compiler) Fix to not scan children under ast.RangeSubselect when retrieving table listing (#2573) * (engine/sqlite) Support NOT IN (#2587) * (codegen/golang) Fixed detection of the used package (#2597) * (engine/dolphin) Fixed problem that LIMIT OFFSET cannot be used with `UNION ALL` (#2613) * (compiler) Support identifiers with schema (#2579) * (compiler) Fix column expansion to work with quoted non-keyword identifiers (#2576) * (codegen/go) Compare define type in codegen (#2263) (#2578) * (engine/sqlite) Fix ast when using compound operator (#2673) * (engine/sqlite) Fix to handle join clauses correctly (#2674) * (codegen) Use correct Go types for bit strings and cid/oid/tid/xid with pgx/v4 (#2668) * (endtoend) Ensure all SQL works against PostgreSQL (#2684) #### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id70 "Link to this heading") * Update Docker installation instructions (#2552) * Missing emit\_pointers\_for\_null\_types configuration option in version 2 (#2682) (#2683) * Fix typo (#2697) * Document sqlc.\* macros (#2698) * (mysql) Document parseTimet=true requirement (#2699) * Add atlas to the list of supported migration frameworks (#2700) * Minor updates to insert howto (#2701) #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id71 "Link to this heading") * (endtoend/testdata) Added two sqlite `CAST` tests and rearranged postgres tests for same (#2551) * (docs) Add a reference to type overriding in datatypes.md (#2557) * (engine/sqlite) Support COLLATE for sqlite WHERE clause (#2554) * (mysql) Add parser support for IS \[NOT\] NULL (#2651) * (engine/dolphin) Support CALL statement (#2614) * (codegen) Allow plugins to access environment variables (#2669) * (config) Add JSON schema files for configs (#2703) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id72 "Link to this heading") * Ignore Vim swap files (#2616) * Fix typo (#2696) #### Refactor[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id73 "Link to this heading") * (astutils) Remove redundant nil check in `Walk` (#2660) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id74 "Link to this heading") * (deps) Bump wasmtime from v8.0.0 to v11.0.0 (#2553) * (deps) Bump golang from 1.20.6 to 1.20.7 (#2563) * (deps) Bump chardet from 5.1.0 to 5.2.0 in /docs (#2562) * (deps) Bump github.com/pganalyze/pg\_query\_go/v4 (#2583) * (deps) Bump golang from 1.20.7 to 1.21.0 (#2596) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.2 to 5.4.3 (#2582) * (deps) Bump pygments from 2.15.1 to 2.16.1 in /docs (#2584) * (deps) Bump sphinxcontrib-applehelp from 1.0.4 to 1.0.7 in /docs (#2620) * (deps) Bump sphinxcontrib-qthelp from 1.0.3 to 1.0.6 in /docs (#2622) * (deps) Bump github.com/google/cel-go from 0.17.1 to 0.17.6 (#2650) * (deps) Bump sphinxcontrib-serializinghtml in /docs (#2641) * Upgrade from Go 1.20 to Go 1.21 (#2665) * (deps) Bump sphinxcontrib-devhelp from 1.0.2 to 1.0.5 in /docs (#2621) * (deps) Bump github.com/bytecodealliance/wasmtime-go from v11.0.0 to v12.0.0 (#2666) * (deps) Bump sphinx-rtd-theme from 1.2.2 to 1.3.0 in /docs (#2670) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.1 to 2.0.4 in /docs (#2671) * (deps) Bump github.com/google/cel-go from 0.17.6 to 0.18.0 (#2691) * (deps) Bump actions/checkout from 3 to 4 (#2694) * (deps) Bump pytz from 2023.3 to 2023.3.post1 in /docs (#2695) * (devenv) Bump go from 1.20.7 to 1.21.0 (#2702) [1.20.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.20.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#v1-20-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-31 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id76 "Link to this heading") #### `kyleconroy/sqlc` is now `sqlc-dev/sqlc`[](https://docs.sqlc.dev/en/latest/reference/changelog.html#kyleconroy-sqlc-is-now-sqlc-dev-sqlc "Link to this heading") We’ve completed our migration to the [sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc) repository. All existing links and installation instructions will continue to work. If you’re using the `go` tool to install `sqlc`, you’ll need to use the new import path to get v1.20.0 (and all future versions). \# INCORRECT: old import path go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.20.0 \# CORRECT: new import path go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.20.0 We designed the upgrade process to be as smooth as possible. If you run into any issues, please [file a bug report](https://github.com/sqlc-dev/sqlc/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=BUG_REPORT.yml) via GitHub. #### Use `EXPLAIN ...` output in lint rules[](https://docs.sqlc.dev/en/latest/reference/changelog.html#use-explain-output-in-lint-rules "Link to this heading") `sqlc vet` can now run `EXPLAIN` on your queries and include the results for use in your lint rules. For example, this rule checks that `SELECT` queries use an index. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- has-index rules: \- name: has-index rule: \> query.sql.startsWith("SELECT") && !(postgresql.explain.plan.plans.all(p, has(p.index\_name) || p.plans.all(p, has(p.index\_name)))) The expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/latest/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. #### Opting-out of lint rules[](https://docs.sqlc.dev/en/latest/reference/changelog.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; #### Bulk insert for MySQL[](https://docs.sqlc.dev/en/latest/reference/changelog.html#bulk-insert-for-mysql "Link to this heading") _Developed by [@Jille](https://github.com/Jille) _ MySQL now supports the `:copyfrom` query annotation. The generated code uses the [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) command to insert data quickly and efficiently. Use caution with this feature. Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use `SHOW WARNINGS` to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } `LOAD DATA` support must be enabled in the MySQL server. #### CAST support for MySQL[](https://docs.sqlc.dev/en/latest/reference/changelog.html#cast-support-for-mysql "Link to this heading") _Developed by [@ryanpbrewster](https://github.com/ryanpbrewster) and [@RadhiFadlillah](https://github.com/RadhiFadlillah) _ `sqlc` now understands `CAST` calls in MySQL queries, offering greater flexibility when generating code for complex queries. CREATE TABLE foo (bar BOOLEAN NOT NULL); \-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo; package querytest import ( "context" ) const selectColumnCast \= \`-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo \` func (q \*Queries) SelectColumnCast(ctx context.Context) (\[\]int64, error) { ... } #### SQLite improvements[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sqlite-improvements "Link to this heading") A slew of fixes landed for our SQLite implementation, bringing it closer to parity with MySQL and PostgreSQL. We want to thank [@orisano](https://github.com/orisano) for their continued dedication to improving `sqlc`’s SQLite support. ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id77 "Link to this heading") #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id78 "Link to this heading") * (debug) Add debug flag and docs for dumping vet rule variables (#2521) * (mysql) :copyfrom support via LOAD DATA INFILE (#2545) * (mysql) Implement cast function parser (#2473) * (postgresql) Add support for PostgreSQL multi-dimensional arrays (#2338) * (sql/catalog) Support ALTER TABLE IF EXISTS (#2542) * (sqlite) Virtual tables and fts5 supported (#2531) * (vet) Add default query parameters for explain queries (#2543) * (vet) Add output from `EXPLAIN ...` for queries to the CEL program environment (#2489) * (vet) Introduce a query annotation to opt out of sqlc vet rules (#2474) * Parse comment lines starting with `@symbol` as boolean flags associated with a query (#2464) #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id79 "Link to this heading") * (codegen/golang) Fix sqlc.embed to work with pq.Array (#2544) * (compiler) Correctly validate alias in order/group by clauses for joins (#2537) * (engine/sqlite) Added function to convert cast node (#2470) * (engine/sqlite) Fix join\_operator rule (#2434) * (engine/sqlite) Fix table\_alias rules (#2465) * (engine/sqlite) Fixed IN operator precedence (#2428) * (engine/sqlite) Fixed to be able to find relation from WITH clause (#2444) * (engine/sqlite) Lowercase ast.ResTarget.Name (#2433) * (engine/sqlite) Put logging statement behind debug flag (#2488) * (engine/sqlite) Support for repeated table\_option (#2482) * (mysql) Generate unsigned param (#2522) * (sql/catalog) Support pg\_dump output (#2508) * (sqlite) Code generation for sqlc.slice (#2431) * (vet) Clean up unnecessary `prepareable()` func and a var name (#2509) * (vet) Query.cmd was always set to “:” (#2525) * (vet) Report an error when a query is unpreparable, close prepared statement connection (#2486) * (vet) Split vet messages out of codegen.proto (#2511) #### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id80 "Link to this heading") * Add a description to the document for cases when a query result has no rows (#2462) * Update copyright and author (#2490) * Add example sqlc.yaml for migration parsing (#2479) * Small updates (#2506) * Point GitHub links to new repository location (#2534) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id81 "Link to this heading") * Rename kyleconroy/sqlc to sqlc-dev/sqlc (#2523) * (proto) Reformat protos using `buf format -w` (#2536) * Update FEATURE\_REQUEST.yml to include SQLite engine option * Finish migration to sqlc-dev/sqlc (#2548) * (compiler) Remove some duplicate code (#2546) #### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id82 "Link to this heading") * Add profiles to docker compose (#2503) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id83 "Link to this heading") * Run all supported versions of MySQL / PostgreSQL (#2463) * (deps) Bump pygments from 2.7.4 to 2.15.0 in /docs (#2485) * (deps) Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2483) * (deps) Bump github.com/google/cel-go from 0.16.0 to 0.17.1 (#2484) * (docs) Check Python dependencies via dependabot (#2497) * (deps) Bump idna from 2.10 to 3.4 in /docs (#2499) * (deps) Bump packaging from 20.9 to 23.1 in /docs (#2498) * (deps) Bump pygments from 2.15.0 to 2.15.1 in /docs (#2500) * (deps) Bump certifi from 2022.12.7 to 2023.7.22 in /docs (#2504) * (deps) Bump sphinx from 4.4.0 to 6.1.0 in /docs (#2505) * Add psql and mysqlsh to devenv (#2507) * (deps) Bump urllib3 from 1.26.5 to 2.0.4 in /docs (#2516) * (deps) Bump chardet from 4.0.0 to 5.1.0 in /docs (#2517) * (deps) Bump snowballstemmer from 2.1.0 to 2.2.0 in /docs (#2519) * (deps) Bump pytz from 2021.1 to 2023.3 in /docs (#2520) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.0 to 2.0.1 in /docs (#2518) * (deps) Bump pyparsing from 2.4.7 to 3.1.0 in /docs (#2530) * (deps) Bump alabaster from 0.7.12 to 0.7.13 in /docs (#2526) * (docs) Ignore updates for sphinx (#2532) * (deps) Bump babel from 2.9.1 to 2.12.1 in /docs (#2527) * (deps) Bump sphinxcontrib-applehelp from 1.0.2 to 1.0.4 in /docs (#2533) * (deps) Bump google.golang.org/grpc from 1.56.2 to 1.57.0 (#2535) * (deps) Bump pyparsing from 3.1.0 to 3.1.1 in /docs (#2547) [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id84 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-13 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id85 "Link to this heading") * Fix to traverse Sel in ast.In (#2414) * (compiler) Validate UNION … ORDER BY (#2446) * (golang) Prevent duplicate enum output (#2447) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id86 "Link to this heading") * Replace codegen, test and docs references to github.com/tabbed repos (#2418) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id87 "Link to this heading") * (deps) Bump google.golang.org/grpc from 1.56.1 to 1.56.2 (#2415) * (deps) Bump golang from 1.20.5 to 1.20.6 (#2437) * Pin Go to 1.20.6 (#2441) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.1 to 5.4.2 (#2436) [1.19.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id88 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-06 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id89 "Link to this heading") #### sqlc vet[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sqlc-vet "Link to this heading") [`sqlc vet`](https://docs.sqlc.dev/en/latest/howto/vet.html) runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/latest/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, an error is reported using the given message. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ##### Database connectivity[](https://docs.sqlc.dev/en/latest/reference/changelog.html#database-connectivity "Link to this heading") `vet` also marks the first time that `sqlc` can connect to a live, running database server. We’ll expand this functionality over time, but for now it powers the `sqlc/db-prepare` built-in rule. When a [database](https://docs.sqlc.dev/en/latest/reference/changelog.html#config.html#database) is configured, the `sqlc/db-preapre` rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Please note that `sqlc` does not manage or migrate your database. Use your migration tool of choice to create the necessary database tables and objects before running `sqlc vet`. #### Omit unused structs[](https://docs.sqlc.dev/en/latest/reference/changelog.html#omit-unused-structs "Link to this heading") Added a new configuration parameter `omit_unused_structs` which, when set to true, filters out table and enum structs that aren’t used in queries for a given package. #### Suggested CI/CD setup[](https://docs.sqlc.dev/en/latest/reference/changelog.html#suggested-ci-cd-setup "Link to this heading") With the addition of `sqlc diff` and `sqlc vet`, we encourage users to run sqlc in your CI/CD pipelines. See our [suggested CI/CD setup](https://docs.sqlc.dev/en/latest/howto/ci-cd.html) for more information. #### Simplified plugin development[](https://docs.sqlc.dev/en/latest/reference/changelog.html#simplified-plugin-development "Link to this heading") The [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) and [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) plugins have been updated use the upcoming [WASI](https://wasi.dev/) support in [Go 1.21](https://tip.golang.org/doc/go1.21#wasip1) . Building these plugins no longer requires [TinyGo](https://tinygo.org/) . ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id90 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id91 "Link to this heading") * Pointers overrides skip imports in generated query files (#2240) * CASE-ELSE clause is not properly parsed when a value is constant (#2238) * Fix toSnakeCase to handle input in CamelCase format (#2245) * Add location info to sqlite ast (#2298) * Add override tags to result struct (#1867) (#1887) * Override types of aliased columns and named parameters (#1884) * Resolve duplicate fields generated when inheriting multiple tables (#2089) * Check column references in ORDER BY (#1411) (#1915) * MySQL slice shadowing database/sql import (#2332) * Don’t defer rows.Close() if pgx.BatchResults.Query() failed (#2362) * Fix type overrides not working with sqlc.slice (#2351) * Type overrides on columns for parameters inside an IN clause (#2352) * Broken interaction between query\_parameter\_limit and pq.Array() (#2383) * (codegen/golang) Bring :execlastid in line with the rest (#2378) #### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id92 "Link to this heading") * Update changelog.md with some minor edits (#2235) * Add F# community plugin (#2295) * Add a ReadTheDocs config file (#2327) * Update query\_parameter\_limit documentation (#2374) * Add launch announcement banner #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id93 "Link to this heading") * PostgreSQL capture correct line and column numbers for parse error (#2289) * Add supporting COMMENT ON VIEW (#2249) * To allow spaces between function name and arguments of functions to be rewritten (#2250) * Add support for pgx/v5 emit\_pointers\_for\_null\_types flag (#2269) * (mysql) Support unsigned integers (#1746) * Allow use of table and column aliases for table functions returning unknown types (#2156) * Support “LIMIT ?” in UPDATE and DELETE for MySQL (#2365) * (internal/codegen/golang) Omit unused structs from output (#2369) * Improve default names for BETWEEN ? AND ? to have prefixes from\_ and to\_ (#2366) * (cmd/sqlc) Add the vet subcommand (#2344) * (sqlite) Add support for UPDATE/DELETE with a LIMIT clause (#2384) * Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) (#2373) * (cmd/vet) Prepare queries against a database (#2387) * (cmd/vet) Prepare queries for MySQL (#2388) * (cmd/vet) Prepare SQLite queries (#2389) * (cmd/vet) Simplify environment variable substiution (#2393) * (cmd/vet) Add built-in db-prepare rule * Add compiler support for NOTIFY and LISTEN (PostgreSQL) (#2363) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id94 "Link to this heading") * A few small staticcheck fixes (#2361) * Remove a bunch of dead code (#2360) * (scripts/regenerate) Should also update stderr.txt (#2379) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id95 "Link to this heading") * (deps) Bump requests from 2.25.1 to 2.31.0 in /docs (#2283) * (deps) Bump golang from 1.20.3 to 1.20.4 (#2256) * (deps) Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#2265) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 (#2293) * (deps) Bump golang.org/x/sync from 0.1.0 to 0.2.0 (#2266) * (deps) Bump golang from 1.20.4 to 1.20.5 (#2301) * Configure dependencies via devenv.sh (#2319) * Configure dependencies via devenv.sh (#2326) * (deps) Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#2328) * (deps) Bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#2333) * (deps) Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 (#2370) * (deps) Bump actions/checkout from 2 to 3 (#2357) * Run govulncheck on all builds (#2372) * (deps) Bump google.golang.org/grpc from 1.56.0 to 1.56.1 (#2358) #### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#cmd-sqlc "Link to this heading") * Show helpful output on missing subcommand (#2345) #### Codegen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#codegen "Link to this heading") * Use catalog’s default schema (#2310) * (go) Add tests for tables with dashes (#2312) * (go) Strip invalid characters from table and column names (#2314) * (go) Support JSON tags for nullable enum structs (#2121) #### Internal/config[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-config "Link to this heading") * Support golang overrides for slices (#2339) #### Kotlin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#kotlin "Link to this heading") * Use latest version of sqlc-gen-kotlin (#2356) #### Postgres[](https://docs.sqlc.dev/en/latest/reference/changelog.html#postgres "Link to this heading") * Column merging for table inheritence (#2315) #### Protos[](https://docs.sqlc.dev/en/latest/reference/changelog.html#protos "Link to this heading") * Add missing field name (#2354) #### Python[](https://docs.sqlc.dev/en/latest/reference/changelog.html#python "Link to this heading") * Use latest version of sqlc-gen-python (#2355) #### Remote[](https://docs.sqlc.dev/en/latest/reference/changelog.html#remote "Link to this heading") * Use user-id/password auth (#2262) #### Sqlite[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sqlite "Link to this heading") * Fixed sqlite column type override (#1986) [1.18.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.18.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id96 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-04-27 ### Release notes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id97 "Link to this heading") #### Remote code generation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#remote-code-generation "Link to this heading") _Developed by [@andrewmbenton](https://github.com/andrewmbenton) _ At its core, sqlc is powered by SQL engines, which include parsers, formatters, analyzers and more. While our goal is to support each engine on each operating system, it’s not always possible. For example, the PostgreSQL engine does not work on Windows. To bridge that gap, we’re announcing remote code generation, currently in private alpha. To join the private alpha, [sign up for the waitlist](https://docs.google.com/forms/d/e/1FAIpQLScDWrGtTgZWKt3mdlF5R2XCX6tL1pMkB4yuZx5yq684tTNN1Q/viewform?usp=sf_link) . Remote code generation works like local code generation, except the heavy lifting is performed in a consistent cloud environment. WASM-based plugins are supported in the remote environment, but process-based plugins are not. To configure remote generation, add a `cloud` block in `sqlc.json`. { "version": "2", "cloud": { "organization": "", "project": "", }, ... } You’ll also need to set the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\= When the `cloud` configuration block exists, `sqlc generate` will default to remote code generation. If you’d like to generate code locally without removing the `cloud` block from your config, pass the `--no-remote` option. sqlc generate \--no-remote Remote generation is off by default and requires an opt-in to use. #### sqlc.embed[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sqlc-embed "Link to this heading") _Developed by [@nickjackson](https://github.com/nickjackson) _ Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ) CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ) We want to select the student record and the highest score they got on a test. Here’s how we’d usually do that: \-- name: HighScore :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT students.\*, high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; When using Go, sqlc will produce a struct like this: type HighScoreRow struct { ID int64 Name sql.NullString Age sql.NullInt32 HighScore int32 } With embedding, the struct will contain a model for the table instead of a flattened list of columns. \-- name: HighScoreEmbed :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT sqlc.embed(students), high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; type HighScoreRow struct { Student Student HighScore int32 } #### sqlc.slice[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sqlc-slice "Link to this heading") _Developed by Paul Cameron and Jille Timmermans_ The MySQL Go driver does not support passing slices to the IN operator. The `sqlc.slice` function generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) func (q \*Queries) SelectStudents(ctx context.Context, ages \[\]int32) (\[\]Student, error) { This feature is only supported in MySQL and cannot be used with prepared queries. #### Batch operation improvements[](https://docs.sqlc.dev/en/latest/reference/changelog.html#batch-operation-improvements "Link to this heading") When using batches with pgx, the error returned when a batch is closed is exported by the generated package. This change allows for cleaner error handling using `errors.Is`. errors.Is(err, generated\_package.ErrBatchAlreadyClosed) Previously, you would have had to check match on the error message itself. err.Error() \== "batch already closed" The generated code for batch operations always lived in `batch.go`. This file name can now be configured via the `output_batch_file_name` configuration option. #### Configurable query parameter limits for Go[](https://docs.sqlc.dev/en/latest/reference/changelog.html#configurable-query-parameter-limits-for-go "Link to this heading") By default, sqlc will limit Go functions to a single parameter. If a query includes more than one parameter, the generated method will use an argument struct instead of positional arguments. This behavior can now be changed via the `query_parameter_limit` configuration option. If set to `0`, every genreated method will use a argument struct. ### Changes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id98 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id99 "Link to this heading") * Prevent variable redeclaration in single param conflict for pgx (#2058) * Retrieve Larg/Rarg join query after inner join (#2051) * Rename argument when conflicted to imported package (#2048) * Pgx closed batch return pointer if need #1959 (#1960) * Correct singularization of “waves” (#2194) * Honor Package level renames in v2 yaml config (#2001) * (mysql) Prevent UPDATE … JOIN panic #1590 (#2154) * Mysql delete join panic (#2197) * Missing import with pointer overrides, solves #2168 #2125 (#2217) #### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id100 "Link to this heading") * (config.md) Add `sqlite` as engine option (#2164) * Add first pass at pgx documentation (#2174) * Add missed configuration option (#2188) * `specifies parameter ":one" without containing a RETURNING clause` (#2173) #### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id101 "Link to this heading") * Add `sqlc.embed` to allow model re-use (#1615) * (Go) Add query\_parameter\_limit conf to codegen (#1558) * Add remote execution for codegen (#2214) #### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id102 "Link to this heading") * Skip tests if required plugins are missing (#2104) * Add tests for reanme fix in v2 (#2196) * Regenerate batch output for filename tests * Remove remote test (#2232) * Regenerate test output #### Bin/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#bin-sqlc "Link to this heading") * Add SQLCTMPDIR environment variable (#2189) #### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id103 "Link to this heading") * (deps) Bump github.com/antlr/antlr4/runtime/Go/antlr (#2109) * (deps) Bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 (#2119) * (deps) Bump golang from 1.20.1 to 1.20.2 (#2135) * (deps) Bump google.golang.org/protobuf from 1.28.1 to 1.29.0 (#2137) * (deps) Bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#2143) * (deps) Bump golang from 1.20.2 to 1.20.3 (#2192) * (deps) Bump actions/setup-go from 3 to 4 (#2150) * (deps) Bump google.golang.org/protobuf from 1.29.1 to 1.30.0 (#2151) * (deps) Bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#2193) * (deps) Bump github.com/lib/pq from 1.10.7 to 1.10.8 (#2211) * (deps) Bump github.com/lib/pq from 1.10.8 to 1.10.9 (#2229) * (deps) Bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 (#2228) #### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id104 "Link to this heading") * Remove –experimental flag (#2170) * Add option to disable process-based plugins (#2180) * Bump version to v1.18.0 #### Codegen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id105 "Link to this heading") * Correctly generate CopyFrom columns for single-column copyfroms (#2185) #### Config[](https://docs.sqlc.dev/en/latest/reference/changelog.html#config "Link to this heading") * Add top-level cloud configuration (#2204) #### Engine/postgres[](https://docs.sqlc.dev/en/latest/reference/changelog.html#engine-postgres "Link to this heading") * Upgrade to pg\_query\_go/v4 (#2114) #### Ext/wasm[](https://docs.sqlc.dev/en/latest/reference/changelog.html#ext-wasm "Link to this heading") * Check exit code on returned error (#2223) #### Parser[](https://docs.sqlc.dev/en/latest/reference/changelog.html#parser "Link to this heading") * Generate correct types for `SELECT NOT EXISTS` (#1972) #### Sqlite[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id106 "Link to this heading") * Add support for CREATE TABLE … STRICT (#2175) #### Wasm[](https://docs.sqlc.dev/en/latest/reference/changelog.html#wasm "Link to this heading") * Upgrade to wasmtime v8.0.0 (#2222) [1.17.2](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.2) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id107 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id108 "Link to this heading") * Fix build on Windows (#2102) [1.17.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.1) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id109 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id110 "Link to this heading") * Prefer to use \[\]T over pgype.Array\[T\] (#2090) * Revert changes to Dockerfile (#2091) * Do not throw error when IF NOT EXISTS is used on ADD COLUMN (#2092) ### MySQL[](https://docs.sqlc.dev/en/latest/reference/changelog.html#mysql "Link to this heading") * Add `float` support to MySQL (#2097) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id111 "Link to this heading") * (deps) Bump golang from 1.20.0 to 1.20.1 (#2082) [1.17.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id112 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-13 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id113 "Link to this heading") * Initialize generated code outside function (#1850) * (engine/mysql) Take into account column’s charset to distinguish text/blob, (var)char/(var)binary (#776) (#1895) * The enum Value method returns correct type (#1996) * Documentation for Inserting Rows (#2034) * Add import statements even if only pointer types exist (#2046) * Search from Rexpr if not found from Lexpr (#2056) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id114 "Link to this heading") * Change ENTRYPOINT to CMD (#1943) * Update samples for HOW-TO GUIDES (#1953) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id115 "Link to this heading") * Add the diff command (#1963) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id116 "Link to this heading") * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.15 to 1.14.16 (#1913) * (deps) Bump github.com/spf13/cobra from 1.6.0 to 1.6.1 (#1909) * Fix devcontainer (#1942) * Run sqlc-pg-gen via GitHub Actions (#1944) * Move large arrays out of functions (#1947) * Fix conflicts from pointer configuration (#1950) * (deps) Bump github.com/go-sql-driver/mysql from 1.6.0 to 1.7.0 (#1988) * (deps) Bump github.com/jackc/pgtype from 1.12.0 to 1.13.0 (#1978) * (deps) Bump golang from 1.19.3 to 1.19.4 (#1992) * (deps) Bump certifi from 2020.12.5 to 2022.12.7 in /docs (#1993) * (deps) Bump golang from 1.19.4 to 1.19.5 (#2016) * (deps) Bump golang from 1.19.5 to 1.20.0 (#2045) * (deps) Bump github.com/jackc/pgtype from 1.13.0 to 1.14.0 (#2062) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.0 (#2063) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#cmd "Link to this heading") * Generate packages in parallel (#2026) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id117 "Link to this heading") * Bump version to v1.17.0 ### Codegen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id118 "Link to this heading") * Remove built-in Kotlin support (#1935) * Remove built-in Python support (#1936) ### Internal/codegen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-codegen "Link to this heading") * Cache pattern matching compilations (#2028) ### Mysql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id119 "Link to this heading") * Add datatype tests (#1948) * Fix blob tests (#1949) ### Plugins[](https://docs.sqlc.dev/en/latest/reference/changelog.html#plugins "Link to this heading") * Upgrade to wasmtime 3.0.1 (#2009) ### Sqlite[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id120 "Link to this heading") * Supported between expr (#1958) (#1967) ### Tools[](https://docs.sqlc.dev/en/latest/reference/changelog.html#tools "Link to this heading") * Regenerate scripts skips dirs that contains diff exec command (#1987) ### Wasm[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id121 "Link to this heading") * Upgrade to wasmtime 5.0.0 (#2065) [1.16.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.16.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id122 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-11-09 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id123 "Link to this heading") * (validate) Sqlc.arg & sqlc.narg are not “missing” (#1814) * Emit correct comment for nullable enums (#1819) * 🐛 Correctly switch `coalesce()` result `.NotNull` value (#1664) * Prevent batch infinite loop with arg length (#1794) * Support version 2 in error message (#1839) * Handle empty column list in postgresql (#1843) * Batch imports filter queries, update cmds having ret type (#1842) * Named params contribute to batch parameter count (#1841) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id124 "Link to this heading") * Add a getting started guide for SQLite (#1798) * Various readability improvements (#1854) * Add documentation for codegen plugins (#1904) * Update migration guides with links (#1933) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id125 "Link to this heading") * Add HAVING support to MySQL (#1806) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id126 "Link to this heading") * Upgrade wasmtime version (#1827) * Bump wasmtime version to v1.0.0 (#1869) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id127 "Link to this heading") * (deps) Bump github.com/jackc/pgconn from 1.12.1 to 1.13.0 (#1785) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.13 to 1.14.15 (#1799) * (deps) Bump github.com/jackc/pgx/v4 from 4.16.1 to 4.17.0 (#1786) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.0 to 4.17.1 (#1825) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1826) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.1 to 4.17.2 (#1831) * (deps) Bump golang from 1.19.0 to 1.19.1 (#1834) * (deps) Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#1838) * (deps) Bump github.com/lib/pq from 1.10.6 to 1.10.7 (#1835) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1857) * (deps) Bump github.com/spf13/cobra from 1.5.0 to 1.6.0 (#1893) * (deps) Bump golang from 1.19.1 to 1.19.3 (#1920) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id128 "Link to this heading") * Bump to v1.16.0 ### Codgen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#codgen "Link to this heading") * Include serialized codegen options (#1890) ### Compiler[](https://docs.sqlc.dev/en/latest/reference/changelog.html#compiler "Link to this heading") * Move Kotlin parameter logic into codegen (#1910) ### Examples[](https://docs.sqlc.dev/en/latest/reference/changelog.html#examples "Link to this heading") * Port Python examples to WASM plugin (#1903) ### Pg-gen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#pg-gen "Link to this heading") * Make sqlc-pg-gen the complete source of truth for pg\_catalog.go (#1809) * Implement information\_schema shema (#1815) ### Python[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id129 "Link to this heading") * Port all Python tests to sqlc-gen-python (#1907) * Upgrade to sqlc-gen-python v1.0.0 (#1932) [1.15.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.15.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id130 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-08-07 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id131 "Link to this heading") * (mysql) Typo (#1700) * (postgresql) Add quotes for CamelCase columns (#1729) * Cannot parse SQLite upsert statement (#1732) * (sqlite) Regenerate test output for builtins (#1735) * (wasm) Version modules by wasmtime version (#1734) * Missing imports (#1637) * Missing slice import for querier (#1773) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id132 "Link to this heading") * Add process-based plugin docs (#1669) * Add links to downloads.sqlc.dev (#1681) * Update transactions how to example (#1775) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id133 "Link to this heading") * More SQL Syntax Support for SQLite (#1687) * (sqlite) Promote SQLite support to beta (#1699) * Codegen plugins, powered by WASM (#1684) * Set user-agent for plugin downloads (#1707) * Null enums types (#1485) * (sqlite) Support stdlib functions (#1712) * (sqlite) Add support for returning (#1741) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id134 "Link to this heading") * Add tests for quoting columns (#1733) * Remove catalog tests (#1762) ### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id135 "Link to this heading") * Add tests for fixing slice imports (#1736) * Add test cases for returning (#1737) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id136 "Link to this heading") * Upgrade to Go 1.19 (#1780) * Upgrade to go-wasmtime 0.39.0 (#1781) ### Plugins[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id137 "Link to this heading") * (wasm) Change default cache location (#1709) * (wasm) Change the SHA-256 config key (#1710) [1.14.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.14.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id138 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-06-09 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id139 "Link to this heading") * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) * (compiler) Fix left join nullability with table aliases (#1491) * Regenerate testdata for CREATE TABLE AS (#1516) * (bundler) Only close multipart writer once (#1528) * (endtoend) Regenerate testdata for exex\_lastid * (pgx) Copyfrom imports (#1626) * Validate sqlc function arguments (#1633) * Fixed typo `sql.narg` in doc (#1668) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id140 "Link to this heading") * (golang) Add Enum.Valid and AllEnumValues (#1613) * (sqlite) Start expanding support (#1410) * (pgx) Add support for batch operations (#1437) * (sqlite) Add support for delete statements (#1447) * (codegen) Insert comments in interfaces (#1458) * (sdk) Add the plugin SDK package (#1463) * Upload projects (#1436) * Add sqlc version to generated Kotlin code (#1512) * Add sqlc version to generated Go code (#1513) * Pass sqlc version in codegen request (#1514) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * Run sqlc with docker on windows cmd (#1557) * Add JSON “codegen” output (#1565) * Add sqlc.narg() for nullable named params (#1536) * Process-based codegen plugins (#1578) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id141 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id142 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) * (sql/catalog) Improve Readability (#1595) * Add basic fuzzing for config / overrides (#1500) [1.13.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.13.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id143 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-03-31 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id144 "Link to this heading") * (compiler) Fix left join nullability with table aliases (#1491) * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id145 "Link to this heading") * (cli) Upload projects (#1436) * (codegen) Add sqlc version to generated Go code (#1513) * (codegen) Add sqlc version to generated Kotlin code (#1512) * (codegen) Insert comments in interfaces (#1458) * (codegen) Pass sqlc version in codegen request (#1514) * (pgx) Add support for batch operations (#1437) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * (sdk) Add the plugin SDK package (#1463) * (sqlite) Add support for delete statements (#1447) * (sqlite) Start expanding support (#1410) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id146 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id147 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) ### Config[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id148 "Link to this heading") * Add basic fuzzing for config / overrides (#1500) [1.12.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.12.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id149 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-02-05 ### Bug[](https://docs.sqlc.dev/en/latest/reference/changelog.html#bug "Link to this heading") * ALTER TABLE SET SCHEMA (#1409) ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id150 "Link to this heading") * Update ANTLR v4 go.mod entry (#1336) * Check delete statements for CTEs (#1329) * Fix validation of GROUP BY on field aliases (#1348) * Fix imports when non-copyfrom queries needed imports that copyfrom queries didn’t (#1386) * Remove extra comment newline (#1395) * Enable strict function checking (#1405) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id151 "Link to this heading") * Bump version to 1.11.0 (#1308) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id152 "Link to this heading") * Inheritance (#1339) * Generate query code using ASTs instead of templates (#1338) * Add support for CREATE TABLE a ( LIKE b ) (#1355) * Add support for sql.NullInt16 (#1376) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id153 "Link to this heading") * Add tests for :exec{result,rows} (#1344) * Delete template-based codegen (#1345) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id154 "Link to this heading") * Bump github.com/jackc/pgx/v4 from 4.14.0 to 4.14.1 (#1316) * Bump golang from 1.17.3 to 1.17.4 (#1331) * Bump golang from 1.17.4 to 1.17.5 (#1337) * Bump github.com/spf13/cobra from 1.2.1 to 1.3.0 (#1343) * Remove devel Docker build * Bump golang from 1.17.5 to 1.17.6 (#1369) * Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 (#1382) * Format all Go code (#1387) [1.11.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.11.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id155 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-11-24 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id156 "Link to this heading") * Update incorrect signatures (#1180) * Correct aggregate func sig (#1182) * Jsonb\_build\_object (#1211) * Case-insensitive identifiers (#1216) * Incorrect handling of meta (#1228) * Detect invalid INSERT expression (#1231) * Respect alias name for coalesce (#1232) * Mark nullable when casting NULL (#1233) * Support nullable fields in joins for MySQL engine (#1249) * Fix between expression handling of table references (#1268) * Support nullable fields in joins on same table (#1270) * Fix missing binds in ORDER BY (#1273) * Set RV for TargetList items on updates (#1252) * Fix MySQL parser for query without trailing semicolon (#1282) * Validate table alias references (#1283) * Add support for MySQL ON DUPLICATE KEY UPDATE (#1286) * Support references to columns in joined tables in UPDATE statements (#1289) * Add validation for GROUP BY clause column references (#1285) * Prevent variable redeclaration in single param conflict (#1298) * Use common params struct field for same named params (#1296) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id157 "Link to this heading") * Replace deprecated go get with go install (#1181) * Fix package name referenced in tutorial (#1202) * Add environment variables (#1264) * Add go.17+ install instructions (#1280) * Warn about golang-migrate file order (#1302) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id158 "Link to this heading") * Instrument compiler via runtime/trace (#1258) * Add MySQL support for BETWEEN arguments (#1265) ### Refactor[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id159 "Link to this heading") * Move from io/ioutil to io and os package (#1164) ### Styling[](https://docs.sqlc.dev/en/latest/reference/changelog.html#styling "Link to this heading") * Apply gofmt to sample code (#1261) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id160 "Link to this heading") * Bump golang from 1.17.0 to 1.17.1 (#1173) * Bump eskatos/gradle-command-action from 1 to 2 (#1220) * Bump golang from 1.17.1 to 1.17.2 (#1227) * Bump github.com/pganalyze/pg\_query\_go/v2 (#1234) * Bump actions/checkout from 2.3.4 to 2.3.5 (#1238) * Bump babel from 2.9.0 to 2.9.1 in /docs (#1245) * Bump golang from 1.17.2 to 1.17.3 (#1272) * Bump actions/checkout from 2.3.5 to 2.4.0 (#1267) * Bump github.com/lib/pq from 1.10.3 to 1.10.4 (#1278) * Bump github.com/jackc/pgx/v4 from 4.13.0 to 4.14.0 (#1303) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id161 "Link to this heading") * Bump version to v1.11.0 [1.10.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.10.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id162 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-09-07 ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id163 "Link to this heading") * Fix invalid language support table (#1161) * Add a getting started guide for MySQL (#1163) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id164 "Link to this heading") * Bump golang from 1.16.7 to 1.17.0 (#1129) * Bump github.com/lib/pq from 1.10.2 to 1.10.3 (#1160) ### Ci[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id165 "Link to this heading") * Upgrade Go to 1.17 (#1130) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id166 "Link to this heading") * Bump version to v1.10.0 (#1165) ### Codegen/golang[](https://docs.sqlc.dev/en/latest/reference/changelog.html#codegen-golang "Link to this heading") * Consolidate import logic (#1139) * Add pgx support for range types (#1146) * Use pgtype for hstore when using pgx (#1156) ### Codgen/golang[](https://docs.sqlc.dev/en/latest/reference/changelog.html#codgen-golang "Link to this heading") * Use p\[gq\]type for network address types (#1142) ### Endtoend[](https://docs.sqlc.dev/en/latest/reference/changelog.html#endtoend "Link to this heading") * Run `go test` in CI (#1134) ### Engine/mysql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#engine-mysql "Link to this heading") * Add support for LIKE (#1162) ### Golang[](https://docs.sqlc.dev/en/latest/reference/changelog.html#golang "Link to this heading") * Output NullUUID when necessary (#1137) [1.9.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.9.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id167 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-08-13 ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id168 "Link to this heading") * Update documentation (a bit) for v1.9.0 (#1117) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id169 "Link to this heading") * Bump golang from 1.16.6 to 1.16.7 (#1107) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id170 "Link to this heading") * Bump version to v1.9.0 (#1121) ### Compiler[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id171 "Link to this heading") * Add tests for COALESCE behavior (#1112) * Handle subqueries in SELECT statements (#1113) [1.8.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.8.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id172 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-05-03 ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id173 "Link to this heading") * Add language support Matrix (#920) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id174 "Link to this heading") * Add case style config option (#905) ### Python[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id175 "Link to this heading") * Eliminate runtime package and use sqlalchemy (#939) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id176 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.4 to 0.5.5 (#926) * Bump github.com/lib/pq from 1.9.0 to 1.10.0 (#931) * Bump golang from 1.16.0 to 1.16.1 (#935) * Bump golang from 1.16.1 to 1.16.2 (#942) * Bump github.com/jackc/pgx/v4 from 4.10.1 to 4.11.0 (#956) * Bump github.com/go-sql-driver/mysql from 1.5.0 to 1.6.0 (#961) * Bump github.com/pganalyze/pg\_query\_go/v2 (#965) * Bump urllib3 from 1.26.3 to 1.26.4 in /docs (#968) * Bump golang from 1.16.2 to 1.16.3 (#963) * Bump github.com/lib/pq from 1.10.0 to 1.10.1 (#980) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id177 "Link to this heading") * Add the –experimental flag (#929) * Fix sqlc init (#959) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id178 "Link to this heading") * Bump version to v1.7.1-devel (#913) * Bump version to v1.8.0 ### Codegen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id179 "Link to this heading") * Generate valid enum names for symbols (#972) ### Postgresql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#postgresql "Link to this heading") * Support generated columns * Add test for PRIMARY KEY INCLUDE * Add tests for CREATE TABLE PARTITION OF * CREATE TRIGGER EXECUTE FUNCTION * Add support for renaming types (#971) ### Sql/ast[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sql-ast "Link to this heading") * Resolve return values from functions (#964) ### Workflows[](https://docs.sqlc.dev/en/latest/reference/changelog.html#workflows "Link to this heading") * Only run tests once (#924) [1.7.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.7.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id180 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-02-28 ### Bug Fixes[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id181 "Link to this heading") * Struct tag formatting (#833) ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id182 "Link to this heading") * Include all the existing Markdown files (#877) * Split docs into four sections (#882) * Reorganize and consolidate documentation * Add link to Windows download (#888) * Shorten the README (#889) ### Features[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id183 "Link to this heading") * Adding support for pgx/v4 * Adding support for pgx/v4 ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#readme "Link to this heading") * Add Go Report Card badge (#891) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id184 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.3 to 0.5.4 (#813) * Bump github.com/lib/pq from 1.8.0 to 1.9.0 (#820) * Bump golang from 1.15.5 to 1.15.6 (#822) * Bump github.com/jackc/pgx/v4 from 4.9.2 to 4.10.0 (#823) * Bump github.com/jackc/pgx/v4 from 4.10.0 to 4.10.1 (#839) * Bump golang from 1.15.6 to 1.15.7 (#855) * Bump golang from 1.15.7 to 1.15.8 (#881) * Bump github.com/spf13/cobra from 1.1.1 to 1.1.2 (#892) * Bump golang from 1.15.8 to 1.16.0 (#897) * Bump github.com/lfittl/pg\_query\_go from 1.0.1 to 1.0.2 (#901) * Bump github.com/spf13/cobra from 1.1.2 to 1.1.3 (#893) ### Catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#catalog "Link to this heading") * Improve alter column type (#818) ### Ci[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id185 "Link to this heading") * Uprade to Go 1.15 (#887) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id186 "Link to this heading") * Allow config file location to be specified (#863) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id187 "Link to this heading") * Bump to version v1.6.1-devel (#807) * Bump version to v1.7.0 (#912) ### Codegen/golang[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id188 "Link to this heading") * Make sure to import net package (#858) ### Compiler[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id189 "Link to this heading") * Support UNION query ### Dolphin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#dolphin "Link to this heading") * Generate bools for tinyint(1) * Support joins in update statements (#883) * Add support for union query ### Endtoend[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id190 "Link to this heading") * Add tests for INTERSECT and EXCEPT ### Go.mod[](https://docs.sqlc.dev/en/latest/reference/changelog.html#go-mod "Link to this heading") * Update to go 1.15 and run ‘go mod tidy’ (#808) ### Mysql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id191 "Link to this heading") * Compile tinyint(1) to bool (#873) ### Sql/ast[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id192 "Link to this heading") * Add enum values for SetOperation [1.6.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.6.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id193 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-11-23 ### Dolphin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id194 "Link to this heading") * Implement Rename (#651) * Skip processing view drops (#653) ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id195 "Link to this heading") * Update language / database support (#698) ### Astutils[](https://docs.sqlc.dev/en/latest/reference/changelog.html#astutils "Link to this heading") * Fix Params rewrite call (#674) ### Build[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id196 "Link to this heading") * Bump golang from 1.14 to 1.15.3 (#765) * Bump docker/build-push-action from v1 to v2.1.0 (#764) * Bump github.com/google/go-cmp from 0.4.0 to 0.5.2 (#766) * Bump github.com/spf13/cobra from 1.0.0 to 1.1.1 (#767) * Bump github.com/jackc/pgx/v4 from 4.6.0 to 4.9.2 (#768) * Bump github.com/lfittl/pg\_query\_go from 1.0.0 to 1.0.1 (#773) * Bump github.com/google/go-cmp from 0.5.2 to 0.5.3 (#783) * Bump golang from 1.15.3 to 1.15.5 (#782) * Bump github.com/lib/pq from 1.4.0 to 1.8.0 (#769) ### Catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id197 "Link to this heading") * Improve variadic argument support (#804) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id198 "Link to this heading") * Bump to version v1.6.0 (#806) ### Codegen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id199 "Link to this heading") * Fix errant database/sql imports (#789) ### Compiler[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id200 "Link to this heading") * Use engine-specific reserved keywords (#677) ### Dolphi[](https://docs.sqlc.dev/en/latest/reference/changelog.html#dolphi "Link to this heading") * Add list of builtin functions (#795) ### Dolphin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id201 "Link to this heading") * Update to the latest MySQL parser (#665) * Add ENUM() support (#676) * Add test for table aliasing (#684) * Add MySQL ddl\_create\_table test (#685) * Implete TRUNCATE table (#697) * Represent tinyint as int32 (#797) * Add support for coalesce (#802) * Add function signatures (#796) ### Endtoend[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id202 "Link to this heading") * Add MySQL json test (#692) * Add MySQL update set multiple test (#696) ### Examples[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id203 "Link to this heading") * Use generated enum constants in db\_test (#678) * Port ondeck to MySQL (#680) * Add MySQL authors example (#682) ### Internal/cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-cmd "Link to this heading") * Print correct config file on parse failure (#749) ### Kotlin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id204 "Link to this heading") * Remove runtime dependency (#774) ### Metadata[](https://docs.sqlc.dev/en/latest/reference/changelog.html#metadata "Link to this heading") * Support multiple comment prefixes (#683) ### Postgresql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id205 "Link to this heading") * Support string concat operator (#701) ### Sql/catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sql-catalog "Link to this heading") * Add support for variadic functions (#798) [1.5.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.5.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id206 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-08-05 ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id207 "Link to this heading") * Build sqlc using Go 1.14 (#549) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id208 "Link to this heading") * Add debugging support (#573) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id209 "Link to this heading") * Bump version to v1.4.1-devel (#548) * Bump version to v1.5.0 ### Compiler[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id210 "Link to this heading") * Support calling functions with defaults (#635) * Skip func args without a paramRef (#636) * Return a single column from coalesce (#639) ### Config[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id211 "Link to this heading") * Add emit\_empty\_slices to version one (#552) ### Contrib[](https://docs.sqlc.dev/en/latest/reference/changelog.html#contrib "Link to this heading") * Add generated code for contrib ### Dinosql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#dinosql "Link to this heading") * Remove deprecated package (#554) ### Dolphin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id212 "Link to this heading") * Add support for column aliasing (#566) * Implement star expansion for subqueries (#619) * Implement exapansion with reserved words (#620) * Implement parameter refs (#621) * Implement limit and offest (#622) * Implement inserts (#623) * Implement delete (#624) * Implement simple update statements (#625) * Implement INSERT … SELECT (#626) * Use test driver instead of TiDB driver (#629) * Implement named parameters via sqlc.arg() (#632) ### Endtoend[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id213 "Link to this heading") * Add MySQL test for SELECT \* JOIN (#565) * Add MySQL test for inflection (#567) ### Engine[](https://docs.sqlc.dev/en/latest/reference/changelog.html#engine "Link to this heading") * Create engine package (#556) ### Equinox[](https://docs.sqlc.dev/en/latest/reference/changelog.html#equinox "Link to this heading") * Use the new equinox-io/setup action (#586) ### Examples[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id214 "Link to this heading") * Run tests for MySQL booktest (#627) ### Golang[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id215 "Link to this heading") * Add support for the money type (#561) * Generate correct types for int2 and int8 (#579) ### Internal[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal "Link to this heading") * Rm catalog, pg, postgres packages (#555) ### Mod[](https://docs.sqlc.dev/en/latest/reference/changelog.html#mod "Link to this heading") * Downgrade TiDB package to fix build (#603) ### Mysql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id216 "Link to this heading") * Upgrade to the latest vitess commit (#562) * Support to infer type of a duplicated arg (#615) * Allow some builtin functions to be nullable (#616) ### Postgresql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id217 "Link to this heading") * Generate all functions in pg\_catalog (#550) * Remove pg\_catalog schema from tests (#638) * Move contrib code to a package ### Sql/catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id218 "Link to this heading") * Fix comparison of pg\_catalog types (#637) ### Tools[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id219 "Link to this heading") * Generate functions for all of contrib ### Workflow[](https://docs.sqlc.dev/en/latest/reference/changelog.html#workflow "Link to this heading") * Migrate to equinox-io/setup-release-tool (#614) [1.4.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.4.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id220 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-06-17 ### Dockerfile[](https://docs.sqlc.dev/en/latest/reference/changelog.html#dockerfile "Link to this heading") * Add version build argument (#487) ### MySQL[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id221 "Link to this heading") * Prevent Panic when WHERE clause contains parenthesis. (#531) ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id222 "Link to this heading") * Document emit\_exact\_table\_names (#486) ### All[](https://docs.sqlc.dev/en/latest/reference/changelog.html#all "Link to this heading") * Remove the exp build tag (#507) ### Catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id223 "Link to this heading") * Support functions with table parameters (#541) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id224 "Link to this heading") * Bump to version 1.3.1-devel (#485) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id225 "Link to this heading") * Bump version to v1.4.0 (#547) ### Codegen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id226 "Link to this heading") * Add the new codegen packages (#513) * Add the :execresult query annotation (#542) ### Compiler[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id227 "Link to this heading") * Validate function calls (#505) * Port bottom of parseQuery (#510) * Don’t mutate table name (#517) * Enable experimental parser by default (#518) * Apply rename rules to enum constants (#523) * Temp fix for typecast function parameters (#530) ### Endtoend[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id228 "Link to this heading") * Standardize JSON formatting (#490) * Add per-test configuration files (#521) * Read expected stderr failures from disk (#527) ### Internal/dinosql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-dinosql "Link to this heading") * Check parameter style before ref (#488) * Remove unneeded column suffix (#492) * Support named function arguments (#494) ### Internal/postgresql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-postgresql "Link to this heading") * Fix NamedArgExpr rewrite (#491) ### Multierr[](https://docs.sqlc.dev/en/latest/reference/changelog.html#multierr "Link to this heading") * Move dinosql.ParserErr to a new package (#496) ### Named[](https://docs.sqlc.dev/en/latest/reference/changelog.html#named "Link to this heading") * Port parameter style validation to SQL (#504) ### Parser[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id229 "Link to this heading") * Support columns from subselect statements (#489) ### Rewrite[](https://docs.sqlc.dev/en/latest/reference/changelog.html#rewrite "Link to this heading") * Move parameter rewrite to package (#499) ### Sqlite[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id230 "Link to this heading") * Use convert functions instead of the listener (#519) ### Sqlpath[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sqlpath "Link to this heading") * Move ReadSQLFiles into a separate package (#495) ### Validation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#validation "Link to this heading") * Move query validation to separate package (#498) [1.3.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.3.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id231 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-05-12 ### Makefile[](https://docs.sqlc.dev/en/latest/reference/changelog.html#makefile "Link to this heading") * Update target (#449) ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id232 "Link to this heading") * Add Myles as a sponsor (#469) ### Testing[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id233 "Link to this heading") * Make sure all Go examples build (#480) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id234 "Link to this heading") * Bump version to v1.3.0 (#484) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id235 "Link to this heading") * Bump version to v1.2.1-devel (#442) ### Dinosql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id236 "Link to this heading") * Inline addFile (#446) * Add PostgreSQL support for TRUNCATE (#448) ### Gen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#gen "Link to this heading") * Emit json.RawMessage for JSON columns (#461) ### Go.mod[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id237 "Link to this heading") * Use latest lib/pq (#471) ### Parser[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id238 "Link to this heading") * Use same function to load SQL files (#483) ### Postgresql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id239 "Link to this heading") * Fix panic walking CreateTableAsStmt (#475) [1.2.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.2.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id240 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-04-07 ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id241 "Link to this heading") * Publish to Docker Hub (#422) ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id242 "Link to this heading") * Docker installation docs (#424) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id243 "Link to this heading") * Bump version to v1.1.1-devel (#407) * Bump version to v1.2.0 (#441) ### Gen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id244 "Link to this heading") * Add special case for “campus” (#435) * Properly quote reserved keywords on expansion (#436) ### Migrations[](https://docs.sqlc.dev/en/latest/reference/changelog.html#migrations "Link to this heading") * Move migration parsing to new package (#427) ### Parser[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id245 "Link to this heading") * Generate correct types for SELECT EXISTS (#411) [1.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.1.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id246 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-03-17 ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id247 "Link to this heading") * Add installation instructions (#350) * Add section on running tests (#357) * Fix typo (#371) ### Ast[](https://docs.sqlc.dev/en/latest/reference/changelog.html#ast "Link to this heading") * Add AST for ALTER TABLE ADD / DROP COLUMN (#376) * Add support for CREATE TYPE as ENUM (#388) * Add support for CREATE / DROP SCHEMA (#389) ### Astutils[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id248 "Link to this heading") * Apply changes to the ValuesList slice (#372) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id249 "Link to this heading") * Return v1.0.0 (#348) * Return next bug fix version (#349) ### Cmd/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id250 "Link to this heading") * Bump version to v1.1.0 (#406) ### Compiler[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id251 "Link to this heading") * Wire up the experimental parsers ### Config[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id252 "Link to this heading") * Remove “emit\_single\_file” option (#367) ### Dolphin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id253 "Link to this heading") * Add experimental parser for MySQL ### Gen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id254 "Link to this heading") * Add option to emit single file for Go (#366) * Add support for the ltree extension (#385) ### Go.mod[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id255 "Link to this heading") * Add packages for MySQL and SQLite parsers ### Internal/dinosql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id256 "Link to this heading") * Support Postgres macaddr type in Go (#358) ### Internal/endtoend[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-endtoend "Link to this heading") * Remove %w (#354) ### Kotlin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id257 "Link to this heading") * Add Query class to support timeout and cancellation (#368) ### Postgresql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id258 "Link to this heading") * Add experimental parser for MySQL ### Sql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sql "Link to this heading") * Add generic SQL AST ### Sql/ast[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id259 "Link to this heading") * Port support for COMMENT ON (#391) * Implement DROP TYPE (#397) * Implement ALTER TABLE RENAME (#398) * Implement ALTER TABLE RENAME column (#399) * Implement ALTER TABLE SET SCHEMA (#400) ### Sql/catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id260 "Link to this heading") * Port tests over from catalog pkg (#402) ### Sql/errors[](https://docs.sqlc.dev/en/latest/reference/changelog.html#sql-errors "Link to this heading") * Add a new errors package (#390) ### Sqlite[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id261 "Link to this heading") * Add experimental parser for SQLite [1.0.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.0.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id262 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-02-18 ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id263 "Link to this heading") * Add documentation for query commands (#270) * Add named parameter documentation (#332) ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id264 "Link to this heading") * Add sponsors section (#333) ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id265 "Link to this heading") * Remove parse subcommand (#322) ### Config[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id266 "Link to this heading") * Parse V2 config format * Add support for YAML (#336) ### Examples[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id267 "Link to this heading") * Add the jets and booktest examples (#237) * Move sqlc.json into examples folder (#238) * Add the authors example (#241) * Add build tag to authors tests (#319) ### Internal[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id268 "Link to this heading") * Allow CTE to be used with UPDATE (#268) * Remove the PackageMap from settings (#295) ### Internal/config[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id269 "Link to this heading") * Create new config package (#313) ### Internal/dinosql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id270 "Link to this heading") * Emit Querier interface (#240) * Strip leading “go-” or trailing “-go” from import (#262) * Overrides can now be basic types (#271) * Import needed types for Querier (#285) * Handle schema-scoped enums (#310) * Ignore golang-migrate rollbacks (#320) ### Internal/endtoend[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id271 "Link to this heading") * Move more tests to the record/replay framework * Add update test for named params (#329) ### Internal/mysql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-mysql "Link to this heading") * Fix flaky test (#242) * Port tests to endtoend package (#315) ### Internal/parser[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-parser "Link to this heading") * Resolve nested CTEs (#324) * Error if last query is missing (#325) * Support joins with aliases (#326) * Remove print statement (#327) ### Internal/sqlc[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-sqlc "Link to this heading") * Add support for composite types (#311) ### Kotlin[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id272 "Link to this heading") * Support primitives * Arrays, enums, and dates * Generate examples * README for examples * Factor out db setup extension * Fix enums, use List instead of Array * Port Go tests for examples * Rewrite numbered params to positional params * Always use use, fix indents * Unbox query params ### Parser[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id273 "Link to this heading") * Attach range vars to insert params * Attach range vars to insert params (#342) * Remove dead code (#343) [0.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v0.1.0) [](https://docs.sqlc.dev/en/latest/reference/changelog.html#id274 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-01-07 ### Documentation[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id275 "Link to this heading") * Replace remaining references to DinoSQL with sqlc (#149) ### README[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id276 "Link to this heading") * Fix download links (#66) * Add LIMIT 1 to query that should return one (#99) ### Catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id277 "Link to this heading") * Support “ALTER TABLE … DROP CONSTRAINT …” (#34) * Differentiate functions with different argument types (#51) ### Ci[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id278 "Link to this heading") * Enable tests on pull requests ### Cmd[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id279 "Link to this heading") * Include filenames in error messages (#69) * Do not output any changes on error (#72) ### Dinosql/internal[](https://docs.sqlc.dev/en/latest/reference/changelog.html#dinosql-internal "Link to this heading") * Add lower and upper functions (#215) * Ignore alter sequence commands (#219) ### Gen[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id280 "Link to this heading") * Add DO NOT EDIT comments to generated code (#50) * Include all schemas when generating models (#90) * Prefix structs with schema name (#91) * Generate single import for uuid package (#98) * Use same import logic for all Go files * Pick correct struct to return for queries (#107) * Create consistent JSON tags (#110) * Add Close method to Queries struct (#127) * Ignore empty override settings (#128) * Turn SQL comments into Go comments (#136) ### Internal/catalog[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-catalog "Link to this heading") * Parse unnamed function arguments (#166) ### Internal/dinosql[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id281 "Link to this heading") * Prepare() with no GoQueries still valid (#95) * Fix multiline comment rendering (#142) * Dereference alias nodes on walk (#158) * Ignore sql-migrate rollbacks (#160) * Sort imported packages (#165) * Add support for timestamptz (#169) * Error on missing queries (#180) * Use more database/sql null types (#182) * Support the pg\_temp schema (#183) * Override columns with array type (#184) * Implement robust expansion * Implement robust expansion (#186) * Add COMMENT ON support (#191) * Add DATE support * Add DATE support (#196) * Filter out invalid characters (#198) * Quote reserved keywords (#205) * Return parser errors first (#207) * Implement advisory locks (#212) * Error on duplicate query names (#221) * Fix incorrect enum names (#223) * Add support for numeric types * Add support for numeric types (#228) ### Internal/dinosql/testdata/ondeck[](https://docs.sqlc.dev/en/latest/reference/changelog.html#internal-dinosql-testdata-ondeck "Link to this heading") * Add Makefile (#156) ### Ondeck[](https://docs.sqlc.dev/en/latest/reference/changelog.html#ondeck "Link to this heading") * Move all tests to GitHub CI (#58) ### ParseQuery[](https://docs.sqlc.dev/en/latest/reference/changelog.html#parsequery "Link to this heading") * Return either a query or an error (#178) ### Parser[](https://docs.sqlc.dev/en/latest/reference/changelog.html#id282 "Link to this heading") * Use schema when resolving catalog refs (#82) * Support function calls in expressions (#104) * Correctly handle single files (#119) * Return error if missing RETURNING (#131) * Add support for mathmatical operators (#132) * Add support for simple case expressions (#134) * Error on mismatched INSERT input (#135) * Set IsArray on joined columns (#139) ### Pg[](https://docs.sqlc.dev/en/latest/reference/changelog.html#pg "Link to this heading") * Store functions in the catalog (#41) * Add location to errors (#73) --- # Changelog — sqlc 1.30.0 documentation * [](https://docs.sqlc.dev/en/v1.30.0/index.html) * Changelog * [View page source](https://docs.sqlc.dev/en/v1.30.0/_sources/reference/changelog.md.txt) * * * Changelog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#changelog "Link to this heading") ========================================================================================================= All notable changes to this project will be documented in this file. [1.30.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.30.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-30-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-09-01 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#bug-fixes "Link to this heading") * (compiler/mysql) Prevent panic in convertSetOprSelectList() (#4042) * Range subselect alias pointer dereference (#3711) * (codegen/golang) Don’t omit enums used as arrays (#4058) * (codegen/golang) Handle `go_struct_tag` for `db_type` overrides (#4055) * (engine/dolphin) Remove references to deprecated `pcast.ChangeStmt` (#4057) * Normalize identifier usage for table names (#4045) * (engine/sqlite) Fix parsing of INSERT DEFAULT VALUES syntax (#4010) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#documentation "Link to this heading") * Fix parameter syntax inconsistency for MySQL and SQLite (#4036) * Use correct configuration to generate the given output for JSON type override (#4049) * Clean up and add to docs regarding type overrides (#4060) * Try a different admonition format (#4061) * Use the correct admonition format (#4062) * Add multi-worded table example for renaming (#4067) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#features "Link to this heading") * (docs) Add link to Gleam/parrot (#4038) * (engine/dolphin) Implement MATCH\_AGAINST conversion in SQL AST (#1192, #3091) (#4070) * (engine/sqlite) Coerce jsonb columns to json before returning to Go code (#3968) ### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#testing "Link to this heading") * (endtoend) Skip process\_plugin\_sqlc\_gen\_json (#4075) * (endtoend) Use Docker to start database servers (#4076) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#build "Link to this heading") * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3941) * (deps) Bump packaging (#3940) * (deps) Bump golang from 1.24.2 to 1.24.4 (#3983) * (deps) Bump golang from 1.24.4 to 1.24.5 (#4014) * (deps) Bump urllib3 from 2.4.0 to 2.5.0 in /docs (#3994) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3989) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4027) * (deps) Bump modernc.org/sqlite (#4032) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4018) * (deps) Bump certifi in /docs in the production-dependencies group (#4041) * (deps) Bump google.golang.org/protobuf (#4043) * (deps) Bump actions/checkout from 4 to 5 (#4059) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#4071) * (deps) Bump requests in /docs in the production-dependencies group (#4068) * Upgrade to Go 1.25 (#4074) * (deps) Bump golang from 1.24.5 to 1.25.0 (#4063) * (deps) Bump github.com/google/cel-go (#4080) [1.29.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.29.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-29-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-04-14 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id3 "Link to this heading") * (docs) Correct spelling and grammar (#3645) * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) * (pgx) Do not wrap nil error (#3913) * (migrations) Normalize case for migration statement for all cases (#3919) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id4 "Link to this heading") * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Add changelog for 1.28.0 (#3797) * Add PHP DBAL plugin (#3813) * Fix PostGIS function name (#3829) * Add Zig plugin (#3824) * Add link to tandemdude/sqlc-gen-java (#3819) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id5 "Link to this heading") * (docs) How-to use transactions with pgx (#3557) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) * (mysql) Add a test for VECTOR column type (#3734) * (cli) Bump version from 1.27.0 to 1.28.0 (#3798) * (codegen/golang) Add an option to wrap query errors that includes query name (#3876) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#miscellaneous-tasks "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) * Update sqlc-gen-java supported engines (#3843) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id6 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) * (deps) Bump golang.org/x/net from 0.30.0 to 0.33.0 (#3796) * (deps) Bump golang from 1.23.5 to 1.23.6 (#3822) * Use govulncheck action (#3831) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3817) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3826) * (deps) Bump golang from 1.23.6 to 1.24.0 (#3842) * (deps) Bump myst-parser (#3841) * (deps) Bump modernc.org/sqlite (#3846) * (deps) Bump golang from 1.24.0 to 1.24.1 (#3870) * (deps) Bump jinja2 in /docs in the production-dependencies group (#3872) * Upgrade to wazero@v1.9.0 (#3887) * Upgrade to Go 1.24.1 (#3892) * Upgrade to latest version of MySQL parser (#3893) * (deps) Bump pyparsing (#3890) * (deps) Bump golang.org/x/net from 0.33.0 to 0.37.0 (#3894) * (deps) Bump the production-dependencies group across 1 directory with 8 updates (#3896) * (deps) Bump github.com/jackc/pgx/v5 (#3898) * (deps) Bump the production-dependencies group (#3899) * (deps) Bump modernc.org/sqlite (#3905) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3914) * (deps) Bump urllib3 in /docs in the production-dependencies group (#3926) * (deps) Bump golang from 1.24.1 to 1.24.2 (#3915) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3923) * (deps) Upgrade github.com/wasilibs/go-pgquery (#3927) [1.28.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.28.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-28-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-01-20 ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id8 "Link to this heading") * (mysql) Add a test for VECTOR column type (#3734) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id9 "Link to this heading") * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id10 "Link to this heading") * How-to use transactions with pgx (#3557) * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Correct spelling and grammar (#3645) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id11 "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id12 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) [1.27.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.27.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-27-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-08-05 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id14 "Link to this heading") * (dbmanager) Add leading slash to db uri path rewrite (#3493) * (verify) Include database engine in request (#3522) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id15 "Link to this heading") * (golang) Add initialisms configuration (#3308) * (compiler) Support subqueries in the FROM clause (second coming) (#3310) * Managed databases with any accessible server (#3421) * (vet) Use new dbmanager client (#3423) * (verify) Update verify to work with managed databases (#3425) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id16 "Link to this heading") * Fix typo in config (#3358) * Resolve a typo in configuration keys (#3349) * Add sponsorship information to README (#3413) * Update the language-support to include C# (#3408) * Add migration guide for hosted managed databases (#3417) * Fix readme links (#3424) * Update the managed db and verify documentation (#3426) * Add sponsor image (#3428) * Add Ruby as supported language (#3487) * Update migrating-to-sqlc-gen-kotlin.md (#3454) * Fix typo in comment (#3316) * Fix deprecated build tag format (#3361) ### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id17 "Link to this heading") * (endtoend) Re-use databases when possible (#3315) * Enabled MySQL database (#3318) * Remove internal/sqltest/hosted package (#3521) [1.26.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.26.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-26-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-03-28 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#release-notes "Link to this heading") This release is mainly a bug fix release. It also includes an [important security fix](https://github.com/sqlc-dev/sqlc/issues/3194) for users using output plugins. ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#changes "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id19 "Link to this heading") * (docker) Use distroless base image instead of scratch (#3111) * (generate) Ensure files are created inside output directory (#3195) * (mysql) BREAKING: Use `int16` for MySQL `SMALLINT` and `YEAR` (#3106) * (mysql) BREAKING: Use `int8` for MySQL TINYINT (#3298) * (mysql) Variables not resolving in ORDER BY statements (#3115) * (opts) Validate SQL package and driver options (#3241) * (postgres/batch) Ignore query\_parameter\_limit for batches * (scripts) Remove deprecated test output regeneration script (#3105) * (sqlite) Correctly skip unknown statements (#3239) #### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id20 "Link to this heading") * (postgres) Add instructions for PostGIS/GEOS (#3182) * Improve details on TEXT (#3247) #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id21 "Link to this heading") * (generate) Avoid generating empty Go imports (#3135) * (mysql) Add NEXTVAL() to the MySQL catalog (#3147) * (mysql) Support json.RawMessage for LOAD DATA INFILE (#3099) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id22 "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 to 5.5.5 (#3259) * (deps) Bump modernc.org/sqlite to 1.29.5 (#3200) * (deps) Bump github.com/go-sql-driver/mysql to 1.8.0 (#3257) * (deps) Bump github.com/tetratelabs/wazero to 1.7.0 (#3096) * (deps) Bump github.com/pganalyze/pg\_query\_go to v5 (#3096) [1.25.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.25.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-25-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-01-03 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id24 "Link to this heading") #### Add tags to push and verify[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#add-tags-to-push-and-verify "Link to this heading") You can add tags when [pushing](https://docs.sqlc.dev/en/v1.30.0/howto/push.html) schema and queries to [sqlc Cloud](https://dashboard.sqlc.dev/) . Tags operate like git tags, meaning you can overwrite previously-pushed tag values. We suggest tagging pushes to associate them with something relevant from your environment, e.g. a git tag or branch name. $ sqlc push --tag v1.0.0 Once you’ve created a tag, you can refer to it when [verifying](https://docs.sqlc.dev/en/v1.30.0/howto/verify.html) changes, allowing you to compare the existing schema against a known set of previous queries. $ sqlc verify --against v1.0.0 #### C-ya, `cgo`[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#c-ya-cgo "Link to this heading") Over the last month, we’ve switched out a few different modules to remove our reliance on [cgo](https://go.dev/blog/cgo) . Previously, we needed cgo for three separate functions: * Parsing PostgreSQL queries with [pganalyze/pg\_query\_go](https://github.com/pganalyze/pg_query_go) * Running SQLite databases with [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) * Executing WASM / WASI code with [bytecodealliance/wasmtime-go](https://github.com/bytecodealliance/wasmtime-go) With the help of the community, we found cgo-free alternatives for each module: * Parsing PostgreSQL queries, now using [wasilibs/go-pgquery](https://github.com/wasilibs/go-pgquery) * Running SQLite databases, now using [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) * Executing WASM / WASI code, now using [tetratelabs/wazero](https://github.com/tetratelabs/wazero) For the first time, Windows users can enjoy full PostgreSQL support without using [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) . It’s a Christmas miracle! If you run into any issues with the updated dependencies, please [open an issue](https://github.com/sqlc-dev/sqlc/issues) . ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id25 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id26 "Link to this heading") * (codegen) Wrong yaml annotation in go codegen options for output\_querier\_file\_name (#3006) * (codegen) Use derived ArrayDims instead of deprecated attndims (#3032) * (codegen) Take the maximum array dimensions (#3034) * (compiler) Skip analysis of queries without a `name` annotation (#3072) * (codegen/golang) Don’t import `"strings"` for `sqlc.slice()` with pgx (#3073) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id27 "Link to this heading") * Add name to query set configuration (#3011) * Add a sidebar link for `push`, add Go plugin link (#3023) * Update banner for sqlc-gen-typescript (#3036) * Add strict\_order\_by in doc (#3044) * Re-order the migration tools list (#3064) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id28 "Link to this heading") * (analyzer) Return zero values when encountering unexpected ast nodes (#3069) * (codegen/go) add omit\_sqlc\_version to Go code generation (#3019) * (codgen/go) Add `emit_sql_as_comment` option to Go code plugin (#2735) * (plugins) Use wazero instead of wasmtime (#3042) * (push) Add tag support (#3074) * (sqlite) Support emit\_pointers\_for\_null\_types (#3026) ### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id29 "Link to this heading") * (endtoend) Enable for more build targets (#3041) * (endtoend) Run MySQL and PostgreSQL locally on the runner (#3095) * (typescript) Test against sqlc-gen-typescript (#3046) * Add tests for omit\_sqlc\_version (#3020) * Split schema and query for test (#3094) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id30 "Link to this heading") * (deps) Bump idna from 3.4 to 3.6 in /docs (#3010) * (deps) Bump sphinx-rtd-theme from 1.3.0 to 2.0.0 in /docs (#3016) * (deps) Bump golang from 1.21.4 to 1.21.5 (#3043) * (deps) Bump actions/setup-go from 4 to 5 (#3047) * (deps) Bump github.com/jackc/pgx/v5 from 5.5.0 to 5.5.1 (#3050) * (deps) Upgrade to latest version of github.com/wasilibs/go-pgquery (#3052) * (deps) Bump google.golang.org/grpc from 1.59.0 to 1.60.0 (#3053) * (deps) Bump babel from 2.13.1 to 2.14.0 in /docs (#3055) * (deps) Bump actions/upload-artifact from 3 to 4 (#3061) * (deps) Bump modernc.org/sqlite from 1.27.0 to 1.28.0 (#3062) * (deps) Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#3068) * (deps) Bump google.golang.org/grpc from 1.60.0 to 1.60.1 (#3070) * (deps) Bump google.golang.org/protobuf from 1.31.0 to 1.32.0 (#3079) * (deps) Bump github.com/tetratelabs/wazero from 1.5.0 to 1.6.0 (#3096) * (sqlite) Update to antlr 4.13.1 (#3086) * (sqlite) Disable modernc for WASM (#3048) * (sqlite) Switch from mattn/go-sqlite3 to modernc.org/sqlite (#3040) [1.24.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.24.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-24-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-11-22 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id32 "Link to this heading") #### Verifying database schema changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#verifying-database-schema-changes "Link to this heading") Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. #### Rename `upload` command to `push`[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#rename-upload-command-to-push "Link to this heading") We’ve renamed the `upload` sub-command to `push`. We changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. We also add annotations to each push. By default, we include these environment variables if they are present: GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA Like upload, `push` should be run when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. #### MySQL support in `createdb`[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#mysql-support-in-createdb "Link to this heading") The `createdb` command, added in the last release, now supports MySQL. If you have a cloud project configured, you can use `sqlc createdb` to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html#with-other-tools) documentation. #### Plugin interface refactor[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#plugin-interface-refactor "Link to this heading") This release includes a refactored plugin interface to better support future functionality. Plugins now support different methods via a gRPC service interface, allowing plugins to support different functionality in a backwards-compatible way. By using gRPC interfaces, we can even (theoretically) support [remote plugins](https://github.com/sqlc-dev/sqlc/pull/2938) , but that’s something for another day. ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id33 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id34 "Link to this heading") * (engine/sqlite) Support CASE expr (#2926) * (engine/sqlite) Support -> and ->> operators (#2927) * (vet) Add a nil pointer check to prevent db/prepare panic (#2934) * (compiler) Prevent panic when compiler is nil (#2942) * (codegen/golang) Move more Go-specific config validation into the plugin (#2951) * (compiler) No panic on full-qualified column names (#2956) * (docs) Better discussion of type override nuances (#2972) * (codegen) Never generate return structs for :exec (#2976) * (generate) Update help text for generate to be more generic (#2981) * (generate) Return an error instead of generating duplicate Go names (#2962) * (codegen/golang) Pull opts into its own package (#2920) * (config) Make some struct and field names less confusing (#2922) #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id35 "Link to this heading") * (codegen) Remove Go specific overrides from codegen proto (#2929) * (plugin) Use gRPC interface for codegen plugin communication (#2930) * (plugin) Calculate SHA256 if it does not exist (#2935) * (sqlc-gen-go) Add script to mirror code to sqlc-gen-go (#2952) * (createdb) Add support for MySQL (#2980) * (verify) Add new command to verify queries and migrations (#2986) #### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id36 "Link to this heading") * (ci) New workflow for sqlc-gen-python (#2936) * (ci) Rely on go.mod to determine which Go version to use (#2971) * (tests) Add glob pattern tests to sqlpath.Glob (#2995) * (examples) Use hosted MySQL databases for tests (#2982) * (docs) Clean up a little, update LICENSE and README (#2941) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id37 "Link to this heading") * (deps) Bump babel from 2.13.0 to 2.13.1 in /docs (#2911) * (deps) Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2944) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.17 to 1.14.18 (#2945) * (deps) Bump golang.org/x/sync from 0.4.0 to 0.5.0 (#2946) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2947) * (deps) Change github.com/pingcap/tidb/parser to github.com/pingcap/tidb/pkg/parser * (deps) Bump github.com/google/cel-go from 0.18.1 to 0.18.2 (#2969) * (deps) Bump urllib3 from 2.0.7 to 2.1.0 in /docs (#2975) * (buf) Change root of Buf module (#2987) * (deps) Bump certifi from 2023.7.22 to 2023.11.17 in /docs (#2993) * (ci) Bump Go version from 1.21.3 to 1.21.4 in workflows and Dockerfile (#2961) [1.23.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.23.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-23-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-10-24 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id39 "Link to this heading") #### Database-backed query analysis[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#database-backed-query-analysis "Link to this heading") With a [database connection](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database) configured, `sqlc generate` will gather metadata from that database to support its query analysis. Turning this on resolves a [large number of issues](https://github.com/sqlc-dev/sqlc/issues?q=is%3Aissue+label%3Aanalyzer) in the backlog related to type inference and more complex queries. The easiest way to try it out is with [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html) . The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. #### New `createdb` command[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#new-createdb-command "Link to this heading") When you have a cloud project configured, you can use the new `sqlc createdb` command to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html#with-other-tools) documentation. #### Support for pgvector[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#support-for-pgvector "Link to this heading") If you’re using [pgvector](https://github.com/pgvector/pgvector) , say goodbye to custom overrides! sqlc now generates code using [pgvector-go](https://github.com/pgvector/pgvector-go#pgx) as long as you’re using `pgx`. The pgvector extension is also available in [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html) . #### Go build tags[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#go-build-tags "Link to this heading") With the new `emit_build_tags` configuration parameter you can set build tags for sqlc to add at the top of generated source files. ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id40 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id41 "Link to this heading") * (codegen) Correct column names in :copyfrom (#2838) * (compiler) Search SELECT and UPDATE the same way (#2841) * (dolphin) Support more UNIONs for MySQL (#2843) * (compiler) Account for parameters without parents (#2844) * (postgresql) Remove temporary pool config (#2851) * (golang) Escape reserved keywords (#2849) * (mysql) Handle simplified CASE statements (#2852) * (engine/dolphin) Support enum in ALTER definition (#2680) * (mysql) Add, drop, rename and change enum values (#2853) * (config) Validate `database` config in all cases (#2856) * (compiler) Use correct func signature for `CommentSyntax` on windows (#2867) * (codegen/go) Prevent filtering of embedded struct fields (#2868) * (compiler) Support functions with OUT params (#2865) * (compiler) Pull in array information from analyzer (#2864) * (analyzer) Error on unexpanded star expression (#2882) * (vet) Remove rollback statements from DDL (#2895) #### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id42 "Link to this heading") * Add stable anchors to changelog (#2784) * Fix typo in v1.22.0 changelog (#2796) * Add sqlc upload to CI / CD guide (#2797) * Fix broken link, add clarity to plugins doc (#2813) * Add clarity and reference to JSON tags (#2819) * Replace form with dashboard link (#2840) * (examples) Update examples to use pgx/v5 (#2863) * Use docker compose v2 and update MYSQL\_DATABASE env var (#2870) * Update getting started guides, use pgx for Postgres guide (#2891) * Use managed databases in PostgreSQL getting started guide (#2892) * Update managed databases doc to discuss codegen (#2897) * Add managed dbs to CI/CD and vet guides (#2896) * Document database-backed query analyzer (#2904) #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id43 "Link to this heading") * (codegen) Support setting Go build tags (#2012) (#2807) * (generate) Reorder codegen handlers to prefer plugins (#2814) * (devenv) Add vscode settings.json with auto newline (#2834) * (cmd) Support sqlc.yml configuration file (#2828) * (analyzer) Analyze queries using a running PostgreSQL database (#2805) * (sql/ast) Render AST to SQL (#2815) * (codegen) Include plugin information (#2846) * (postgresql) Add ALTER VIEW … SET SCHEMA (#2855) * (compiler) Parse query parameter metadata from comments (#2850) * (postgresql) Support system columns on tables (#2871) * (compiler) Support LEFT JOIN on aliased table (#2873) * Improve messaging for common cloud config and rpc errors (#2885) * Abort compiler when rpc fails as unauthenticated (#2887) * (codegen) Add support for pgvector and pgvector-go (#2888) * (analyzer) Cache query analysis (#2889) * (createdb) Create ephemeral databases (#2894) * (debug) Add databases=managed debug option (#2898) * (config) Remove managed database validation (#2901) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id44 "Link to this heading") * (endtoend) Fix test output for do tests (#2782) #### Refactor[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#refactor "Link to this heading") * (codegen) Remove golang and json settings from plugin proto (#2822) * (codegen) Removed deprecated code and improved speed (#2899) #### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id45 "Link to this heading") * (endtoend) Split shema and queries (#2803) * Fix a few incorrect testcases (#2804) * (analyzer) Add more database analyzer test cases (#2854) * Add more analyzer test cases (#2866) * Add more test cases for new analyzer (#2879) * (endtoend) Enabled managed-db tests in CI (#2883) * Enabled pgvector tests for managed dbs (#2893) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id46 "Link to this heading") * (deps) Bump packaging from 23.1 to 23.2 in /docs (#2791) * (deps) Bump urllib3 from 2.0.5 to 2.0.6 in /docs (#2798) * (deps) Bump babel from 2.12.1 to 2.13.0 in /docs (#2799) * (deps) Bump golang.org/x/sync from 0.3.0 to 0.4.0 (#2810) * (deps) Bump golang from 1.21.1 to 1.21.2 (#2811) * (deps) Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (#2826) * (deps) Bump golang from 1.21.2 to 1.21.3 (#2824) * (deps) Bump google.golang.org/grpc from 1.58.2 to 1.58.3 (#2825) * (deps) Bump golang.org/x/net from 0.12.0 to 0.17.0 (#2836) * (deps) Bump urllib3 from 2.0.6 to 2.0.7 in /docs (#2872) * (deps) Bump google.golang.org/grpc from 1.58.3 to 1.59.0 (#2876) * (deps) Upgrade wasmtime-go from 13.0.0 to 14.0.0 (#2900) #### Ci[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#ci "Link to this heading") * Bump go version in workflows (#2835) [1.22.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.22.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-22-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-26 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id48 "Link to this heading") #### Managed databases for `sqlc vet`[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#managed-databases-for-sqlc-vet "Link to this heading") If you’re using [sqlc vet](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html) to write rules that require access to a running database, `sqlc` can now start and manage that database for you. PostgreSQL support is available today, with MySQL on the way. When you turn on managed databases, `sqlc` will use your schema to create a template database that it can copy to make future runs of `sqlc vet` very performant. This feature relies on configuration obtained via [sqlc Cloud](https://dashboard.sqlc.dev/) . Read more in the [managed databases](https://docs.sqlc.dev/en/v1.30.0/howto/managed-databases.html) documentation. ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id49 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id50 "Link to this heading") * (codegen/golang) Refactor imports code to match templates (#2709) * (codegen/golang) Support name type (#2715) * (wasm) Move Runner struct to shared file (#2725) * (engine/sqlite) Fix grammer to avoid missing join\_constraint (#2732) * (convert) Support YAML anchors in plugin options (#2733) * (mysql) Disallow time.Time in mysql :copyfrom queries, not all queries (#2768) * (engine/sqlite) Fix convert process for VALUES (#2737) #### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id51 "Link to this heading") * Clarify nullable override behavior (#2753) * Add managed databases to sidebar (#2764) * Pull renaming and type overrides into separate sections (#2774) * Update the docs banner for managed dbs (#2775) #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id52 "Link to this heading") * (config) Enables the configuration of copyfrom.go similar to quierer and friends (#2727) * (vet) Run rules against a managed database (#2751) * (upload) Point upload command at new endpoint (#2772) * (compiler) Support DO statements (#2777) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id53 "Link to this heading") * (endtoend) Skip tests missing secrets (#2763) * Skip certain tests on PRs (#2769) #### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id54 "Link to this heading") * (endtoend) Verify all schemas in endtoend (#2744) * (examples) Use a hosted database for example testing (#2749) * (endtoend) Pull region from environment (#2750) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id55 "Link to this heading") * (deps) Bump golang from 1.21.0 to 1.21.1 (#2711) * (deps) Bump google.golang.org/grpc from 1.57.0 to 1.58.1 (#2743) * (deps) Bump wasmtime-go from v12 to v13 (#2756) * (windows) Downgrade to mingw 11.2.0 (#2757) * (deps) Bump urllib3 from 2.0.4 to 2.0.5 in /docs (#2747) * (deps) Bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#2758) * (deps) Bump github.com/google/cel-go from 0.18.0 to 0.18.1 (#2778) #### Ci[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id56 "Link to this heading") * Bump go version to latest in ci workflows (#2722) [1.21.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.21.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-21-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-06 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id58 "Link to this heading") This is primarily a bugfix release, along with some documentation and testing improvements. #### MySQL engine improvements[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#mysql-engine-improvements "Link to this heading") `sqlc` previously didn’t know how to parse a `CALL` statement when using the MySQL engine, which meant it was impossible to use sqlc with stored procedures in MySQL databases. Additionally, `sqlc` now supports `IS [NOT] NULL` in queries. And `LIMIT` and `OFFSET` clauses now work with `UNION`. #### SQLite engine improvements[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sqlite-engine-improvements "Link to this heading") GitHub user [@orisano](https://github.com/orisano) continues to bring bugfixes and improvements to `sqlc`’s SQLite engine. See the “Changes” section below for the full list. #### Plugin access to environment variables[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#plugin-access-to-environment-variables "Link to this heading") If you’re authoring a [sqlc plugin](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#../guides/plugins.html) , you can now configure sqlc to pass your plugin the values of specific environment variables. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id59 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id60 "Link to this heading") * Myriad string formatting changes (#2558) * (engine/sqlite) Support quoted identifier (#2556) * (engine/sqlite) Fix compile error (#2564) * (engine/sqlite) Fixed detection of column alias without AS (#2560) * (ci) Bump go version to 1.20.7 (#2568) * Remove references to deprecated `--experimental` flag (#2567) * (postgres) Fixed a problem with array dimensions disappearing when using “ALTER TABLE ADD COLUMN” (#2572) * Remove GitHub sponsor integration (#2574) * (docs) Improve discussion of prepared statements support (#2604) * (docs) Remove multidimensional array qualification in datatypes.md (#2619) * (config) Go struct tag parsing (#2606) * (compiler) Fix to not scan children under ast.RangeSubselect when retrieving table listing (#2573) * (engine/sqlite) Support NOT IN (#2587) * (codegen/golang) Fixed detection of the used package (#2597) * (engine/dolphin) Fixed problem that LIMIT OFFSET cannot be used with `UNION ALL` (#2613) * (compiler) Support identifiers with schema (#2579) * (compiler) Fix column expansion to work with quoted non-keyword identifiers (#2576) * (codegen/go) Compare define type in codegen (#2263) (#2578) * (engine/sqlite) Fix ast when using compound operator (#2673) * (engine/sqlite) Fix to handle join clauses correctly (#2674) * (codegen) Use correct Go types for bit strings and cid/oid/tid/xid with pgx/v4 (#2668) * (endtoend) Ensure all SQL works against PostgreSQL (#2684) #### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id61 "Link to this heading") * Update Docker installation instructions (#2552) * Missing emit\_pointers\_for\_null\_types configuration option in version 2 (#2682) (#2683) * Fix typo (#2697) * Document sqlc.\* macros (#2698) * (mysql) Document parseTimet=true requirement (#2699) * Add atlas to the list of supported migration frameworks (#2700) * Minor updates to insert howto (#2701) #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id62 "Link to this heading") * (endtoend/testdata) Added two sqlite `CAST` tests and rearranged postgres tests for same (#2551) * (docs) Add a reference to type overriding in datatypes.md (#2557) * (engine/sqlite) Support COLLATE for sqlite WHERE clause (#2554) * (mysql) Add parser support for IS \[NOT\] NULL (#2651) * (engine/dolphin) Support CALL statement (#2614) * (codegen) Allow plugins to access environment variables (#2669) * (config) Add JSON schema files for configs (#2703) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id63 "Link to this heading") * Ignore Vim swap files (#2616) * Fix typo (#2696) #### Refactor[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id64 "Link to this heading") * (astutils) Remove redundant nil check in `Walk` (#2660) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id65 "Link to this heading") * (deps) Bump wasmtime from v8.0.0 to v11.0.0 (#2553) * (deps) Bump golang from 1.20.6 to 1.20.7 (#2563) * (deps) Bump chardet from 5.1.0 to 5.2.0 in /docs (#2562) * (deps) Bump github.com/pganalyze/pg\_query\_go/v4 (#2583) * (deps) Bump golang from 1.20.7 to 1.21.0 (#2596) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.2 to 5.4.3 (#2582) * (deps) Bump pygments from 2.15.1 to 2.16.1 in /docs (#2584) * (deps) Bump sphinxcontrib-applehelp from 1.0.4 to 1.0.7 in /docs (#2620) * (deps) Bump sphinxcontrib-qthelp from 1.0.3 to 1.0.6 in /docs (#2622) * (deps) Bump github.com/google/cel-go from 0.17.1 to 0.17.6 (#2650) * (deps) Bump sphinxcontrib-serializinghtml in /docs (#2641) * Upgrade from Go 1.20 to Go 1.21 (#2665) * (deps) Bump sphinxcontrib-devhelp from 1.0.2 to 1.0.5 in /docs (#2621) * (deps) Bump github.com/bytecodealliance/wasmtime-go from v11.0.0 to v12.0.0 (#2666) * (deps) Bump sphinx-rtd-theme from 1.2.2 to 1.3.0 in /docs (#2670) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.1 to 2.0.4 in /docs (#2671) * (deps) Bump github.com/google/cel-go from 0.17.6 to 0.18.0 (#2691) * (deps) Bump actions/checkout from 3 to 4 (#2694) * (deps) Bump pytz from 2023.3 to 2023.3.post1 in /docs (#2695) * (devenv) Bump go from 1.20.7 to 1.21.0 (#2702) [1.20.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.20.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#v1-20-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-31 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id67 "Link to this heading") #### `kyleconroy/sqlc` is now `sqlc-dev/sqlc`[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#kyleconroy-sqlc-is-now-sqlc-dev-sqlc "Link to this heading") We’ve completed our migration to the [sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc) repository. All existing links and installation instructions will continue to work. If you’re using the `go` tool to install `sqlc`, you’ll need to use the new import path to get v1.20.0 (and all future versions). \# INCORRECT: old import path go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.20.0 \# CORRECT: new import path go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.20.0 We designed the upgrade process to be as smooth as possible. If you run into any issues, please [file a bug report](https://github.com/sqlc-dev/sqlc/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=BUG_REPORT.yml) via GitHub. #### Use `EXPLAIN ...` output in lint rules[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#use-explain-output-in-lint-rules "Link to this heading") `sqlc vet` can now run `EXPLAIN` on your queries and include the results for use in your lint rules. For example, this rule checks that `SELECT` queries use an index. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- has-index rules: \- name: has-index rule: \> query.sql.startsWith("SELECT") && !(postgresql.explain.plan.plans.all(p, has(p.index\_name) || p.plans.all(p, has(p.index\_name)))) The expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.30.0/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. #### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; #### Bulk insert for MySQL[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#bulk-insert-for-mysql "Link to this heading") _Developed by [@Jille](https://github.com/Jille) _ MySQL now supports the `:copyfrom` query annotation. The generated code uses the [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) command to insert data quickly and efficiently. Use caution with this feature. Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use `SHOW WARNINGS` to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } `LOAD DATA` support must be enabled in the MySQL server. #### CAST support for MySQL[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#cast-support-for-mysql "Link to this heading") _Developed by [@ryanpbrewster](https://github.com/ryanpbrewster) and [@RadhiFadlillah](https://github.com/RadhiFadlillah) _ `sqlc` now understands `CAST` calls in MySQL queries, offering greater flexibility when generating code for complex queries. CREATE TABLE foo (bar BOOLEAN NOT NULL); \-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo; package querytest import ( "context" ) const selectColumnCast \= \`-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo \` func (q \*Queries) SelectColumnCast(ctx context.Context) (\[\]int64, error) { ... } #### SQLite improvements[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sqlite-improvements "Link to this heading") A slew of fixes landed for our SQLite implementation, bringing it closer to parity with MySQL and PostgreSQL. We want to thank [@orisano](https://github.com/orisano) for their continued dedication to improving `sqlc`’s SQLite support. ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id68 "Link to this heading") #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id69 "Link to this heading") * (debug) Add debug flag and docs for dumping vet rule variables (#2521) * (mysql) :copyfrom support via LOAD DATA INFILE (#2545) * (mysql) Implement cast function parser (#2473) * (postgresql) Add support for PostgreSQL multi-dimensional arrays (#2338) * (sql/catalog) Support ALTER TABLE IF EXISTS (#2542) * (sqlite) Virtual tables and fts5 supported (#2531) * (vet) Add default query parameters for explain queries (#2543) * (vet) Add output from `EXPLAIN ...` for queries to the CEL program environment (#2489) * (vet) Introduce a query annotation to opt out of sqlc vet rules (#2474) * Parse comment lines starting with `@symbol` as boolean flags associated with a query (#2464) #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id70 "Link to this heading") * (codegen/golang) Fix sqlc.embed to work with pq.Array (#2544) * (compiler) Correctly validate alias in order/group by clauses for joins (#2537) * (engine/sqlite) Added function to convert cast node (#2470) * (engine/sqlite) Fix join\_operator rule (#2434) * (engine/sqlite) Fix table\_alias rules (#2465) * (engine/sqlite) Fixed IN operator precedence (#2428) * (engine/sqlite) Fixed to be able to find relation from WITH clause (#2444) * (engine/sqlite) Lowercase ast.ResTarget.Name (#2433) * (engine/sqlite) Put logging statement behind debug flag (#2488) * (engine/sqlite) Support for repeated table\_option (#2482) * (mysql) Generate unsigned param (#2522) * (sql/catalog) Support pg\_dump output (#2508) * (sqlite) Code generation for sqlc.slice (#2431) * (vet) Clean up unnecessary `prepareable()` func and a var name (#2509) * (vet) Query.cmd was always set to “:” (#2525) * (vet) Report an error when a query is unpreparable, close prepared statement connection (#2486) * (vet) Split vet messages out of codegen.proto (#2511) #### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id71 "Link to this heading") * Add a description to the document for cases when a query result has no rows (#2462) * Update copyright and author (#2490) * Add example sqlc.yaml for migration parsing (#2479) * Small updates (#2506) * Point GitHub links to new repository location (#2534) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id72 "Link to this heading") * Rename kyleconroy/sqlc to sqlc-dev/sqlc (#2523) * (proto) Reformat protos using `buf format -w` (#2536) * Update FEATURE\_REQUEST.yml to include SQLite engine option * Finish migration to sqlc-dev/sqlc (#2548) * (compiler) Remove some duplicate code (#2546) #### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id73 "Link to this heading") * Add profiles to docker compose (#2503) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id74 "Link to this heading") * Run all supported versions of MySQL / PostgreSQL (#2463) * (deps) Bump pygments from 2.7.4 to 2.15.0 in /docs (#2485) * (deps) Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2483) * (deps) Bump github.com/google/cel-go from 0.16.0 to 0.17.1 (#2484) * (docs) Check Python dependencies via dependabot (#2497) * (deps) Bump idna from 2.10 to 3.4 in /docs (#2499) * (deps) Bump packaging from 20.9 to 23.1 in /docs (#2498) * (deps) Bump pygments from 2.15.0 to 2.15.1 in /docs (#2500) * (deps) Bump certifi from 2022.12.7 to 2023.7.22 in /docs (#2504) * (deps) Bump sphinx from 4.4.0 to 6.1.0 in /docs (#2505) * Add psql and mysqlsh to devenv (#2507) * (deps) Bump urllib3 from 1.26.5 to 2.0.4 in /docs (#2516) * (deps) Bump chardet from 4.0.0 to 5.1.0 in /docs (#2517) * (deps) Bump snowballstemmer from 2.1.0 to 2.2.0 in /docs (#2519) * (deps) Bump pytz from 2021.1 to 2023.3 in /docs (#2520) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.0 to 2.0.1 in /docs (#2518) * (deps) Bump pyparsing from 2.4.7 to 3.1.0 in /docs (#2530) * (deps) Bump alabaster from 0.7.12 to 0.7.13 in /docs (#2526) * (docs) Ignore updates for sphinx (#2532) * (deps) Bump babel from 2.9.1 to 2.12.1 in /docs (#2527) * (deps) Bump sphinxcontrib-applehelp from 1.0.2 to 1.0.4 in /docs (#2533) * (deps) Bump google.golang.org/grpc from 1.56.2 to 1.57.0 (#2535) * (deps) Bump pyparsing from 3.1.0 to 3.1.1 in /docs (#2547) [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id75 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id76 "Link to this heading") * Fix to traverse Sel in ast.In (#2414) * (compiler) Validate UNION … ORDER BY (#2446) * (golang) Prevent duplicate enum output (#2447) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id77 "Link to this heading") * Replace codegen, test and docs references to github.com/tabbed repos (#2418) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id78 "Link to this heading") * (deps) Bump google.golang.org/grpc from 1.56.1 to 1.56.2 (#2415) * (deps) Bump golang from 1.20.5 to 1.20.6 (#2437) * Pin Go to 1.20.6 (#2441) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.1 to 5.4.2 (#2436) [1.19.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id79 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-06 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id80 "Link to this heading") #### sqlc vet[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sqlc-vet "Link to this heading") [`sqlc vet`](https://docs.sqlc.dev/en/v1.30.0/howto/vet.html) runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.30.0/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, an error is reported using the given message. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ##### Database connectivity[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#database-connectivity "Link to this heading") `vet` also marks the first time that `sqlc` can connect to a live, running database server. We’ll expand this functionality over time, but for now it powers the `sqlc/db-prepare` built-in rule. When a [database](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#config.html#database) is configured, the `sqlc/db-preapre` rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Please note that `sqlc` does not manage or migrate your database. Use your migration tool of choice to create the necessary database tables and objects before running `sqlc vet`. #### Omit unused structs[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#omit-unused-structs "Link to this heading") Added a new configuration parameter `omit_unused_structs` which, when set to true, filters out table and enum structs that aren’t used in queries for a given package. #### Suggested CI/CD setup[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#suggested-ci-cd-setup "Link to this heading") With the addition of `sqlc diff` and `sqlc vet`, we encourage users to run sqlc in your CI/CD pipelines. See our [suggested CI/CD setup](https://docs.sqlc.dev/en/v1.30.0/howto/ci-cd.html) for more information. #### Simplified plugin development[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#simplified-plugin-development "Link to this heading") The [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) and [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) plugins have been updated use the upcoming [WASI](https://wasi.dev/) support in [Go 1.21](https://tip.golang.org/doc/go1.21#wasip1) . Building these plugins no longer requires [TinyGo](https://tinygo.org/) . ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id81 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id82 "Link to this heading") * Pointers overrides skip imports in generated query files (#2240) * CASE-ELSE clause is not properly parsed when a value is constant (#2238) * Fix toSnakeCase to handle input in CamelCase format (#2245) * Add location info to sqlite ast (#2298) * Add override tags to result struct (#1867) (#1887) * Override types of aliased columns and named parameters (#1884) * Resolve duplicate fields generated when inheriting multiple tables (#2089) * Check column references in ORDER BY (#1411) (#1915) * MySQL slice shadowing database/sql import (#2332) * Don’t defer rows.Close() if pgx.BatchResults.Query() failed (#2362) * Fix type overrides not working with sqlc.slice (#2351) * Type overrides on columns for parameters inside an IN clause (#2352) * Broken interaction between query\_parameter\_limit and pq.Array() (#2383) * (codegen/golang) Bring :execlastid in line with the rest (#2378) #### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id83 "Link to this heading") * Update changelog.md with some minor edits (#2235) * Add F# community plugin (#2295) * Add a ReadTheDocs config file (#2327) * Update query\_parameter\_limit documentation (#2374) * Add launch announcement banner #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id84 "Link to this heading") * PostgreSQL capture correct line and column numbers for parse error (#2289) * Add supporting COMMENT ON VIEW (#2249) * To allow spaces between function name and arguments of functions to be rewritten (#2250) * Add support for pgx/v5 emit\_pointers\_for\_null\_types flag (#2269) * (mysql) Support unsigned integers (#1746) * Allow use of table and column aliases for table functions returning unknown types (#2156) * Support “LIMIT ?” in UPDATE and DELETE for MySQL (#2365) * (internal/codegen/golang) Omit unused structs from output (#2369) * Improve default names for BETWEEN ? AND ? to have prefixes from\_ and to\_ (#2366) * (cmd/sqlc) Add the vet subcommand (#2344) * (sqlite) Add support for UPDATE/DELETE with a LIMIT clause (#2384) * Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) (#2373) * (cmd/vet) Prepare queries against a database (#2387) * (cmd/vet) Prepare queries for MySQL (#2388) * (cmd/vet) Prepare SQLite queries (#2389) * (cmd/vet) Simplify environment variable substiution (#2393) * (cmd/vet) Add built-in db-prepare rule * Add compiler support for NOTIFY and LISTEN (PostgreSQL) (#2363) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id85 "Link to this heading") * A few small staticcheck fixes (#2361) * Remove a bunch of dead code (#2360) * (scripts/regenerate) Should also update stderr.txt (#2379) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id86 "Link to this heading") * (deps) Bump requests from 2.25.1 to 2.31.0 in /docs (#2283) * (deps) Bump golang from 1.20.3 to 1.20.4 (#2256) * (deps) Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#2265) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 (#2293) * (deps) Bump golang.org/x/sync from 0.1.0 to 0.2.0 (#2266) * (deps) Bump golang from 1.20.4 to 1.20.5 (#2301) * Configure dependencies via devenv.sh (#2319) * Configure dependencies via devenv.sh (#2326) * (deps) Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#2328) * (deps) Bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#2333) * (deps) Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 (#2370) * (deps) Bump actions/checkout from 2 to 3 (#2357) * Run govulncheck on all builds (#2372) * (deps) Bump google.golang.org/grpc from 1.56.0 to 1.56.1 (#2358) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#cmd-sqlc "Link to this heading") * Show helpful output on missing subcommand (#2345) #### Codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#codegen "Link to this heading") * Use catalog’s default schema (#2310) * (go) Add tests for tables with dashes (#2312) * (go) Strip invalid characters from table and column names (#2314) * (go) Support JSON tags for nullable enum structs (#2121) #### Internal/config[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-config "Link to this heading") * Support golang overrides for slices (#2339) #### Kotlin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#kotlin "Link to this heading") * Use latest version of sqlc-gen-kotlin (#2356) #### Postgres[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#postgres "Link to this heading") * Column merging for table inheritence (#2315) #### Protos[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#protos "Link to this heading") * Add missing field name (#2354) #### Python[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#python "Link to this heading") * Use latest version of sqlc-gen-python (#2355) #### Remote[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#remote "Link to this heading") * Use user-id/password auth (#2262) #### Sqlite[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sqlite "Link to this heading") * Fixed sqlite column type override (#1986) [1.18.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.18.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id87 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-04-27 ### Release notes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id88 "Link to this heading") #### Remote code generation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#remote-code-generation "Link to this heading") _Developed by [@andrewmbenton](https://github.com/andrewmbenton) _ At its core, sqlc is powered by SQL engines, which include parsers, formatters, analyzers and more. While our goal is to support each engine on each operating system, it’s not always possible. For example, the PostgreSQL engine does not work on Windows. To bridge that gap, we’re announcing remote code generation, currently in private alpha. To join the private alpha, [sign up for the waitlist](https://docs.google.com/forms/d/e/1FAIpQLScDWrGtTgZWKt3mdlF5R2XCX6tL1pMkB4yuZx5yq684tTNN1Q/viewform?usp=sf_link) . Remote code generation works like local code generation, except the heavy lifting is performed in a consistent cloud environment. WASM-based plugins are supported in the remote environment, but process-based plugins are not. To configure remote generation, add a `cloud` block in `sqlc.json`. { "version": "2", "cloud": { "organization": "", "project": "", }, ... } You’ll also need to set the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\= When the `cloud` configuration block exists, `sqlc generate` will default to remote code generation. If you’d like to generate code locally without removing the `cloud` block from your config, pass the `--no-remote` option. sqlc generate \--no-remote Remote generation is off by default and requires an opt-in to use. #### sqlc.embed[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sqlc-embed "Link to this heading") _Developed by [@nickjackson](https://github.com/nickjackson) _ Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ) CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ) We want to select the student record and the highest score they got on a test. Here’s how we’d usually do that: \-- name: HighScore :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT students.\*, high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; When using Go, sqlc will produce a struct like this: type HighScoreRow struct { ID int64 Name sql.NullString Age sql.NullInt32 HighScore int32 } With embedding, the struct will contain a model for the table instead of a flattened list of columns. \-- name: HighScoreEmbed :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT sqlc.embed(students), high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; type HighScoreRow struct { Student Student HighScore int32 } #### sqlc.slice[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sqlc-slice "Link to this heading") _Developed by Paul Cameron and Jille Timmermans_ The MySQL Go driver does not support passing slices to the IN operator. The `sqlc.slice` function generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) func (q \*Queries) SelectStudents(ctx context.Context, ages \[\]int32) (\[\]Student, error) { This feature is only supported in MySQL and cannot be used with prepared queries. #### Batch operation improvements[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#batch-operation-improvements "Link to this heading") When using batches with pgx, the error returned when a batch is closed is exported by the generated package. This change allows for cleaner error handling using `errors.Is`. errors.Is(err, generated\_package.ErrBatchAlreadyClosed) Previously, you would have had to check match on the error message itself. err.Error() \== "batch already closed" The generated code for batch operations always lived in `batch.go`. This file name can now be configured via the `output_batch_file_name` configuration option. #### Configurable query parameter limits for Go[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#configurable-query-parameter-limits-for-go "Link to this heading") By default, sqlc will limit Go functions to a single parameter. If a query includes more than one parameter, the generated method will use an argument struct instead of positional arguments. This behavior can now be changed via the `query_parameter_limit` configuration option. If set to `0`, every genreated method will use a argument struct. ### Changes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id89 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id90 "Link to this heading") * Prevent variable redeclaration in single param conflict for pgx (#2058) * Retrieve Larg/Rarg join query after inner join (#2051) * Rename argument when conflicted to imported package (#2048) * Pgx closed batch return pointer if need #1959 (#1960) * Correct singularization of “waves” (#2194) * Honor Package level renames in v2 yaml config (#2001) * (mysql) Prevent UPDATE … JOIN panic #1590 (#2154) * Mysql delete join panic (#2197) * Missing import with pointer overrides, solves #2168 #2125 (#2217) #### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id91 "Link to this heading") * (config.md) Add `sqlite` as engine option (#2164) * Add first pass at pgx documentation (#2174) * Add missed configuration option (#2188) * `specifies parameter ":one" without containing a RETURNING clause` (#2173) #### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id92 "Link to this heading") * Add `sqlc.embed` to allow model re-use (#1615) * (Go) Add query\_parameter\_limit conf to codegen (#1558) * Add remote execution for codegen (#2214) #### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id93 "Link to this heading") * Skip tests if required plugins are missing (#2104) * Add tests for reanme fix in v2 (#2196) * Regenerate batch output for filename tests * Remove remote test (#2232) * Regenerate test output #### Bin/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#bin-sqlc "Link to this heading") * Add SQLCTMPDIR environment variable (#2189) #### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id94 "Link to this heading") * (deps) Bump github.com/antlr/antlr4/runtime/Go/antlr (#2109) * (deps) Bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 (#2119) * (deps) Bump golang from 1.20.1 to 1.20.2 (#2135) * (deps) Bump google.golang.org/protobuf from 1.28.1 to 1.29.0 (#2137) * (deps) Bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#2143) * (deps) Bump golang from 1.20.2 to 1.20.3 (#2192) * (deps) Bump actions/setup-go from 3 to 4 (#2150) * (deps) Bump google.golang.org/protobuf from 1.29.1 to 1.30.0 (#2151) * (deps) Bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#2193) * (deps) Bump github.com/lib/pq from 1.10.7 to 1.10.8 (#2211) * (deps) Bump github.com/lib/pq from 1.10.8 to 1.10.9 (#2229) * (deps) Bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 (#2228) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id95 "Link to this heading") * Remove –experimental flag (#2170) * Add option to disable process-based plugins (#2180) * Bump version to v1.18.0 #### Codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id96 "Link to this heading") * Correctly generate CopyFrom columns for single-column copyfroms (#2185) #### Config[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#config "Link to this heading") * Add top-level cloud configuration (#2204) #### Engine/postgres[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#engine-postgres "Link to this heading") * Upgrade to pg\_query\_go/v4 (#2114) #### Ext/wasm[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#ext-wasm "Link to this heading") * Check exit code on returned error (#2223) #### Parser[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#parser "Link to this heading") * Generate correct types for `SELECT NOT EXISTS` (#1972) #### Sqlite[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id97 "Link to this heading") * Add support for CREATE TABLE … STRICT (#2175) #### Wasm[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#wasm "Link to this heading") * Upgrade to wasmtime v8.0.0 (#2222) [1.17.2](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.2) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id98 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id99 "Link to this heading") * Fix build on Windows (#2102) [1.17.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.1) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id100 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id101 "Link to this heading") * Prefer to use \[\]T over pgype.Array\[T\] (#2090) * Revert changes to Dockerfile (#2091) * Do not throw error when IF NOT EXISTS is used on ADD COLUMN (#2092) ### MySQL[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#mysql "Link to this heading") * Add `float` support to MySQL (#2097) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id102 "Link to this heading") * (deps) Bump golang from 1.20.0 to 1.20.1 (#2082) [1.17.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id103 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id104 "Link to this heading") * Initialize generated code outside function (#1850) * (engine/mysql) Take into account column’s charset to distinguish text/blob, (var)char/(var)binary (#776) (#1895) * The enum Value method returns correct type (#1996) * Documentation for Inserting Rows (#2034) * Add import statements even if only pointer types exist (#2046) * Search from Rexpr if not found from Lexpr (#2056) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id105 "Link to this heading") * Change ENTRYPOINT to CMD (#1943) * Update samples for HOW-TO GUIDES (#1953) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id106 "Link to this heading") * Add the diff command (#1963) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id107 "Link to this heading") * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.15 to 1.14.16 (#1913) * (deps) Bump github.com/spf13/cobra from 1.6.0 to 1.6.1 (#1909) * Fix devcontainer (#1942) * Run sqlc-pg-gen via GitHub Actions (#1944) * Move large arrays out of functions (#1947) * Fix conflicts from pointer configuration (#1950) * (deps) Bump github.com/go-sql-driver/mysql from 1.6.0 to 1.7.0 (#1988) * (deps) Bump github.com/jackc/pgtype from 1.12.0 to 1.13.0 (#1978) * (deps) Bump golang from 1.19.3 to 1.19.4 (#1992) * (deps) Bump certifi from 2020.12.5 to 2022.12.7 in /docs (#1993) * (deps) Bump golang from 1.19.4 to 1.19.5 (#2016) * (deps) Bump golang from 1.19.5 to 1.20.0 (#2045) * (deps) Bump github.com/jackc/pgtype from 1.13.0 to 1.14.0 (#2062) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.0 (#2063) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#cmd "Link to this heading") * Generate packages in parallel (#2026) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id108 "Link to this heading") * Bump version to v1.17.0 ### Codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id109 "Link to this heading") * Remove built-in Kotlin support (#1935) * Remove built-in Python support (#1936) ### Internal/codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-codegen "Link to this heading") * Cache pattern matching compilations (#2028) ### Mysql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id110 "Link to this heading") * Add datatype tests (#1948) * Fix blob tests (#1949) ### Plugins[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#plugins "Link to this heading") * Upgrade to wasmtime 3.0.1 (#2009) ### Sqlite[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id111 "Link to this heading") * Supported between expr (#1958) (#1967) ### Tools[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#tools "Link to this heading") * Regenerate scripts skips dirs that contains diff exec command (#1987) ### Wasm[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id112 "Link to this heading") * Upgrade to wasmtime 5.0.0 (#2065) [1.16.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.16.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id113 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-11-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id114 "Link to this heading") * (validate) Sqlc.arg & sqlc.narg are not “missing” (#1814) * Emit correct comment for nullable enums (#1819) * 🐛 Correctly switch `coalesce()` result `.NotNull` value (#1664) * Prevent batch infinite loop with arg length (#1794) * Support version 2 in error message (#1839) * Handle empty column list in postgresql (#1843) * Batch imports filter queries, update cmds having ret type (#1842) * Named params contribute to batch parameter count (#1841) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id115 "Link to this heading") * Add a getting started guide for SQLite (#1798) * Various readability improvements (#1854) * Add documentation for codegen plugins (#1904) * Update migration guides with links (#1933) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id116 "Link to this heading") * Add HAVING support to MySQL (#1806) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id117 "Link to this heading") * Upgrade wasmtime version (#1827) * Bump wasmtime version to v1.0.0 (#1869) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id118 "Link to this heading") * (deps) Bump github.com/jackc/pgconn from 1.12.1 to 1.13.0 (#1785) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.13 to 1.14.15 (#1799) * (deps) Bump github.com/jackc/pgx/v4 from 4.16.1 to 4.17.0 (#1786) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.0 to 4.17.1 (#1825) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1826) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.1 to 4.17.2 (#1831) * (deps) Bump golang from 1.19.0 to 1.19.1 (#1834) * (deps) Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#1838) * (deps) Bump github.com/lib/pq from 1.10.6 to 1.10.7 (#1835) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1857) * (deps) Bump github.com/spf13/cobra from 1.5.0 to 1.6.0 (#1893) * (deps) Bump golang from 1.19.1 to 1.19.3 (#1920) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id119 "Link to this heading") * Bump to v1.16.0 ### Codgen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#codgen "Link to this heading") * Include serialized codegen options (#1890) ### Compiler[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#compiler "Link to this heading") * Move Kotlin parameter logic into codegen (#1910) ### Examples[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#examples "Link to this heading") * Port Python examples to WASM plugin (#1903) ### Pg-gen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#pg-gen "Link to this heading") * Make sqlc-pg-gen the complete source of truth for pg\_catalog.go (#1809) * Implement information\_schema shema (#1815) ### Python[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id120 "Link to this heading") * Port all Python tests to sqlc-gen-python (#1907) * Upgrade to sqlc-gen-python v1.0.0 (#1932) [1.15.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.15.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id121 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-08-07 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id122 "Link to this heading") * (mysql) Typo (#1700) * (postgresql) Add quotes for CamelCase columns (#1729) * Cannot parse SQLite upsert statement (#1732) * (sqlite) Regenerate test output for builtins (#1735) * (wasm) Version modules by wasmtime version (#1734) * Missing imports (#1637) * Missing slice import for querier (#1773) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id123 "Link to this heading") * Add process-based plugin docs (#1669) * Add links to downloads.sqlc.dev (#1681) * Update transactions how to example (#1775) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id124 "Link to this heading") * More SQL Syntax Support for SQLite (#1687) * (sqlite) Promote SQLite support to beta (#1699) * Codegen plugins, powered by WASM (#1684) * Set user-agent for plugin downloads (#1707) * Null enums types (#1485) * (sqlite) Support stdlib functions (#1712) * (sqlite) Add support for returning (#1741) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id125 "Link to this heading") * Add tests for quoting columns (#1733) * Remove catalog tests (#1762) ### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id126 "Link to this heading") * Add tests for fixing slice imports (#1736) * Add test cases for returning (#1737) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id127 "Link to this heading") * Upgrade to Go 1.19 (#1780) * Upgrade to go-wasmtime 0.39.0 (#1781) ### Plugins[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id128 "Link to this heading") * (wasm) Change default cache location (#1709) * (wasm) Change the SHA-256 config key (#1710) [1.14.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.14.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id129 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-06-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id130 "Link to this heading") * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) * (compiler) Fix left join nullability with table aliases (#1491) * Regenerate testdata for CREATE TABLE AS (#1516) * (bundler) Only close multipart writer once (#1528) * (endtoend) Regenerate testdata for exex\_lastid * (pgx) Copyfrom imports (#1626) * Validate sqlc function arguments (#1633) * Fixed typo `sql.narg` in doc (#1668) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id131 "Link to this heading") * (golang) Add Enum.Valid and AllEnumValues (#1613) * (sqlite) Start expanding support (#1410) * (pgx) Add support for batch operations (#1437) * (sqlite) Add support for delete statements (#1447) * (codegen) Insert comments in interfaces (#1458) * (sdk) Add the plugin SDK package (#1463) * Upload projects (#1436) * Add sqlc version to generated Kotlin code (#1512) * Add sqlc version to generated Go code (#1513) * Pass sqlc version in codegen request (#1514) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * Run sqlc with docker on windows cmd (#1557) * Add JSON “codegen” output (#1565) * Add sqlc.narg() for nullable named params (#1536) * Process-based codegen plugins (#1578) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id132 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id133 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) * (sql/catalog) Improve Readability (#1595) * Add basic fuzzing for config / overrides (#1500) [1.13.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.13.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id134 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-03-31 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id135 "Link to this heading") * (compiler) Fix left join nullability with table aliases (#1491) * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id136 "Link to this heading") * (cli) Upload projects (#1436) * (codegen) Add sqlc version to generated Go code (#1513) * (codegen) Add sqlc version to generated Kotlin code (#1512) * (codegen) Insert comments in interfaces (#1458) * (codegen) Pass sqlc version in codegen request (#1514) * (pgx) Add support for batch operations (#1437) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * (sdk) Add the plugin SDK package (#1463) * (sqlite) Add support for delete statements (#1447) * (sqlite) Start expanding support (#1410) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id137 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id138 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) ### Config[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id139 "Link to this heading") * Add basic fuzzing for config / overrides (#1500) [1.12.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.12.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id140 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-02-05 ### Bug[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#bug "Link to this heading") * ALTER TABLE SET SCHEMA (#1409) ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id141 "Link to this heading") * Update ANTLR v4 go.mod entry (#1336) * Check delete statements for CTEs (#1329) * Fix validation of GROUP BY on field aliases (#1348) * Fix imports when non-copyfrom queries needed imports that copyfrom queries didn’t (#1386) * Remove extra comment newline (#1395) * Enable strict function checking (#1405) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id142 "Link to this heading") * Bump version to 1.11.0 (#1308) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id143 "Link to this heading") * Inheritance (#1339) * Generate query code using ASTs instead of templates (#1338) * Add support for CREATE TABLE a ( LIKE b ) (#1355) * Add support for sql.NullInt16 (#1376) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id144 "Link to this heading") * Add tests for :exec{result,rows} (#1344) * Delete template-based codegen (#1345) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id145 "Link to this heading") * Bump github.com/jackc/pgx/v4 from 4.14.0 to 4.14.1 (#1316) * Bump golang from 1.17.3 to 1.17.4 (#1331) * Bump golang from 1.17.4 to 1.17.5 (#1337) * Bump github.com/spf13/cobra from 1.2.1 to 1.3.0 (#1343) * Remove devel Docker build * Bump golang from 1.17.5 to 1.17.6 (#1369) * Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 (#1382) * Format all Go code (#1387) [1.11.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.11.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id146 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-11-24 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id147 "Link to this heading") * Update incorrect signatures (#1180) * Correct aggregate func sig (#1182) * Jsonb\_build\_object (#1211) * Case-insensitive identifiers (#1216) * Incorrect handling of meta (#1228) * Detect invalid INSERT expression (#1231) * Respect alias name for coalesce (#1232) * Mark nullable when casting NULL (#1233) * Support nullable fields in joins for MySQL engine (#1249) * Fix between expression handling of table references (#1268) * Support nullable fields in joins on same table (#1270) * Fix missing binds in ORDER BY (#1273) * Set RV for TargetList items on updates (#1252) * Fix MySQL parser for query without trailing semicolon (#1282) * Validate table alias references (#1283) * Add support for MySQL ON DUPLICATE KEY UPDATE (#1286) * Support references to columns in joined tables in UPDATE statements (#1289) * Add validation for GROUP BY clause column references (#1285) * Prevent variable redeclaration in single param conflict (#1298) * Use common params struct field for same named params (#1296) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id148 "Link to this heading") * Replace deprecated go get with go install (#1181) * Fix package name referenced in tutorial (#1202) * Add environment variables (#1264) * Add go.17+ install instructions (#1280) * Warn about golang-migrate file order (#1302) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id149 "Link to this heading") * Instrument compiler via runtime/trace (#1258) * Add MySQL support for BETWEEN arguments (#1265) ### Refactor[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id150 "Link to this heading") * Move from io/ioutil to io and os package (#1164) ### Styling[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#styling "Link to this heading") * Apply gofmt to sample code (#1261) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id151 "Link to this heading") * Bump golang from 1.17.0 to 1.17.1 (#1173) * Bump eskatos/gradle-command-action from 1 to 2 (#1220) * Bump golang from 1.17.1 to 1.17.2 (#1227) * Bump github.com/pganalyze/pg\_query\_go/v2 (#1234) * Bump actions/checkout from 2.3.4 to 2.3.5 (#1238) * Bump babel from 2.9.0 to 2.9.1 in /docs (#1245) * Bump golang from 1.17.2 to 1.17.3 (#1272) * Bump actions/checkout from 2.3.5 to 2.4.0 (#1267) * Bump github.com/lib/pq from 1.10.3 to 1.10.4 (#1278) * Bump github.com/jackc/pgx/v4 from 4.13.0 to 4.14.0 (#1303) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id152 "Link to this heading") * Bump version to v1.11.0 [1.10.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.10.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id153 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-09-07 ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id154 "Link to this heading") * Fix invalid language support table (#1161) * Add a getting started guide for MySQL (#1163) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id155 "Link to this heading") * Bump golang from 1.16.7 to 1.17.0 (#1129) * Bump github.com/lib/pq from 1.10.2 to 1.10.3 (#1160) ### Ci[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id156 "Link to this heading") * Upgrade Go to 1.17 (#1130) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id157 "Link to this heading") * Bump version to v1.10.0 (#1165) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#codegen-golang "Link to this heading") * Consolidate import logic (#1139) * Add pgx support for range types (#1146) * Use pgtype for hstore when using pgx (#1156) ### Codgen/golang[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#codgen-golang "Link to this heading") * Use p\[gq\]type for network address types (#1142) ### Endtoend[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#endtoend "Link to this heading") * Run `go test` in CI (#1134) ### Engine/mysql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#engine-mysql "Link to this heading") * Add support for LIKE (#1162) ### Golang[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#golang "Link to this heading") * Output NullUUID when necessary (#1137) [1.9.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.9.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id158 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-08-13 ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id159 "Link to this heading") * Update documentation (a bit) for v1.9.0 (#1117) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id160 "Link to this heading") * Bump golang from 1.16.6 to 1.16.7 (#1107) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id161 "Link to this heading") * Bump version to v1.9.0 (#1121) ### Compiler[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id162 "Link to this heading") * Add tests for COALESCE behavior (#1112) * Handle subqueries in SELECT statements (#1113) [1.8.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.8.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id163 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-05-03 ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id164 "Link to this heading") * Add language support Matrix (#920) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id165 "Link to this heading") * Add case style config option (#905) ### Python[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id166 "Link to this heading") * Eliminate runtime package and use sqlalchemy (#939) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id167 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.4 to 0.5.5 (#926) * Bump github.com/lib/pq from 1.9.0 to 1.10.0 (#931) * Bump golang from 1.16.0 to 1.16.1 (#935) * Bump golang from 1.16.1 to 1.16.2 (#942) * Bump github.com/jackc/pgx/v4 from 4.10.1 to 4.11.0 (#956) * Bump github.com/go-sql-driver/mysql from 1.5.0 to 1.6.0 (#961) * Bump github.com/pganalyze/pg\_query\_go/v2 (#965) * Bump urllib3 from 1.26.3 to 1.26.4 in /docs (#968) * Bump golang from 1.16.2 to 1.16.3 (#963) * Bump github.com/lib/pq from 1.10.0 to 1.10.1 (#980) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id168 "Link to this heading") * Add the –experimental flag (#929) * Fix sqlc init (#959) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id169 "Link to this heading") * Bump version to v1.7.1-devel (#913) * Bump version to v1.8.0 ### Codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id170 "Link to this heading") * Generate valid enum names for symbols (#972) ### Postgresql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#postgresql "Link to this heading") * Support generated columns * Add test for PRIMARY KEY INCLUDE * Add tests for CREATE TABLE PARTITION OF * CREATE TRIGGER EXECUTE FUNCTION * Add support for renaming types (#971) ### Sql/ast[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sql-ast "Link to this heading") * Resolve return values from functions (#964) ### Workflows[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#workflows "Link to this heading") * Only run tests once (#924) [1.7.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.7.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id171 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-02-28 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id172 "Link to this heading") * Struct tag formatting (#833) ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id173 "Link to this heading") * Include all the existing Markdown files (#877) * Split docs into four sections (#882) * Reorganize and consolidate documentation * Add link to Windows download (#888) * Shorten the README (#889) ### Features[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id174 "Link to this heading") * Adding support for pgx/v4 * Adding support for pgx/v4 ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#readme "Link to this heading") * Add Go Report Card badge (#891) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id175 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.3 to 0.5.4 (#813) * Bump github.com/lib/pq from 1.8.0 to 1.9.0 (#820) * Bump golang from 1.15.5 to 1.15.6 (#822) * Bump github.com/jackc/pgx/v4 from 4.9.2 to 4.10.0 (#823) * Bump github.com/jackc/pgx/v4 from 4.10.0 to 4.10.1 (#839) * Bump golang from 1.15.6 to 1.15.7 (#855) * Bump golang from 1.15.7 to 1.15.8 (#881) * Bump github.com/spf13/cobra from 1.1.1 to 1.1.2 (#892) * Bump golang from 1.15.8 to 1.16.0 (#897) * Bump github.com/lfittl/pg\_query\_go from 1.0.1 to 1.0.2 (#901) * Bump github.com/spf13/cobra from 1.1.2 to 1.1.3 (#893) ### Catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#catalog "Link to this heading") * Improve alter column type (#818) ### Ci[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id176 "Link to this heading") * Uprade to Go 1.15 (#887) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id177 "Link to this heading") * Allow config file location to be specified (#863) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id178 "Link to this heading") * Bump to version v1.6.1-devel (#807) * Bump version to v1.7.0 (#912) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id179 "Link to this heading") * Make sure to import net package (#858) ### Compiler[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id180 "Link to this heading") * Support UNION query ### Dolphin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#dolphin "Link to this heading") * Generate bools for tinyint(1) * Support joins in update statements (#883) * Add support for union query ### Endtoend[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id181 "Link to this heading") * Add tests for INTERSECT and EXCEPT ### Go.mod[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#go-mod "Link to this heading") * Update to go 1.15 and run ‘go mod tidy’ (#808) ### Mysql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id182 "Link to this heading") * Compile tinyint(1) to bool (#873) ### Sql/ast[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id183 "Link to this heading") * Add enum values for SetOperation [1.6.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.6.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id184 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-11-23 ### Dolphin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id185 "Link to this heading") * Implement Rename (#651) * Skip processing view drops (#653) ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id186 "Link to this heading") * Update language / database support (#698) ### Astutils[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#astutils "Link to this heading") * Fix Params rewrite call (#674) ### Build[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id187 "Link to this heading") * Bump golang from 1.14 to 1.15.3 (#765) * Bump docker/build-push-action from v1 to v2.1.0 (#764) * Bump github.com/google/go-cmp from 0.4.0 to 0.5.2 (#766) * Bump github.com/spf13/cobra from 1.0.0 to 1.1.1 (#767) * Bump github.com/jackc/pgx/v4 from 4.6.0 to 4.9.2 (#768) * Bump github.com/lfittl/pg\_query\_go from 1.0.0 to 1.0.1 (#773) * Bump github.com/google/go-cmp from 0.5.2 to 0.5.3 (#783) * Bump golang from 1.15.3 to 1.15.5 (#782) * Bump github.com/lib/pq from 1.4.0 to 1.8.0 (#769) ### Catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id188 "Link to this heading") * Improve variadic argument support (#804) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id189 "Link to this heading") * Bump to version v1.6.0 (#806) ### Codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id190 "Link to this heading") * Fix errant database/sql imports (#789) ### Compiler[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id191 "Link to this heading") * Use engine-specific reserved keywords (#677) ### Dolphi[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#dolphi "Link to this heading") * Add list of builtin functions (#795) ### Dolphin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id192 "Link to this heading") * Update to the latest MySQL parser (#665) * Add ENUM() support (#676) * Add test for table aliasing (#684) * Add MySQL ddl\_create\_table test (#685) * Implete TRUNCATE table (#697) * Represent tinyint as int32 (#797) * Add support for coalesce (#802) * Add function signatures (#796) ### Endtoend[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id193 "Link to this heading") * Add MySQL json test (#692) * Add MySQL update set multiple test (#696) ### Examples[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id194 "Link to this heading") * Use generated enum constants in db\_test (#678) * Port ondeck to MySQL (#680) * Add MySQL authors example (#682) ### Internal/cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-cmd "Link to this heading") * Print correct config file on parse failure (#749) ### Kotlin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id195 "Link to this heading") * Remove runtime dependency (#774) ### Metadata[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#metadata "Link to this heading") * Support multiple comment prefixes (#683) ### Postgresql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id196 "Link to this heading") * Support string concat operator (#701) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sql-catalog "Link to this heading") * Add support for variadic functions (#798) [1.5.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.5.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id197 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-08-05 ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id198 "Link to this heading") * Build sqlc using Go 1.14 (#549) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id199 "Link to this heading") * Add debugging support (#573) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id200 "Link to this heading") * Bump version to v1.4.1-devel (#548) * Bump version to v1.5.0 ### Compiler[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id201 "Link to this heading") * Support calling functions with defaults (#635) * Skip func args without a paramRef (#636) * Return a single column from coalesce (#639) ### Config[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id202 "Link to this heading") * Add emit\_empty\_slices to version one (#552) ### Contrib[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#contrib "Link to this heading") * Add generated code for contrib ### Dinosql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#dinosql "Link to this heading") * Remove deprecated package (#554) ### Dolphin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id203 "Link to this heading") * Add support for column aliasing (#566) * Implement star expansion for subqueries (#619) * Implement exapansion with reserved words (#620) * Implement parameter refs (#621) * Implement limit and offest (#622) * Implement inserts (#623) * Implement delete (#624) * Implement simple update statements (#625) * Implement INSERT … SELECT (#626) * Use test driver instead of TiDB driver (#629) * Implement named parameters via sqlc.arg() (#632) ### Endtoend[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id204 "Link to this heading") * Add MySQL test for SELECT \* JOIN (#565) * Add MySQL test for inflection (#567) ### Engine[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#engine "Link to this heading") * Create engine package (#556) ### Equinox[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#equinox "Link to this heading") * Use the new equinox-io/setup action (#586) ### Examples[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id205 "Link to this heading") * Run tests for MySQL booktest (#627) ### Golang[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id206 "Link to this heading") * Add support for the money type (#561) * Generate correct types for int2 and int8 (#579) ### Internal[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal "Link to this heading") * Rm catalog, pg, postgres packages (#555) ### Mod[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#mod "Link to this heading") * Downgrade TiDB package to fix build (#603) ### Mysql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id207 "Link to this heading") * Upgrade to the latest vitess commit (#562) * Support to infer type of a duplicated arg (#615) * Allow some builtin functions to be nullable (#616) ### Postgresql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id208 "Link to this heading") * Generate all functions in pg\_catalog (#550) * Remove pg\_catalog schema from tests (#638) * Move contrib code to a package ### Sql/catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id209 "Link to this heading") * Fix comparison of pg\_catalog types (#637) ### Tools[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id210 "Link to this heading") * Generate functions for all of contrib ### Workflow[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#workflow "Link to this heading") * Migrate to equinox-io/setup-release-tool (#614) [1.4.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.4.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id211 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-06-17 ### Dockerfile[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#dockerfile "Link to this heading") * Add version build argument (#487) ### MySQL[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id212 "Link to this heading") * Prevent Panic when WHERE clause contains parenthesis. (#531) ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id213 "Link to this heading") * Document emit\_exact\_table\_names (#486) ### All[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#all "Link to this heading") * Remove the exp build tag (#507) ### Catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id214 "Link to this heading") * Support functions with table parameters (#541) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id215 "Link to this heading") * Bump to version 1.3.1-devel (#485) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id216 "Link to this heading") * Bump version to v1.4.0 (#547) ### Codegen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id217 "Link to this heading") * Add the new codegen packages (#513) * Add the :execresult query annotation (#542) ### Compiler[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id218 "Link to this heading") * Validate function calls (#505) * Port bottom of parseQuery (#510) * Don’t mutate table name (#517) * Enable experimental parser by default (#518) * Apply rename rules to enum constants (#523) * Temp fix for typecast function parameters (#530) ### Endtoend[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id219 "Link to this heading") * Standardize JSON formatting (#490) * Add per-test configuration files (#521) * Read expected stderr failures from disk (#527) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-dinosql "Link to this heading") * Check parameter style before ref (#488) * Remove unneeded column suffix (#492) * Support named function arguments (#494) ### Internal/postgresql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-postgresql "Link to this heading") * Fix NamedArgExpr rewrite (#491) ### Multierr[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#multierr "Link to this heading") * Move dinosql.ParserErr to a new package (#496) ### Named[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#named "Link to this heading") * Port parameter style validation to SQL (#504) ### Parser[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id220 "Link to this heading") * Support columns from subselect statements (#489) ### Rewrite[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#rewrite "Link to this heading") * Move parameter rewrite to package (#499) ### Sqlite[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id221 "Link to this heading") * Use convert functions instead of the listener (#519) ### Sqlpath[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sqlpath "Link to this heading") * Move ReadSQLFiles into a separate package (#495) ### Validation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#validation "Link to this heading") * Move query validation to separate package (#498) [1.3.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.3.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id222 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-05-12 ### Makefile[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#makefile "Link to this heading") * Update target (#449) ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id223 "Link to this heading") * Add Myles as a sponsor (#469) ### Testing[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id224 "Link to this heading") * Make sure all Go examples build (#480) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id225 "Link to this heading") * Bump version to v1.3.0 (#484) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id226 "Link to this heading") * Bump version to v1.2.1-devel (#442) ### Dinosql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id227 "Link to this heading") * Inline addFile (#446) * Add PostgreSQL support for TRUNCATE (#448) ### Gen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#gen "Link to this heading") * Emit json.RawMessage for JSON columns (#461) ### Go.mod[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id228 "Link to this heading") * Use latest lib/pq (#471) ### Parser[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id229 "Link to this heading") * Use same function to load SQL files (#483) ### Postgresql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id230 "Link to this heading") * Fix panic walking CreateTableAsStmt (#475) [1.2.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.2.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id231 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-04-07 ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id232 "Link to this heading") * Publish to Docker Hub (#422) ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id233 "Link to this heading") * Docker installation docs (#424) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id234 "Link to this heading") * Bump version to v1.1.1-devel (#407) * Bump version to v1.2.0 (#441) ### Gen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id235 "Link to this heading") * Add special case for “campus” (#435) * Properly quote reserved keywords on expansion (#436) ### Migrations[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#migrations "Link to this heading") * Move migration parsing to new package (#427) ### Parser[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id236 "Link to this heading") * Generate correct types for SELECT EXISTS (#411) [1.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.1.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id237 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-03-17 ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id238 "Link to this heading") * Add installation instructions (#350) * Add section on running tests (#357) * Fix typo (#371) ### Ast[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#ast "Link to this heading") * Add AST for ALTER TABLE ADD / DROP COLUMN (#376) * Add support for CREATE TYPE as ENUM (#388) * Add support for CREATE / DROP SCHEMA (#389) ### Astutils[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id239 "Link to this heading") * Apply changes to the ValuesList slice (#372) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id240 "Link to this heading") * Return v1.0.0 (#348) * Return next bug fix version (#349) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id241 "Link to this heading") * Bump version to v1.1.0 (#406) ### Compiler[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id242 "Link to this heading") * Wire up the experimental parsers ### Config[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id243 "Link to this heading") * Remove “emit\_single\_file” option (#367) ### Dolphin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id244 "Link to this heading") * Add experimental parser for MySQL ### Gen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id245 "Link to this heading") * Add option to emit single file for Go (#366) * Add support for the ltree extension (#385) ### Go.mod[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id246 "Link to this heading") * Add packages for MySQL and SQLite parsers ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id247 "Link to this heading") * Support Postgres macaddr type in Go (#358) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-endtoend "Link to this heading") * Remove %w (#354) ### Kotlin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id248 "Link to this heading") * Add Query class to support timeout and cancellation (#368) ### Postgresql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id249 "Link to this heading") * Add experimental parser for MySQL ### Sql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sql "Link to this heading") * Add generic SQL AST ### Sql/ast[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id250 "Link to this heading") * Port support for COMMENT ON (#391) * Implement DROP TYPE (#397) * Implement ALTER TABLE RENAME (#398) * Implement ALTER TABLE RENAME column (#399) * Implement ALTER TABLE SET SCHEMA (#400) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id251 "Link to this heading") * Port tests over from catalog pkg (#402) ### Sql/errors[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#sql-errors "Link to this heading") * Add a new errors package (#390) ### Sqlite[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id252 "Link to this heading") * Add experimental parser for SQLite [1.0.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.0.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id253 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-02-18 ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id254 "Link to this heading") * Add documentation for query commands (#270) * Add named parameter documentation (#332) ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id255 "Link to this heading") * Add sponsors section (#333) ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id256 "Link to this heading") * Remove parse subcommand (#322) ### Config[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id257 "Link to this heading") * Parse V2 config format * Add support for YAML (#336) ### Examples[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id258 "Link to this heading") * Add the jets and booktest examples (#237) * Move sqlc.json into examples folder (#238) * Add the authors example (#241) * Add build tag to authors tests (#319) ### Internal[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id259 "Link to this heading") * Allow CTE to be used with UPDATE (#268) * Remove the PackageMap from settings (#295) ### Internal/config[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id260 "Link to this heading") * Create new config package (#313) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id261 "Link to this heading") * Emit Querier interface (#240) * Strip leading “go-” or trailing “-go” from import (#262) * Overrides can now be basic types (#271) * Import needed types for Querier (#285) * Handle schema-scoped enums (#310) * Ignore golang-migrate rollbacks (#320) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id262 "Link to this heading") * Move more tests to the record/replay framework * Add update test for named params (#329) ### Internal/mysql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-mysql "Link to this heading") * Fix flaky test (#242) * Port tests to endtoend package (#315) ### Internal/parser[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-parser "Link to this heading") * Resolve nested CTEs (#324) * Error if last query is missing (#325) * Support joins with aliases (#326) * Remove print statement (#327) ### Internal/sqlc[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-sqlc "Link to this heading") * Add support for composite types (#311) ### Kotlin[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id263 "Link to this heading") * Support primitives * Arrays, enums, and dates * Generate examples * README for examples * Factor out db setup extension * Fix enums, use List instead of Array * Port Go tests for examples * Rewrite numbered params to positional params * Always use use, fix indents * Unbox query params ### Parser[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id264 "Link to this heading") * Attach range vars to insert params * Attach range vars to insert params (#342) * Remove dead code (#343) [0.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v0.1.0) [](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id265 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-01-07 ### Documentation[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id266 "Link to this heading") * Replace remaining references to DinoSQL with sqlc (#149) ### README[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id267 "Link to this heading") * Fix download links (#66) * Add LIMIT 1 to query that should return one (#99) ### Catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id268 "Link to this heading") * Support “ALTER TABLE … DROP CONSTRAINT …” (#34) * Differentiate functions with different argument types (#51) ### Ci[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id269 "Link to this heading") * Enable tests on pull requests ### Cmd[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id270 "Link to this heading") * Include filenames in error messages (#69) * Do not output any changes on error (#72) ### Dinosql/internal[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#dinosql-internal "Link to this heading") * Add lower and upper functions (#215) * Ignore alter sequence commands (#219) ### Gen[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id271 "Link to this heading") * Add DO NOT EDIT comments to generated code (#50) * Include all schemas when generating models (#90) * Prefix structs with schema name (#91) * Generate single import for uuid package (#98) * Use same import logic for all Go files * Pick correct struct to return for queries (#107) * Create consistent JSON tags (#110) * Add Close method to Queries struct (#127) * Ignore empty override settings (#128) * Turn SQL comments into Go comments (#136) ### Internal/catalog[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-catalog "Link to this heading") * Parse unnamed function arguments (#166) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id272 "Link to this heading") * Prepare() with no GoQueries still valid (#95) * Fix multiline comment rendering (#142) * Dereference alias nodes on walk (#158) * Ignore sql-migrate rollbacks (#160) * Sort imported packages (#165) * Add support for timestamptz (#169) * Error on missing queries (#180) * Use more database/sql null types (#182) * Support the pg\_temp schema (#183) * Override columns with array type (#184) * Implement robust expansion * Implement robust expansion (#186) * Add COMMENT ON support (#191) * Add DATE support * Add DATE support (#196) * Filter out invalid characters (#198) * Quote reserved keywords (#205) * Return parser errors first (#207) * Implement advisory locks (#212) * Error on duplicate query names (#221) * Fix incorrect enum names (#223) * Add support for numeric types * Add support for numeric types (#228) ### Internal/dinosql/testdata/ondeck[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#internal-dinosql-testdata-ondeck "Link to this heading") * Add Makefile (#156) ### Ondeck[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#ondeck "Link to this heading") * Move all tests to GitHub CI (#58) ### ParseQuery[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#parsequery "Link to this heading") * Return either a query or an error (#178) ### Parser[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#id273 "Link to this heading") * Use schema when resolving catalog refs (#82) * Support function calls in expressions (#104) * Correctly handle single files (#119) * Return error if missing RETURNING (#131) * Add support for mathmatical operators (#132) * Add support for simple case expressions (#134) * Error on mismatched INSERT input (#135) * Set IsArray on joined columns (#139) ### Pg[](https://docs.sqlc.dev/en/v1.30.0/reference/changelog.html#pg "Link to this heading") * Store functions in the catalog (#41) * Add location to errors (#73) --- # Changelog — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/stable/index.html) * Changelog * [View page source](https://docs.sqlc.dev/en/stable/_sources/reference/changelog.md.txt) * * * Changelog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#changelog "Link to this heading") ======================================================================================================== All notable changes to this project will be documented in this file. [1.31.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.31.1) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-31-1 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2026-04-22 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#bug-fixes "Link to this heading") * Remove go.mod replace directive that breaks `go install ...@latest` (#4401) * Downgrade github.com/ncruces/go-sqlite3 to v0.32.0 (#4400) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#build "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 (#4398) [1.31.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.31.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-31-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2026-04-19 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id3 "Link to this heading") * Strip psql meta-commands from schema files (#4390) * Emit pointers for nullable enum columns when `emit_pointers_for_null_types` is set (#4388) * Map xid8 to pgtype.Uint64 for pgx/v5 (#4387) * Rename `:one` return variable when it conflicts with a parameter (#4383) * Coerce SQLite JSONB output regardless of type casing (#4385) * Dedupe `sqlc.arg` parameters wrapped in a type cast for MySQL (#4384) * Preserve MySQL optimizer hints in generated query text (#4382) * Catch invalid `ON CONFLICT DO UPDATE` column references (#4366) * Replace manual loop with `copy()` builtin (#4166) * (native) Make MySQL connection check immediate on first attempt (#4254) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#documentation "Link to this heading") * Add link to community python plugin (#4157) * Add Claude Code remote environment setup instructions (#4246) * Add sqlc-gen-sqlx to community language support (#4371) * Add GitHub Topic to the plugins page (#4258) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#features "Link to this heading") * (sqlfile) Add `sqlfile.Split` (#4146) * (sqlite) Add database analyzer using ncruces/go-sqlite3 (#4199) * (ast) Implement comprehensive SQL AST formatting (#4205) * (mysql) Improve AST formatting and add DELETE JOIN support (#4206) * (sqlite) Add SQLite support to format tests (#4207) * (expander) Add star expander for `SELECT *` and `RETURNING *` (PostgreSQL, MySQL, SQLite) (#4203) * Add `SQLCEXPERIMENT` environment variable for experimental features (#4228) * Add native database support for e2e tests without Docker (#4236) * (postgresql) Add analyzerv2 experiment for database-only analysis (#4237) * Graduate parsecmd experiment (#4253) * Add parse subcommand with AST JSON output (#4240) * Add ClickHouse support to `sqlc parse` (#4267) * Add `sqlc-test-setup` command for database test environment setup (#4304) ### Refactor[](https://docs.sqlc.dev/en/stable/reference/changelog.html#refactor "Link to this heading") * (ast) Rename Formatter interface to Dialect (#4208) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id4 "Link to this heading") * Upgrade Go toolchain to 1.26.2 (#4378) * Upgrade Go version to 1.26.0 (#4312) * Remove github.com/jackc/pgx/v4 dependency (#4379) * Upgrade github.com/pingcap/tidb/pkg/parser (#4389) * Install PostgreSQL from theseus-rs/postgresql-binaries instead of apt (#4310) * Skip CI/RTD builds when the change is irrelevant (#4381) * (deps) 35 dependabot bumps (collapsed from individual entries) [1.30.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.30.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-30-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-09-01 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id6 "Link to this heading") * (compiler/mysql) Prevent panic in convertSetOprSelectList() (#4042) * Range subselect alias pointer dereference (#3711) * (codegen/golang) Don’t omit enums used as arrays (#4058) * (codegen/golang) Handle `go_struct_tag` for `db_type` overrides (#4055) * (engine/dolphin) Remove references to deprecated `pcast.ChangeStmt` (#4057) * Normalize identifier usage for table names (#4045) * (engine/sqlite) Fix parsing of INSERT DEFAULT VALUES syntax (#4010) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id7 "Link to this heading") * Fix parameter syntax inconsistency for MySQL and SQLite (#4036) * Use correct configuration to generate the given output for JSON type override (#4049) * Clean up and add to docs regarding type overrides (#4060) * Try a different admonition format (#4061) * Use the correct admonition format (#4062) * Add multi-worded table example for renaming (#4067) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id8 "Link to this heading") * (docs) Add link to Gleam/parrot (#4038) * (engine/dolphin) Implement MATCH\_AGAINST conversion in SQL AST (#1192, #3091) (#4070) * (engine/sqlite) Coerce jsonb columns to json before returning to Go code (#3968) ### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#testing "Link to this heading") * (endtoend) Skip process\_plugin\_sqlc\_gen\_json (#4075) * (endtoend) Use Docker to start database servers (#4076) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id9 "Link to this heading") * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3941) * (deps) Bump packaging (#3940) * (deps) Bump golang from 1.24.2 to 1.24.4 (#3983) * (deps) Bump golang from 1.24.4 to 1.24.5 (#4014) * (deps) Bump urllib3 from 2.4.0 to 2.5.0 in /docs (#3994) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3989) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4027) * (deps) Bump modernc.org/sqlite (#4032) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4018) * (deps) Bump certifi in /docs in the production-dependencies group (#4041) * (deps) Bump google.golang.org/protobuf (#4043) * (deps) Bump actions/checkout from 4 to 5 (#4059) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#4071) * (deps) Bump requests in /docs in the production-dependencies group (#4068) * Upgrade to Go 1.25 (#4074) * (deps) Bump golang from 1.24.5 to 1.25.0 (#4063) * (deps) Bump github.com/google/cel-go (#4080) [1.29.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.29.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-29-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-04-14 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id11 "Link to this heading") * (docs) Correct spelling and grammar (#3645) * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) * (pgx) Do not wrap nil error (#3913) * (migrations) Normalize case for migration statement for all cases (#3919) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id12 "Link to this heading") * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Add changelog for 1.28.0 (#3797) * Add PHP DBAL plugin (#3813) * Fix PostGIS function name (#3829) * Add Zig plugin (#3824) * Add link to tandemdude/sqlc-gen-java (#3819) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id13 "Link to this heading") * (docs) How-to use transactions with pgx (#3557) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) * (mysql) Add a test for VECTOR column type (#3734) * (cli) Bump version from 1.27.0 to 1.28.0 (#3798) * (codegen/golang) Add an option to wrap query errors that includes query name (#3876) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#miscellaneous-tasks "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) * Update sqlc-gen-java supported engines (#3843) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id14 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) * (deps) Bump golang.org/x/net from 0.30.0 to 0.33.0 (#3796) * (deps) Bump golang from 1.23.5 to 1.23.6 (#3822) * Use govulncheck action (#3831) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3817) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3826) * (deps) Bump golang from 1.23.6 to 1.24.0 (#3842) * (deps) Bump myst-parser (#3841) * (deps) Bump modernc.org/sqlite (#3846) * (deps) Bump golang from 1.24.0 to 1.24.1 (#3870) * (deps) Bump jinja2 in /docs in the production-dependencies group (#3872) * Upgrade to wazero@v1.9.0 (#3887) * Upgrade to Go 1.24.1 (#3892) * Upgrade to latest version of MySQL parser (#3893) * (deps) Bump pyparsing (#3890) * (deps) Bump golang.org/x/net from 0.33.0 to 0.37.0 (#3894) * (deps) Bump the production-dependencies group across 1 directory with 8 updates (#3896) * (deps) Bump github.com/jackc/pgx/v5 (#3898) * (deps) Bump the production-dependencies group (#3899) * (deps) Bump modernc.org/sqlite (#3905) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3914) * (deps) Bump urllib3 in /docs in the production-dependencies group (#3926) * (deps) Bump golang from 1.24.1 to 1.24.2 (#3915) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3923) * (deps) Upgrade github.com/wasilibs/go-pgquery (#3927) [1.28.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.28.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-28-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-01-20 ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id16 "Link to this heading") * (mysql) Add a test for VECTOR column type (#3734) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id17 "Link to this heading") * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id18 "Link to this heading") * How-to use transactions with pgx (#3557) * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Correct spelling and grammar (#3645) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id19 "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id20 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) [1.27.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.27.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-27-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-08-05 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id22 "Link to this heading") * (dbmanager) Add leading slash to db uri path rewrite (#3493) * (verify) Include database engine in request (#3522) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id23 "Link to this heading") * (golang) Add initialisms configuration (#3308) * (compiler) Support subqueries in the FROM clause (second coming) (#3310) * Managed databases with any accessible server (#3421) * (vet) Use new dbmanager client (#3423) * (verify) Update verify to work with managed databases (#3425) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id24 "Link to this heading") * Fix typo in config (#3358) * Resolve a typo in configuration keys (#3349) * Add sponsorship information to README (#3413) * Update the language-support to include C# (#3408) * Add migration guide for hosted managed databases (#3417) * Fix readme links (#3424) * Update the managed db and verify documentation (#3426) * Add sponsor image (#3428) * Add Ruby as supported language (#3487) * Update migrating-to-sqlc-gen-kotlin.md (#3454) * Fix typo in comment (#3316) * Fix deprecated build tag format (#3361) ### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id25 "Link to this heading") * (endtoend) Re-use databases when possible (#3315) * Enabled MySQL database (#3318) * Remove internal/sqltest/hosted package (#3521) [1.26.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.26.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-26-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-03-28 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#release-notes "Link to this heading") This release is mainly a bug fix release. It also includes an [important security fix](https://github.com/sqlc-dev/sqlc/issues/3194) for users using output plugins. ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#changes "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id27 "Link to this heading") * (docker) Use distroless base image instead of scratch (#3111) * (generate) Ensure files are created inside output directory (#3195) * (mysql) BREAKING: Use `int16` for MySQL `SMALLINT` and `YEAR` (#3106) * (mysql) BREAKING: Use `int8` for MySQL TINYINT (#3298) * (mysql) Variables not resolving in ORDER BY statements (#3115) * (opts) Validate SQL package and driver options (#3241) * (postgres/batch) Ignore query\_parameter\_limit for batches * (scripts) Remove deprecated test output regeneration script (#3105) * (sqlite) Correctly skip unknown statements (#3239) #### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id28 "Link to this heading") * (postgres) Add instructions for PostGIS/GEOS (#3182) * Improve details on TEXT (#3247) #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id29 "Link to this heading") * (generate) Avoid generating empty Go imports (#3135) * (mysql) Add NEXTVAL() to the MySQL catalog (#3147) * (mysql) Support json.RawMessage for LOAD DATA INFILE (#3099) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id30 "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 to 5.5.5 (#3259) * (deps) Bump modernc.org/sqlite to 1.29.5 (#3200) * (deps) Bump github.com/go-sql-driver/mysql to 1.8.0 (#3257) * (deps) Bump github.com/tetratelabs/wazero to 1.7.0 (#3096) * (deps) Bump github.com/pganalyze/pg\_query\_go to v5 (#3096) [1.25.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.25.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-25-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-01-03 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id32 "Link to this heading") #### Add tags to push and verify[](https://docs.sqlc.dev/en/stable/reference/changelog.html#add-tags-to-push-and-verify "Link to this heading") You can add tags when [pushing](https://docs.sqlc.dev/en/stable/howto/push.html) schema and queries to [sqlc Cloud](https://dashboard.sqlc.dev/) . Tags operate like git tags, meaning you can overwrite previously-pushed tag values. We suggest tagging pushes to associate them with something relevant from your environment, e.g. a git tag or branch name. $ sqlc push --tag v1.0.0 Once you’ve created a tag, you can refer to it when [verifying](https://docs.sqlc.dev/en/stable/howto/verify.html) changes, allowing you to compare the existing schema against a known set of previous queries. $ sqlc verify --against v1.0.0 #### C-ya, `cgo`[](https://docs.sqlc.dev/en/stable/reference/changelog.html#c-ya-cgo "Link to this heading") Over the last month, we’ve switched out a few different modules to remove our reliance on [cgo](https://go.dev/blog/cgo) . Previously, we needed cgo for three separate functions: * Parsing PostgreSQL queries with [pganalyze/pg\_query\_go](https://github.com/pganalyze/pg_query_go) * Running SQLite databases with [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) * Executing WASM / WASI code with [bytecodealliance/wasmtime-go](https://github.com/bytecodealliance/wasmtime-go) With the help of the community, we found cgo-free alternatives for each module: * Parsing PostgreSQL queries, now using [wasilibs/go-pgquery](https://github.com/wasilibs/go-pgquery) * Running SQLite databases, now using [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) * Executing WASM / WASI code, now using [tetratelabs/wazero](https://github.com/tetratelabs/wazero) For the first time, Windows users can enjoy full PostgreSQL support without using [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) . It’s a Christmas miracle! If you run into any issues with the updated dependencies, please [open an issue](https://github.com/sqlc-dev/sqlc/issues) . ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id33 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id34 "Link to this heading") * (codegen) Wrong yaml annotation in go codegen options for output\_querier\_file\_name (#3006) * (codegen) Use derived ArrayDims instead of deprecated attndims (#3032) * (codegen) Take the maximum array dimensions (#3034) * (compiler) Skip analysis of queries without a `name` annotation (#3072) * (codegen/golang) Don’t import `"strings"` for `sqlc.slice()` with pgx (#3073) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id35 "Link to this heading") * Add name to query set configuration (#3011) * Add a sidebar link for `push`, add Go plugin link (#3023) * Update banner for sqlc-gen-typescript (#3036) * Add strict\_order\_by in doc (#3044) * Re-order the migration tools list (#3064) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id36 "Link to this heading") * (analyzer) Return zero values when encountering unexpected ast nodes (#3069) * (codegen/go) add omit\_sqlc\_version to Go code generation (#3019) * (codgen/go) Add `emit_sql_as_comment` option to Go code plugin (#2735) * (plugins) Use wazero instead of wasmtime (#3042) * (push) Add tag support (#3074) * (sqlite) Support emit\_pointers\_for\_null\_types (#3026) ### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id37 "Link to this heading") * (endtoend) Enable for more build targets (#3041) * (endtoend) Run MySQL and PostgreSQL locally on the runner (#3095) * (typescript) Test against sqlc-gen-typescript (#3046) * Add tests for omit\_sqlc\_version (#3020) * Split schema and query for test (#3094) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id38 "Link to this heading") * (deps) Bump idna from 3.4 to 3.6 in /docs (#3010) * (deps) Bump sphinx-rtd-theme from 1.3.0 to 2.0.0 in /docs (#3016) * (deps) Bump golang from 1.21.4 to 1.21.5 (#3043) * (deps) Bump actions/setup-go from 4 to 5 (#3047) * (deps) Bump github.com/jackc/pgx/v5 from 5.5.0 to 5.5.1 (#3050) * (deps) Upgrade to latest version of github.com/wasilibs/go-pgquery (#3052) * (deps) Bump google.golang.org/grpc from 1.59.0 to 1.60.0 (#3053) * (deps) Bump babel from 2.13.1 to 2.14.0 in /docs (#3055) * (deps) Bump actions/upload-artifact from 3 to 4 (#3061) * (deps) Bump modernc.org/sqlite from 1.27.0 to 1.28.0 (#3062) * (deps) Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#3068) * (deps) Bump google.golang.org/grpc from 1.60.0 to 1.60.1 (#3070) * (deps) Bump google.golang.org/protobuf from 1.31.0 to 1.32.0 (#3079) * (deps) Bump github.com/tetratelabs/wazero from 1.5.0 to 1.6.0 (#3096) * (sqlite) Update to antlr 4.13.1 (#3086) * (sqlite) Disable modernc for WASM (#3048) * (sqlite) Switch from mattn/go-sqlite3 to modernc.org/sqlite (#3040) [1.24.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.24.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-24-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-11-22 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id40 "Link to this heading") #### Verifying database schema changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#verifying-database-schema-changes "Link to this heading") Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. #### Rename `upload` command to `push`[](https://docs.sqlc.dev/en/stable/reference/changelog.html#rename-upload-command-to-push "Link to this heading") We’ve renamed the `upload` sub-command to `push`. We changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. We also add annotations to each push. By default, we include these environment variables if they are present: GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA Like upload, `push` should be run when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. #### MySQL support in `createdb`[](https://docs.sqlc.dev/en/stable/reference/changelog.html#mysql-support-in-createdb "Link to this heading") The `createdb` command, added in the last release, now supports MySQL. If you have a cloud project configured, you can use `sqlc createdb` to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html#with-other-tools) documentation. #### Plugin interface refactor[](https://docs.sqlc.dev/en/stable/reference/changelog.html#plugin-interface-refactor "Link to this heading") This release includes a refactored plugin interface to better support future functionality. Plugins now support different methods via a gRPC service interface, allowing plugins to support different functionality in a backwards-compatible way. By using gRPC interfaces, we can even (theoretically) support [remote plugins](https://github.com/sqlc-dev/sqlc/pull/2938) , but that’s something for another day. ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id41 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id42 "Link to this heading") * (engine/sqlite) Support CASE expr (#2926) * (engine/sqlite) Support -> and ->> operators (#2927) * (vet) Add a nil pointer check to prevent db/prepare panic (#2934) * (compiler) Prevent panic when compiler is nil (#2942) * (codegen/golang) Move more Go-specific config validation into the plugin (#2951) * (compiler) No panic on full-qualified column names (#2956) * (docs) Better discussion of type override nuances (#2972) * (codegen) Never generate return structs for :exec (#2976) * (generate) Update help text for generate to be more generic (#2981) * (generate) Return an error instead of generating duplicate Go names (#2962) * (codegen/golang) Pull opts into its own package (#2920) * (config) Make some struct and field names less confusing (#2922) #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id43 "Link to this heading") * (codegen) Remove Go specific overrides from codegen proto (#2929) * (plugin) Use gRPC interface for codegen plugin communication (#2930) * (plugin) Calculate SHA256 if it does not exist (#2935) * (sqlc-gen-go) Add script to mirror code to sqlc-gen-go (#2952) * (createdb) Add support for MySQL (#2980) * (verify) Add new command to verify queries and migrations (#2986) #### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id44 "Link to this heading") * (ci) New workflow for sqlc-gen-python (#2936) * (ci) Rely on go.mod to determine which Go version to use (#2971) * (tests) Add glob pattern tests to sqlpath.Glob (#2995) * (examples) Use hosted MySQL databases for tests (#2982) * (docs) Clean up a little, update LICENSE and README (#2941) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id45 "Link to this heading") * (deps) Bump babel from 2.13.0 to 2.13.1 in /docs (#2911) * (deps) Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2944) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.17 to 1.14.18 (#2945) * (deps) Bump golang.org/x/sync from 0.4.0 to 0.5.0 (#2946) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2947) * (deps) Change github.com/pingcap/tidb/parser to github.com/pingcap/tidb/pkg/parser * (deps) Bump github.com/google/cel-go from 0.18.1 to 0.18.2 (#2969) * (deps) Bump urllib3 from 2.0.7 to 2.1.0 in /docs (#2975) * (buf) Change root of Buf module (#2987) * (deps) Bump certifi from 2023.7.22 to 2023.11.17 in /docs (#2993) * (ci) Bump Go version from 1.21.3 to 1.21.4 in workflows and Dockerfile (#2961) [1.23.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.23.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-23-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-10-24 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id47 "Link to this heading") #### Database-backed query analysis[](https://docs.sqlc.dev/en/stable/reference/changelog.html#database-backed-query-analysis "Link to this heading") With a [database connection](https://docs.sqlc.dev/en/stable/reference/config.html#database) configured, `sqlc generate` will gather metadata from that database to support its query analysis. Turning this on resolves a [large number of issues](https://github.com/sqlc-dev/sqlc/issues?q=is%3Aissue+label%3Aanalyzer) in the backlog related to type inference and more complex queries. The easiest way to try it out is with [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html) . The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. #### New `createdb` command[](https://docs.sqlc.dev/en/stable/reference/changelog.html#new-createdb-command "Link to this heading") When you have a cloud project configured, you can use the new `sqlc createdb` command to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html#with-other-tools) documentation. #### Support for pgvector[](https://docs.sqlc.dev/en/stable/reference/changelog.html#support-for-pgvector "Link to this heading") If you’re using [pgvector](https://github.com/pgvector/pgvector) , say goodbye to custom overrides! sqlc now generates code using [pgvector-go](https://github.com/pgvector/pgvector-go#pgx) as long as you’re using `pgx`. The pgvector extension is also available in [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html) . #### Go build tags[](https://docs.sqlc.dev/en/stable/reference/changelog.html#go-build-tags "Link to this heading") With the new `emit_build_tags` configuration parameter you can set build tags for sqlc to add at the top of generated source files. ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id48 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id49 "Link to this heading") * (codegen) Correct column names in :copyfrom (#2838) * (compiler) Search SELECT and UPDATE the same way (#2841) * (dolphin) Support more UNIONs for MySQL (#2843) * (compiler) Account for parameters without parents (#2844) * (postgresql) Remove temporary pool config (#2851) * (golang) Escape reserved keywords (#2849) * (mysql) Handle simplified CASE statements (#2852) * (engine/dolphin) Support enum in ALTER definition (#2680) * (mysql) Add, drop, rename and change enum values (#2853) * (config) Validate `database` config in all cases (#2856) * (compiler) Use correct func signature for `CommentSyntax` on windows (#2867) * (codegen/go) Prevent filtering of embedded struct fields (#2868) * (compiler) Support functions with OUT params (#2865) * (compiler) Pull in array information from analyzer (#2864) * (analyzer) Error on unexpanded star expression (#2882) * (vet) Remove rollback statements from DDL (#2895) #### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id50 "Link to this heading") * Add stable anchors to changelog (#2784) * Fix typo in v1.22.0 changelog (#2796) * Add sqlc upload to CI / CD guide (#2797) * Fix broken link, add clarity to plugins doc (#2813) * Add clarity and reference to JSON tags (#2819) * Replace form with dashboard link (#2840) * (examples) Update examples to use pgx/v5 (#2863) * Use docker compose v2 and update MYSQL\_DATABASE env var (#2870) * Update getting started guides, use pgx for Postgres guide (#2891) * Use managed databases in PostgreSQL getting started guide (#2892) * Update managed databases doc to discuss codegen (#2897) * Add managed dbs to CI/CD and vet guides (#2896) * Document database-backed query analyzer (#2904) #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id51 "Link to this heading") * (codegen) Support setting Go build tags (#2012) (#2807) * (generate) Reorder codegen handlers to prefer plugins (#2814) * (devenv) Add vscode settings.json with auto newline (#2834) * (cmd) Support sqlc.yml configuration file (#2828) * (analyzer) Analyze queries using a running PostgreSQL database (#2805) * (sql/ast) Render AST to SQL (#2815) * (codegen) Include plugin information (#2846) * (postgresql) Add ALTER VIEW … SET SCHEMA (#2855) * (compiler) Parse query parameter metadata from comments (#2850) * (postgresql) Support system columns on tables (#2871) * (compiler) Support LEFT JOIN on aliased table (#2873) * Improve messaging for common cloud config and rpc errors (#2885) * Abort compiler when rpc fails as unauthenticated (#2887) * (codegen) Add support for pgvector and pgvector-go (#2888) * (analyzer) Cache query analysis (#2889) * (createdb) Create ephemeral databases (#2894) * (debug) Add databases=managed debug option (#2898) * (config) Remove managed database validation (#2901) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id52 "Link to this heading") * (endtoend) Fix test output for do tests (#2782) #### Refactor[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id53 "Link to this heading") * (codegen) Remove golang and json settings from plugin proto (#2822) * (codegen) Removed deprecated code and improved speed (#2899) #### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id54 "Link to this heading") * (endtoend) Split shema and queries (#2803) * Fix a few incorrect testcases (#2804) * (analyzer) Add more database analyzer test cases (#2854) * Add more analyzer test cases (#2866) * Add more test cases for new analyzer (#2879) * (endtoend) Enabled managed-db tests in CI (#2883) * Enabled pgvector tests for managed dbs (#2893) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id55 "Link to this heading") * (deps) Bump packaging from 23.1 to 23.2 in /docs (#2791) * (deps) Bump urllib3 from 2.0.5 to 2.0.6 in /docs (#2798) * (deps) Bump babel from 2.12.1 to 2.13.0 in /docs (#2799) * (deps) Bump golang.org/x/sync from 0.3.0 to 0.4.0 (#2810) * (deps) Bump golang from 1.21.1 to 1.21.2 (#2811) * (deps) Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (#2826) * (deps) Bump golang from 1.21.2 to 1.21.3 (#2824) * (deps) Bump google.golang.org/grpc from 1.58.2 to 1.58.3 (#2825) * (deps) Bump golang.org/x/net from 0.12.0 to 0.17.0 (#2836) * (deps) Bump urllib3 from 2.0.6 to 2.0.7 in /docs (#2872) * (deps) Bump google.golang.org/grpc from 1.58.3 to 1.59.0 (#2876) * (deps) Upgrade wasmtime-go from 13.0.0 to 14.0.0 (#2900) #### Ci[](https://docs.sqlc.dev/en/stable/reference/changelog.html#ci "Link to this heading") * Bump go version in workflows (#2835) [1.22.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.22.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-22-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-26 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id57 "Link to this heading") #### Managed databases for `sqlc vet`[](https://docs.sqlc.dev/en/stable/reference/changelog.html#managed-databases-for-sqlc-vet "Link to this heading") If you’re using [sqlc vet](https://docs.sqlc.dev/en/stable/howto/vet.html) to write rules that require access to a running database, `sqlc` can now start and manage that database for you. PostgreSQL support is available today, with MySQL on the way. When you turn on managed databases, `sqlc` will use your schema to create a template database that it can copy to make future runs of `sqlc vet` very performant. This feature relies on configuration obtained via [sqlc Cloud](https://dashboard.sqlc.dev/) . Read more in the [managed databases](https://docs.sqlc.dev/en/stable/howto/managed-databases.html) documentation. ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id58 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id59 "Link to this heading") * (codegen/golang) Refactor imports code to match templates (#2709) * (codegen/golang) Support name type (#2715) * (wasm) Move Runner struct to shared file (#2725) * (engine/sqlite) Fix grammer to avoid missing join\_constraint (#2732) * (convert) Support YAML anchors in plugin options (#2733) * (mysql) Disallow time.Time in mysql :copyfrom queries, not all queries (#2768) * (engine/sqlite) Fix convert process for VALUES (#2737) #### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id60 "Link to this heading") * Clarify nullable override behavior (#2753) * Add managed databases to sidebar (#2764) * Pull renaming and type overrides into separate sections (#2774) * Update the docs banner for managed dbs (#2775) #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id61 "Link to this heading") * (config) Enables the configuration of copyfrom.go similar to quierer and friends (#2727) * (vet) Run rules against a managed database (#2751) * (upload) Point upload command at new endpoint (#2772) * (compiler) Support DO statements (#2777) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id62 "Link to this heading") * (endtoend) Skip tests missing secrets (#2763) * Skip certain tests on PRs (#2769) #### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id63 "Link to this heading") * (endtoend) Verify all schemas in endtoend (#2744) * (examples) Use a hosted database for example testing (#2749) * (endtoend) Pull region from environment (#2750) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id64 "Link to this heading") * (deps) Bump golang from 1.21.0 to 1.21.1 (#2711) * (deps) Bump google.golang.org/grpc from 1.57.0 to 1.58.1 (#2743) * (deps) Bump wasmtime-go from v12 to v13 (#2756) * (windows) Downgrade to mingw 11.2.0 (#2757) * (deps) Bump urllib3 from 2.0.4 to 2.0.5 in /docs (#2747) * (deps) Bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#2758) * (deps) Bump github.com/google/cel-go from 0.18.0 to 0.18.1 (#2778) #### Ci[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id65 "Link to this heading") * Bump go version to latest in ci workflows (#2722) [1.21.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.21.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-21-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-06 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id67 "Link to this heading") This is primarily a bugfix release, along with some documentation and testing improvements. #### MySQL engine improvements[](https://docs.sqlc.dev/en/stable/reference/changelog.html#mysql-engine-improvements "Link to this heading") `sqlc` previously didn’t know how to parse a `CALL` statement when using the MySQL engine, which meant it was impossible to use sqlc with stored procedures in MySQL databases. Additionally, `sqlc` now supports `IS [NOT] NULL` in queries. And `LIMIT` and `OFFSET` clauses now work with `UNION`. #### SQLite engine improvements[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sqlite-engine-improvements "Link to this heading") GitHub user [@orisano](https://github.com/orisano) continues to bring bugfixes and improvements to `sqlc`’s SQLite engine. See the “Changes” section below for the full list. #### Plugin access to environment variables[](https://docs.sqlc.dev/en/stable/reference/changelog.html#plugin-access-to-environment-variables "Link to this heading") If you’re authoring a [sqlc plugin](https://docs.sqlc.dev/en/stable/reference/changelog.html#../guides/plugins.html) , you can now configure sqlc to pass your plugin the values of specific environment variables. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id68 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id69 "Link to this heading") * Myriad string formatting changes (#2558) * (engine/sqlite) Support quoted identifier (#2556) * (engine/sqlite) Fix compile error (#2564) * (engine/sqlite) Fixed detection of column alias without AS (#2560) * (ci) Bump go version to 1.20.7 (#2568) * Remove references to deprecated `--experimental` flag (#2567) * (postgres) Fixed a problem with array dimensions disappearing when using “ALTER TABLE ADD COLUMN” (#2572) * Remove GitHub sponsor integration (#2574) * (docs) Improve discussion of prepared statements support (#2604) * (docs) Remove multidimensional array qualification in datatypes.md (#2619) * (config) Go struct tag parsing (#2606) * (compiler) Fix to not scan children under ast.RangeSubselect when retrieving table listing (#2573) * (engine/sqlite) Support NOT IN (#2587) * (codegen/golang) Fixed detection of the used package (#2597) * (engine/dolphin) Fixed problem that LIMIT OFFSET cannot be used with `UNION ALL` (#2613) * (compiler) Support identifiers with schema (#2579) * (compiler) Fix column expansion to work with quoted non-keyword identifiers (#2576) * (codegen/go) Compare define type in codegen (#2263) (#2578) * (engine/sqlite) Fix ast when using compound operator (#2673) * (engine/sqlite) Fix to handle join clauses correctly (#2674) * (codegen) Use correct Go types for bit strings and cid/oid/tid/xid with pgx/v4 (#2668) * (endtoend) Ensure all SQL works against PostgreSQL (#2684) #### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id70 "Link to this heading") * Update Docker installation instructions (#2552) * Missing emit\_pointers\_for\_null\_types configuration option in version 2 (#2682) (#2683) * Fix typo (#2697) * Document sqlc.\* macros (#2698) * (mysql) Document parseTimet=true requirement (#2699) * Add atlas to the list of supported migration frameworks (#2700) * Minor updates to insert howto (#2701) #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id71 "Link to this heading") * (endtoend/testdata) Added two sqlite `CAST` tests and rearranged postgres tests for same (#2551) * (docs) Add a reference to type overriding in datatypes.md (#2557) * (engine/sqlite) Support COLLATE for sqlite WHERE clause (#2554) * (mysql) Add parser support for IS \[NOT\] NULL (#2651) * (engine/dolphin) Support CALL statement (#2614) * (codegen) Allow plugins to access environment variables (#2669) * (config) Add JSON schema files for configs (#2703) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id72 "Link to this heading") * Ignore Vim swap files (#2616) * Fix typo (#2696) #### Refactor[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id73 "Link to this heading") * (astutils) Remove redundant nil check in `Walk` (#2660) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id74 "Link to this heading") * (deps) Bump wasmtime from v8.0.0 to v11.0.0 (#2553) * (deps) Bump golang from 1.20.6 to 1.20.7 (#2563) * (deps) Bump chardet from 5.1.0 to 5.2.0 in /docs (#2562) * (deps) Bump github.com/pganalyze/pg\_query\_go/v4 (#2583) * (deps) Bump golang from 1.20.7 to 1.21.0 (#2596) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.2 to 5.4.3 (#2582) * (deps) Bump pygments from 2.15.1 to 2.16.1 in /docs (#2584) * (deps) Bump sphinxcontrib-applehelp from 1.0.4 to 1.0.7 in /docs (#2620) * (deps) Bump sphinxcontrib-qthelp from 1.0.3 to 1.0.6 in /docs (#2622) * (deps) Bump github.com/google/cel-go from 0.17.1 to 0.17.6 (#2650) * (deps) Bump sphinxcontrib-serializinghtml in /docs (#2641) * Upgrade from Go 1.20 to Go 1.21 (#2665) * (deps) Bump sphinxcontrib-devhelp from 1.0.2 to 1.0.5 in /docs (#2621) * (deps) Bump github.com/bytecodealliance/wasmtime-go from v11.0.0 to v12.0.0 (#2666) * (deps) Bump sphinx-rtd-theme from 1.2.2 to 1.3.0 in /docs (#2670) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.1 to 2.0.4 in /docs (#2671) * (deps) Bump github.com/google/cel-go from 0.17.6 to 0.18.0 (#2691) * (deps) Bump actions/checkout from 3 to 4 (#2694) * (deps) Bump pytz from 2023.3 to 2023.3.post1 in /docs (#2695) * (devenv) Bump go from 1.20.7 to 1.21.0 (#2702) [1.20.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.20.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#v1-20-0 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-31 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id76 "Link to this heading") #### `kyleconroy/sqlc` is now `sqlc-dev/sqlc`[](https://docs.sqlc.dev/en/stable/reference/changelog.html#kyleconroy-sqlc-is-now-sqlc-dev-sqlc "Link to this heading") We’ve completed our migration to the [sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc) repository. All existing links and installation instructions will continue to work. If you’re using the `go` tool to install `sqlc`, you’ll need to use the new import path to get v1.20.0 (and all future versions). \# INCORRECT: old import path go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.20.0 \# CORRECT: new import path go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.20.0 We designed the upgrade process to be as smooth as possible. If you run into any issues, please [file a bug report](https://github.com/sqlc-dev/sqlc/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=BUG_REPORT.yml) via GitHub. #### Use `EXPLAIN ...` output in lint rules[](https://docs.sqlc.dev/en/stable/reference/changelog.html#use-explain-output-in-lint-rules "Link to this heading") `sqlc vet` can now run `EXPLAIN` on your queries and include the results for use in your lint rules. For example, this rule checks that `SELECT` queries use an index. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- has-index rules: \- name: has-index rule: \> query.sql.startsWith("SELECT") && !(postgresql.explain.plan.plans.all(p, has(p.index\_name) || p.plans.all(p, has(p.index\_name)))) The expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/stable/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. #### Opting-out of lint rules[](https://docs.sqlc.dev/en/stable/reference/changelog.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; #### Bulk insert for MySQL[](https://docs.sqlc.dev/en/stable/reference/changelog.html#bulk-insert-for-mysql "Link to this heading") _Developed by [@Jille](https://github.com/Jille) _ MySQL now supports the `:copyfrom` query annotation. The generated code uses the [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) command to insert data quickly and efficiently. Use caution with this feature. Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use `SHOW WARNINGS` to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } `LOAD DATA` support must be enabled in the MySQL server. #### CAST support for MySQL[](https://docs.sqlc.dev/en/stable/reference/changelog.html#cast-support-for-mysql "Link to this heading") _Developed by [@ryanpbrewster](https://github.com/ryanpbrewster) and [@RadhiFadlillah](https://github.com/RadhiFadlillah) _ `sqlc` now understands `CAST` calls in MySQL queries, offering greater flexibility when generating code for complex queries. CREATE TABLE foo (bar BOOLEAN NOT NULL); \-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo; package querytest import ( "context" ) const selectColumnCast \= \`-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo \` func (q \*Queries) SelectColumnCast(ctx context.Context) (\[\]int64, error) { ... } #### SQLite improvements[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sqlite-improvements "Link to this heading") A slew of fixes landed for our SQLite implementation, bringing it closer to parity with MySQL and PostgreSQL. We want to thank [@orisano](https://github.com/orisano) for their continued dedication to improving `sqlc`’s SQLite support. ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id77 "Link to this heading") #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id78 "Link to this heading") * (debug) Add debug flag and docs for dumping vet rule variables (#2521) * (mysql) :copyfrom support via LOAD DATA INFILE (#2545) * (mysql) Implement cast function parser (#2473) * (postgresql) Add support for PostgreSQL multi-dimensional arrays (#2338) * (sql/catalog) Support ALTER TABLE IF EXISTS (#2542) * (sqlite) Virtual tables and fts5 supported (#2531) * (vet) Add default query parameters for explain queries (#2543) * (vet) Add output from `EXPLAIN ...` for queries to the CEL program environment (#2489) * (vet) Introduce a query annotation to opt out of sqlc vet rules (#2474) * Parse comment lines starting with `@symbol` as boolean flags associated with a query (#2464) #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id79 "Link to this heading") * (codegen/golang) Fix sqlc.embed to work with pq.Array (#2544) * (compiler) Correctly validate alias in order/group by clauses for joins (#2537) * (engine/sqlite) Added function to convert cast node (#2470) * (engine/sqlite) Fix join\_operator rule (#2434) * (engine/sqlite) Fix table\_alias rules (#2465) * (engine/sqlite) Fixed IN operator precedence (#2428) * (engine/sqlite) Fixed to be able to find relation from WITH clause (#2444) * (engine/sqlite) Lowercase ast.ResTarget.Name (#2433) * (engine/sqlite) Put logging statement behind debug flag (#2488) * (engine/sqlite) Support for repeated table\_option (#2482) * (mysql) Generate unsigned param (#2522) * (sql/catalog) Support pg\_dump output (#2508) * (sqlite) Code generation for sqlc.slice (#2431) * (vet) Clean up unnecessary `prepareable()` func and a var name (#2509) * (vet) Query.cmd was always set to “:” (#2525) * (vet) Report an error when a query is unpreparable, close prepared statement connection (#2486) * (vet) Split vet messages out of codegen.proto (#2511) #### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id80 "Link to this heading") * Add a description to the document for cases when a query result has no rows (#2462) * Update copyright and author (#2490) * Add example sqlc.yaml for migration parsing (#2479) * Small updates (#2506) * Point GitHub links to new repository location (#2534) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id81 "Link to this heading") * Rename kyleconroy/sqlc to sqlc-dev/sqlc (#2523) * (proto) Reformat protos using `buf format -w` (#2536) * Update FEATURE\_REQUEST.yml to include SQLite engine option * Finish migration to sqlc-dev/sqlc (#2548) * (compiler) Remove some duplicate code (#2546) #### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id82 "Link to this heading") * Add profiles to docker compose (#2503) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id83 "Link to this heading") * Run all supported versions of MySQL / PostgreSQL (#2463) * (deps) Bump pygments from 2.7.4 to 2.15.0 in /docs (#2485) * (deps) Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2483) * (deps) Bump github.com/google/cel-go from 0.16.0 to 0.17.1 (#2484) * (docs) Check Python dependencies via dependabot (#2497) * (deps) Bump idna from 2.10 to 3.4 in /docs (#2499) * (deps) Bump packaging from 20.9 to 23.1 in /docs (#2498) * (deps) Bump pygments from 2.15.0 to 2.15.1 in /docs (#2500) * (deps) Bump certifi from 2022.12.7 to 2023.7.22 in /docs (#2504) * (deps) Bump sphinx from 4.4.0 to 6.1.0 in /docs (#2505) * Add psql and mysqlsh to devenv (#2507) * (deps) Bump urllib3 from 1.26.5 to 2.0.4 in /docs (#2516) * (deps) Bump chardet from 4.0.0 to 5.1.0 in /docs (#2517) * (deps) Bump snowballstemmer from 2.1.0 to 2.2.0 in /docs (#2519) * (deps) Bump pytz from 2021.1 to 2023.3 in /docs (#2520) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.0 to 2.0.1 in /docs (#2518) * (deps) Bump pyparsing from 2.4.7 to 3.1.0 in /docs (#2530) * (deps) Bump alabaster from 0.7.12 to 0.7.13 in /docs (#2526) * (docs) Ignore updates for sphinx (#2532) * (deps) Bump babel from 2.9.1 to 2.12.1 in /docs (#2527) * (deps) Bump sphinxcontrib-applehelp from 1.0.2 to 1.0.4 in /docs (#2533) * (deps) Bump google.golang.org/grpc from 1.56.2 to 1.57.0 (#2535) * (deps) Bump pyparsing from 3.1.0 to 3.1.1 in /docs (#2547) [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id84 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-13 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id85 "Link to this heading") * Fix to traverse Sel in ast.In (#2414) * (compiler) Validate UNION … ORDER BY (#2446) * (golang) Prevent duplicate enum output (#2447) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id86 "Link to this heading") * Replace codegen, test and docs references to github.com/tabbed repos (#2418) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id87 "Link to this heading") * (deps) Bump google.golang.org/grpc from 1.56.1 to 1.56.2 (#2415) * (deps) Bump golang from 1.20.5 to 1.20.6 (#2437) * Pin Go to 1.20.6 (#2441) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.1 to 5.4.2 (#2436) [1.19.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id88 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-06 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id89 "Link to this heading") #### sqlc vet[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sqlc-vet "Link to this heading") [`sqlc vet`](https://docs.sqlc.dev/en/stable/howto/vet.html) runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/stable/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, an error is reported using the given message. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ##### Database connectivity[](https://docs.sqlc.dev/en/stable/reference/changelog.html#database-connectivity "Link to this heading") `vet` also marks the first time that `sqlc` can connect to a live, running database server. We’ll expand this functionality over time, but for now it powers the `sqlc/db-prepare` built-in rule. When a [database](https://docs.sqlc.dev/en/stable/reference/changelog.html#config.html#database) is configured, the `sqlc/db-preapre` rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Please note that `sqlc` does not manage or migrate your database. Use your migration tool of choice to create the necessary database tables and objects before running `sqlc vet`. #### Omit unused structs[](https://docs.sqlc.dev/en/stable/reference/changelog.html#omit-unused-structs "Link to this heading") Added a new configuration parameter `omit_unused_structs` which, when set to true, filters out table and enum structs that aren’t used in queries for a given package. #### Suggested CI/CD setup[](https://docs.sqlc.dev/en/stable/reference/changelog.html#suggested-ci-cd-setup "Link to this heading") With the addition of `sqlc diff` and `sqlc vet`, we encourage users to run sqlc in your CI/CD pipelines. See our [suggested CI/CD setup](https://docs.sqlc.dev/en/stable/howto/ci-cd.html) for more information. #### Simplified plugin development[](https://docs.sqlc.dev/en/stable/reference/changelog.html#simplified-plugin-development "Link to this heading") The [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) and [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) plugins have been updated use the upcoming [WASI](https://wasi.dev/) support in [Go 1.21](https://tip.golang.org/doc/go1.21#wasip1) . Building these plugins no longer requires [TinyGo](https://tinygo.org/) . ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id90 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id91 "Link to this heading") * Pointers overrides skip imports in generated query files (#2240) * CASE-ELSE clause is not properly parsed when a value is constant (#2238) * Fix toSnakeCase to handle input in CamelCase format (#2245) * Add location info to sqlite ast (#2298) * Add override tags to result struct (#1867) (#1887) * Override types of aliased columns and named parameters (#1884) * Resolve duplicate fields generated when inheriting multiple tables (#2089) * Check column references in ORDER BY (#1411) (#1915) * MySQL slice shadowing database/sql import (#2332) * Don’t defer rows.Close() if pgx.BatchResults.Query() failed (#2362) * Fix type overrides not working with sqlc.slice (#2351) * Type overrides on columns for parameters inside an IN clause (#2352) * Broken interaction between query\_parameter\_limit and pq.Array() (#2383) * (codegen/golang) Bring :execlastid in line with the rest (#2378) #### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id92 "Link to this heading") * Update changelog.md with some minor edits (#2235) * Add F# community plugin (#2295) * Add a ReadTheDocs config file (#2327) * Update query\_parameter\_limit documentation (#2374) * Add launch announcement banner #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id93 "Link to this heading") * PostgreSQL capture correct line and column numbers for parse error (#2289) * Add supporting COMMENT ON VIEW (#2249) * To allow spaces between function name and arguments of functions to be rewritten (#2250) * Add support for pgx/v5 emit\_pointers\_for\_null\_types flag (#2269) * (mysql) Support unsigned integers (#1746) * Allow use of table and column aliases for table functions returning unknown types (#2156) * Support “LIMIT ?” in UPDATE and DELETE for MySQL (#2365) * (internal/codegen/golang) Omit unused structs from output (#2369) * Improve default names for BETWEEN ? AND ? to have prefixes from\_ and to\_ (#2366) * (cmd/sqlc) Add the vet subcommand (#2344) * (sqlite) Add support for UPDATE/DELETE with a LIMIT clause (#2384) * Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) (#2373) * (cmd/vet) Prepare queries against a database (#2387) * (cmd/vet) Prepare queries for MySQL (#2388) * (cmd/vet) Prepare SQLite queries (#2389) * (cmd/vet) Simplify environment variable substiution (#2393) * (cmd/vet) Add built-in db-prepare rule * Add compiler support for NOTIFY and LISTEN (PostgreSQL) (#2363) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id94 "Link to this heading") * A few small staticcheck fixes (#2361) * Remove a bunch of dead code (#2360) * (scripts/regenerate) Should also update stderr.txt (#2379) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id95 "Link to this heading") * (deps) Bump requests from 2.25.1 to 2.31.0 in /docs (#2283) * (deps) Bump golang from 1.20.3 to 1.20.4 (#2256) * (deps) Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#2265) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 (#2293) * (deps) Bump golang.org/x/sync from 0.1.0 to 0.2.0 (#2266) * (deps) Bump golang from 1.20.4 to 1.20.5 (#2301) * Configure dependencies via devenv.sh (#2319) * Configure dependencies via devenv.sh (#2326) * (deps) Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#2328) * (deps) Bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#2333) * (deps) Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 (#2370) * (deps) Bump actions/checkout from 2 to 3 (#2357) * Run govulncheck on all builds (#2372) * (deps) Bump google.golang.org/grpc from 1.56.0 to 1.56.1 (#2358) #### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#cmd-sqlc "Link to this heading") * Show helpful output on missing subcommand (#2345) #### Codegen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#codegen "Link to this heading") * Use catalog’s default schema (#2310) * (go) Add tests for tables with dashes (#2312) * (go) Strip invalid characters from table and column names (#2314) * (go) Support JSON tags for nullable enum structs (#2121) #### Internal/config[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-config "Link to this heading") * Support golang overrides for slices (#2339) #### Kotlin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#kotlin "Link to this heading") * Use latest version of sqlc-gen-kotlin (#2356) #### Postgres[](https://docs.sqlc.dev/en/stable/reference/changelog.html#postgres "Link to this heading") * Column merging for table inheritence (#2315) #### Protos[](https://docs.sqlc.dev/en/stable/reference/changelog.html#protos "Link to this heading") * Add missing field name (#2354) #### Python[](https://docs.sqlc.dev/en/stable/reference/changelog.html#python "Link to this heading") * Use latest version of sqlc-gen-python (#2355) #### Remote[](https://docs.sqlc.dev/en/stable/reference/changelog.html#remote "Link to this heading") * Use user-id/password auth (#2262) #### Sqlite[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sqlite "Link to this heading") * Fixed sqlite column type override (#1986) [1.18.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.18.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id96 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-04-27 ### Release notes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id97 "Link to this heading") #### Remote code generation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#remote-code-generation "Link to this heading") _Developed by [@andrewmbenton](https://github.com/andrewmbenton) _ At its core, sqlc is powered by SQL engines, which include parsers, formatters, analyzers and more. While our goal is to support each engine on each operating system, it’s not always possible. For example, the PostgreSQL engine does not work on Windows. To bridge that gap, we’re announcing remote code generation, currently in private alpha. To join the private alpha, [sign up for the waitlist](https://docs.google.com/forms/d/e/1FAIpQLScDWrGtTgZWKt3mdlF5R2XCX6tL1pMkB4yuZx5yq684tTNN1Q/viewform?usp=sf_link) . Remote code generation works like local code generation, except the heavy lifting is performed in a consistent cloud environment. WASM-based plugins are supported in the remote environment, but process-based plugins are not. To configure remote generation, add a `cloud` block in `sqlc.json`. { "version": "2", "cloud": { "organization": "", "project": "", }, ... } You’ll also need to set the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\= When the `cloud` configuration block exists, `sqlc generate` will default to remote code generation. If you’d like to generate code locally without removing the `cloud` block from your config, pass the `--no-remote` option. sqlc generate \--no-remote Remote generation is off by default and requires an opt-in to use. #### sqlc.embed[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sqlc-embed "Link to this heading") _Developed by [@nickjackson](https://github.com/nickjackson) _ Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ) CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ) We want to select the student record and the highest score they got on a test. Here’s how we’d usually do that: \-- name: HighScore :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT students.\*, high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; When using Go, sqlc will produce a struct like this: type HighScoreRow struct { ID int64 Name sql.NullString Age sql.NullInt32 HighScore int32 } With embedding, the struct will contain a model for the table instead of a flattened list of columns. \-- name: HighScoreEmbed :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT sqlc.embed(students), high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; type HighScoreRow struct { Student Student HighScore int32 } #### sqlc.slice[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sqlc-slice "Link to this heading") _Developed by Paul Cameron and Jille Timmermans_ The MySQL Go driver does not support passing slices to the IN operator. The `sqlc.slice` function generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) func (q \*Queries) SelectStudents(ctx context.Context, ages \[\]int32) (\[\]Student, error) { This feature is only supported in MySQL and cannot be used with prepared queries. #### Batch operation improvements[](https://docs.sqlc.dev/en/stable/reference/changelog.html#batch-operation-improvements "Link to this heading") When using batches with pgx, the error returned when a batch is closed is exported by the generated package. This change allows for cleaner error handling using `errors.Is`. errors.Is(err, generated\_package.ErrBatchAlreadyClosed) Previously, you would have had to check match on the error message itself. err.Error() \== "batch already closed" The generated code for batch operations always lived in `batch.go`. This file name can now be configured via the `output_batch_file_name` configuration option. #### Configurable query parameter limits for Go[](https://docs.sqlc.dev/en/stable/reference/changelog.html#configurable-query-parameter-limits-for-go "Link to this heading") By default, sqlc will limit Go functions to a single parameter. If a query includes more than one parameter, the generated method will use an argument struct instead of positional arguments. This behavior can now be changed via the `query_parameter_limit` configuration option. If set to `0`, every genreated method will use a argument struct. ### Changes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id98 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id99 "Link to this heading") * Prevent variable redeclaration in single param conflict for pgx (#2058) * Retrieve Larg/Rarg join query after inner join (#2051) * Rename argument when conflicted to imported package (#2048) * Pgx closed batch return pointer if need #1959 (#1960) * Correct singularization of “waves” (#2194) * Honor Package level renames in v2 yaml config (#2001) * (mysql) Prevent UPDATE … JOIN panic #1590 (#2154) * Mysql delete join panic (#2197) * Missing import with pointer overrides, solves #2168 #2125 (#2217) #### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id100 "Link to this heading") * (config.md) Add `sqlite` as engine option (#2164) * Add first pass at pgx documentation (#2174) * Add missed configuration option (#2188) * `specifies parameter ":one" without containing a RETURNING clause` (#2173) #### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id101 "Link to this heading") * Add `sqlc.embed` to allow model re-use (#1615) * (Go) Add query\_parameter\_limit conf to codegen (#1558) * Add remote execution for codegen (#2214) #### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id102 "Link to this heading") * Skip tests if required plugins are missing (#2104) * Add tests for reanme fix in v2 (#2196) * Regenerate batch output for filename tests * Remove remote test (#2232) * Regenerate test output #### Bin/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#bin-sqlc "Link to this heading") * Add SQLCTMPDIR environment variable (#2189) #### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id103 "Link to this heading") * (deps) Bump github.com/antlr/antlr4/runtime/Go/antlr (#2109) * (deps) Bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 (#2119) * (deps) Bump golang from 1.20.1 to 1.20.2 (#2135) * (deps) Bump google.golang.org/protobuf from 1.28.1 to 1.29.0 (#2137) * (deps) Bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#2143) * (deps) Bump golang from 1.20.2 to 1.20.3 (#2192) * (deps) Bump actions/setup-go from 3 to 4 (#2150) * (deps) Bump google.golang.org/protobuf from 1.29.1 to 1.30.0 (#2151) * (deps) Bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#2193) * (deps) Bump github.com/lib/pq from 1.10.7 to 1.10.8 (#2211) * (deps) Bump github.com/lib/pq from 1.10.8 to 1.10.9 (#2229) * (deps) Bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 (#2228) #### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id104 "Link to this heading") * Remove –experimental flag (#2170) * Add option to disable process-based plugins (#2180) * Bump version to v1.18.0 #### Codegen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id105 "Link to this heading") * Correctly generate CopyFrom columns for single-column copyfroms (#2185) #### Config[](https://docs.sqlc.dev/en/stable/reference/changelog.html#config "Link to this heading") * Add top-level cloud configuration (#2204) #### Engine/postgres[](https://docs.sqlc.dev/en/stable/reference/changelog.html#engine-postgres "Link to this heading") * Upgrade to pg\_query\_go/v4 (#2114) #### Ext/wasm[](https://docs.sqlc.dev/en/stable/reference/changelog.html#ext-wasm "Link to this heading") * Check exit code on returned error (#2223) #### Parser[](https://docs.sqlc.dev/en/stable/reference/changelog.html#parser "Link to this heading") * Generate correct types for `SELECT NOT EXISTS` (#1972) #### Sqlite[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id106 "Link to this heading") * Add support for CREATE TABLE … STRICT (#2175) #### Wasm[](https://docs.sqlc.dev/en/stable/reference/changelog.html#wasm "Link to this heading") * Upgrade to wasmtime v8.0.0 (#2222) [1.17.2](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.2) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id107 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id108 "Link to this heading") * Fix build on Windows (#2102) [1.17.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.1) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id109 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id110 "Link to this heading") * Prefer to use \[\]T over pgype.Array\[T\] (#2090) * Revert changes to Dockerfile (#2091) * Do not throw error when IF NOT EXISTS is used on ADD COLUMN (#2092) ### MySQL[](https://docs.sqlc.dev/en/stable/reference/changelog.html#mysql "Link to this heading") * Add `float` support to MySQL (#2097) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id111 "Link to this heading") * (deps) Bump golang from 1.20.0 to 1.20.1 (#2082) [1.17.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id112 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-02-13 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id113 "Link to this heading") * Initialize generated code outside function (#1850) * (engine/mysql) Take into account column’s charset to distinguish text/blob, (var)char/(var)binary (#776) (#1895) * The enum Value method returns correct type (#1996) * Documentation for Inserting Rows (#2034) * Add import statements even if only pointer types exist (#2046) * Search from Rexpr if not found from Lexpr (#2056) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id114 "Link to this heading") * Change ENTRYPOINT to CMD (#1943) * Update samples for HOW-TO GUIDES (#1953) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id115 "Link to this heading") * Add the diff command (#1963) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id116 "Link to this heading") * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.15 to 1.14.16 (#1913) * (deps) Bump github.com/spf13/cobra from 1.6.0 to 1.6.1 (#1909) * Fix devcontainer (#1942) * Run sqlc-pg-gen via GitHub Actions (#1944) * Move large arrays out of functions (#1947) * Fix conflicts from pointer configuration (#1950) * (deps) Bump github.com/go-sql-driver/mysql from 1.6.0 to 1.7.0 (#1988) * (deps) Bump github.com/jackc/pgtype from 1.12.0 to 1.13.0 (#1978) * (deps) Bump golang from 1.19.3 to 1.19.4 (#1992) * (deps) Bump certifi from 2020.12.5 to 2022.12.7 in /docs (#1993) * (deps) Bump golang from 1.19.4 to 1.19.5 (#2016) * (deps) Bump golang from 1.19.5 to 1.20.0 (#2045) * (deps) Bump github.com/jackc/pgtype from 1.13.0 to 1.14.0 (#2062) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.0 (#2063) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#cmd "Link to this heading") * Generate packages in parallel (#2026) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id117 "Link to this heading") * Bump version to v1.17.0 ### Codegen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id118 "Link to this heading") * Remove built-in Kotlin support (#1935) * Remove built-in Python support (#1936) ### Internal/codegen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-codegen "Link to this heading") * Cache pattern matching compilations (#2028) ### Mysql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id119 "Link to this heading") * Add datatype tests (#1948) * Fix blob tests (#1949) ### Plugins[](https://docs.sqlc.dev/en/stable/reference/changelog.html#plugins "Link to this heading") * Upgrade to wasmtime 3.0.1 (#2009) ### Sqlite[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id120 "Link to this heading") * Supported between expr (#1958) (#1967) ### Tools[](https://docs.sqlc.dev/en/stable/reference/changelog.html#tools "Link to this heading") * Regenerate scripts skips dirs that contains diff exec command (#1987) ### Wasm[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id121 "Link to this heading") * Upgrade to wasmtime 5.0.0 (#2065) [1.16.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.16.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id122 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-11-09 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id123 "Link to this heading") * (validate) Sqlc.arg & sqlc.narg are not “missing” (#1814) * Emit correct comment for nullable enums (#1819) * 🐛 Correctly switch `coalesce()` result `.NotNull` value (#1664) * Prevent batch infinite loop with arg length (#1794) * Support version 2 in error message (#1839) * Handle empty column list in postgresql (#1843) * Batch imports filter queries, update cmds having ret type (#1842) * Named params contribute to batch parameter count (#1841) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id124 "Link to this heading") * Add a getting started guide for SQLite (#1798) * Various readability improvements (#1854) * Add documentation for codegen plugins (#1904) * Update migration guides with links (#1933) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id125 "Link to this heading") * Add HAVING support to MySQL (#1806) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id126 "Link to this heading") * Upgrade wasmtime version (#1827) * Bump wasmtime version to v1.0.0 (#1869) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id127 "Link to this heading") * (deps) Bump github.com/jackc/pgconn from 1.12.1 to 1.13.0 (#1785) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.13 to 1.14.15 (#1799) * (deps) Bump github.com/jackc/pgx/v4 from 4.16.1 to 4.17.0 (#1786) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.0 to 4.17.1 (#1825) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1826) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.1 to 4.17.2 (#1831) * (deps) Bump golang from 1.19.0 to 1.19.1 (#1834) * (deps) Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#1838) * (deps) Bump github.com/lib/pq from 1.10.6 to 1.10.7 (#1835) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1857) * (deps) Bump github.com/spf13/cobra from 1.5.0 to 1.6.0 (#1893) * (deps) Bump golang from 1.19.1 to 1.19.3 (#1920) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id128 "Link to this heading") * Bump to v1.16.0 ### Codgen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#codgen "Link to this heading") * Include serialized codegen options (#1890) ### Compiler[](https://docs.sqlc.dev/en/stable/reference/changelog.html#compiler "Link to this heading") * Move Kotlin parameter logic into codegen (#1910) ### Examples[](https://docs.sqlc.dev/en/stable/reference/changelog.html#examples "Link to this heading") * Port Python examples to WASM plugin (#1903) ### Pg-gen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#pg-gen "Link to this heading") * Make sqlc-pg-gen the complete source of truth for pg\_catalog.go (#1809) * Implement information\_schema shema (#1815) ### Python[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id129 "Link to this heading") * Port all Python tests to sqlc-gen-python (#1907) * Upgrade to sqlc-gen-python v1.0.0 (#1932) [1.15.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.15.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id130 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-08-07 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id131 "Link to this heading") * (mysql) Typo (#1700) * (postgresql) Add quotes for CamelCase columns (#1729) * Cannot parse SQLite upsert statement (#1732) * (sqlite) Regenerate test output for builtins (#1735) * (wasm) Version modules by wasmtime version (#1734) * Missing imports (#1637) * Missing slice import for querier (#1773) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id132 "Link to this heading") * Add process-based plugin docs (#1669) * Add links to downloads.sqlc.dev (#1681) * Update transactions how to example (#1775) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id133 "Link to this heading") * More SQL Syntax Support for SQLite (#1687) * (sqlite) Promote SQLite support to beta (#1699) * Codegen plugins, powered by WASM (#1684) * Set user-agent for plugin downloads (#1707) * Null enums types (#1485) * (sqlite) Support stdlib functions (#1712) * (sqlite) Add support for returning (#1741) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id134 "Link to this heading") * Add tests for quoting columns (#1733) * Remove catalog tests (#1762) ### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id135 "Link to this heading") * Add tests for fixing slice imports (#1736) * Add test cases for returning (#1737) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id136 "Link to this heading") * Upgrade to Go 1.19 (#1780) * Upgrade to go-wasmtime 0.39.0 (#1781) ### Plugins[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id137 "Link to this heading") * (wasm) Change default cache location (#1709) * (wasm) Change the SHA-256 config key (#1710) [1.14.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.14.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id138 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-06-09 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id139 "Link to this heading") * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) * (compiler) Fix left join nullability with table aliases (#1491) * Regenerate testdata for CREATE TABLE AS (#1516) * (bundler) Only close multipart writer once (#1528) * (endtoend) Regenerate testdata for exex\_lastid * (pgx) Copyfrom imports (#1626) * Validate sqlc function arguments (#1633) * Fixed typo `sql.narg` in doc (#1668) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id140 "Link to this heading") * (golang) Add Enum.Valid and AllEnumValues (#1613) * (sqlite) Start expanding support (#1410) * (pgx) Add support for batch operations (#1437) * (sqlite) Add support for delete statements (#1447) * (codegen) Insert comments in interfaces (#1458) * (sdk) Add the plugin SDK package (#1463) * Upload projects (#1436) * Add sqlc version to generated Kotlin code (#1512) * Add sqlc version to generated Go code (#1513) * Pass sqlc version in codegen request (#1514) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * Run sqlc with docker on windows cmd (#1557) * Add JSON “codegen” output (#1565) * Add sqlc.narg() for nullable named params (#1536) * Process-based codegen plugins (#1578) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id141 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id142 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) * (sql/catalog) Improve Readability (#1595) * Add basic fuzzing for config / overrides (#1500) [1.13.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.13.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id143 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-03-31 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id144 "Link to this heading") * (compiler) Fix left join nullability with table aliases (#1491) * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id145 "Link to this heading") * (cli) Upload projects (#1436) * (codegen) Add sqlc version to generated Go code (#1513) * (codegen) Add sqlc version to generated Kotlin code (#1512) * (codegen) Insert comments in interfaces (#1458) * (codegen) Pass sqlc version in codegen request (#1514) * (pgx) Add support for batch operations (#1437) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * (sdk) Add the plugin SDK package (#1463) * (sqlite) Add support for delete statements (#1447) * (sqlite) Start expanding support (#1410) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id146 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id147 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) ### Config[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id148 "Link to this heading") * Add basic fuzzing for config / overrides (#1500) [1.12.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.12.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id149 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2022-02-05 ### Bug[](https://docs.sqlc.dev/en/stable/reference/changelog.html#bug "Link to this heading") * ALTER TABLE SET SCHEMA (#1409) ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id150 "Link to this heading") * Update ANTLR v4 go.mod entry (#1336) * Check delete statements for CTEs (#1329) * Fix validation of GROUP BY on field aliases (#1348) * Fix imports when non-copyfrom queries needed imports that copyfrom queries didn’t (#1386) * Remove extra comment newline (#1395) * Enable strict function checking (#1405) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id151 "Link to this heading") * Bump version to 1.11.0 (#1308) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id152 "Link to this heading") * Inheritance (#1339) * Generate query code using ASTs instead of templates (#1338) * Add support for CREATE TABLE a ( LIKE b ) (#1355) * Add support for sql.NullInt16 (#1376) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id153 "Link to this heading") * Add tests for :exec{result,rows} (#1344) * Delete template-based codegen (#1345) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id154 "Link to this heading") * Bump github.com/jackc/pgx/v4 from 4.14.0 to 4.14.1 (#1316) * Bump golang from 1.17.3 to 1.17.4 (#1331) * Bump golang from 1.17.4 to 1.17.5 (#1337) * Bump github.com/spf13/cobra from 1.2.1 to 1.3.0 (#1343) * Remove devel Docker build * Bump golang from 1.17.5 to 1.17.6 (#1369) * Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 (#1382) * Format all Go code (#1387) [1.11.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.11.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id155 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-11-24 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id156 "Link to this heading") * Update incorrect signatures (#1180) * Correct aggregate func sig (#1182) * Jsonb\_build\_object (#1211) * Case-insensitive identifiers (#1216) * Incorrect handling of meta (#1228) * Detect invalid INSERT expression (#1231) * Respect alias name for coalesce (#1232) * Mark nullable when casting NULL (#1233) * Support nullable fields in joins for MySQL engine (#1249) * Fix between expression handling of table references (#1268) * Support nullable fields in joins on same table (#1270) * Fix missing binds in ORDER BY (#1273) * Set RV for TargetList items on updates (#1252) * Fix MySQL parser for query without trailing semicolon (#1282) * Validate table alias references (#1283) * Add support for MySQL ON DUPLICATE KEY UPDATE (#1286) * Support references to columns in joined tables in UPDATE statements (#1289) * Add validation for GROUP BY clause column references (#1285) * Prevent variable redeclaration in single param conflict (#1298) * Use common params struct field for same named params (#1296) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id157 "Link to this heading") * Replace deprecated go get with go install (#1181) * Fix package name referenced in tutorial (#1202) * Add environment variables (#1264) * Add go.17+ install instructions (#1280) * Warn about golang-migrate file order (#1302) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id158 "Link to this heading") * Instrument compiler via runtime/trace (#1258) * Add MySQL support for BETWEEN arguments (#1265) ### Refactor[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id159 "Link to this heading") * Move from io/ioutil to io and os package (#1164) ### Styling[](https://docs.sqlc.dev/en/stable/reference/changelog.html#styling "Link to this heading") * Apply gofmt to sample code (#1261) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id160 "Link to this heading") * Bump golang from 1.17.0 to 1.17.1 (#1173) * Bump eskatos/gradle-command-action from 1 to 2 (#1220) * Bump golang from 1.17.1 to 1.17.2 (#1227) * Bump github.com/pganalyze/pg\_query\_go/v2 (#1234) * Bump actions/checkout from 2.3.4 to 2.3.5 (#1238) * Bump babel from 2.9.0 to 2.9.1 in /docs (#1245) * Bump golang from 1.17.2 to 1.17.3 (#1272) * Bump actions/checkout from 2.3.5 to 2.4.0 (#1267) * Bump github.com/lib/pq from 1.10.3 to 1.10.4 (#1278) * Bump github.com/jackc/pgx/v4 from 4.13.0 to 4.14.0 (#1303) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id161 "Link to this heading") * Bump version to v1.11.0 [1.10.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.10.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id162 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-09-07 ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id163 "Link to this heading") * Fix invalid language support table (#1161) * Add a getting started guide for MySQL (#1163) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id164 "Link to this heading") * Bump golang from 1.16.7 to 1.17.0 (#1129) * Bump github.com/lib/pq from 1.10.2 to 1.10.3 (#1160) ### Ci[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id165 "Link to this heading") * Upgrade Go to 1.17 (#1130) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id166 "Link to this heading") * Bump version to v1.10.0 (#1165) ### Codegen/golang[](https://docs.sqlc.dev/en/stable/reference/changelog.html#codegen-golang "Link to this heading") * Consolidate import logic (#1139) * Add pgx support for range types (#1146) * Use pgtype for hstore when using pgx (#1156) ### Codgen/golang[](https://docs.sqlc.dev/en/stable/reference/changelog.html#codgen-golang "Link to this heading") * Use p\[gq\]type for network address types (#1142) ### Endtoend[](https://docs.sqlc.dev/en/stable/reference/changelog.html#endtoend "Link to this heading") * Run `go test` in CI (#1134) ### Engine/mysql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#engine-mysql "Link to this heading") * Add support for LIKE (#1162) ### Golang[](https://docs.sqlc.dev/en/stable/reference/changelog.html#golang "Link to this heading") * Output NullUUID when necessary (#1137) [1.9.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.9.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id167 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-08-13 ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id168 "Link to this heading") * Update documentation (a bit) for v1.9.0 (#1117) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id169 "Link to this heading") * Bump golang from 1.16.6 to 1.16.7 (#1107) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id170 "Link to this heading") * Bump version to v1.9.0 (#1121) ### Compiler[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id171 "Link to this heading") * Add tests for COALESCE behavior (#1112) * Handle subqueries in SELECT statements (#1113) [1.8.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.8.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id172 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-05-03 ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id173 "Link to this heading") * Add language support Matrix (#920) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id174 "Link to this heading") * Add case style config option (#905) ### Python[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id175 "Link to this heading") * Eliminate runtime package and use sqlalchemy (#939) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id176 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.4 to 0.5.5 (#926) * Bump github.com/lib/pq from 1.9.0 to 1.10.0 (#931) * Bump golang from 1.16.0 to 1.16.1 (#935) * Bump golang from 1.16.1 to 1.16.2 (#942) * Bump github.com/jackc/pgx/v4 from 4.10.1 to 4.11.0 (#956) * Bump github.com/go-sql-driver/mysql from 1.5.0 to 1.6.0 (#961) * Bump github.com/pganalyze/pg\_query\_go/v2 (#965) * Bump urllib3 from 1.26.3 to 1.26.4 in /docs (#968) * Bump golang from 1.16.2 to 1.16.3 (#963) * Bump github.com/lib/pq from 1.10.0 to 1.10.1 (#980) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id177 "Link to this heading") * Add the –experimental flag (#929) * Fix sqlc init (#959) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id178 "Link to this heading") * Bump version to v1.7.1-devel (#913) * Bump version to v1.8.0 ### Codegen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id179 "Link to this heading") * Generate valid enum names for symbols (#972) ### Postgresql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#postgresql "Link to this heading") * Support generated columns * Add test for PRIMARY KEY INCLUDE * Add tests for CREATE TABLE PARTITION OF * CREATE TRIGGER EXECUTE FUNCTION * Add support for renaming types (#971) ### Sql/ast[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sql-ast "Link to this heading") * Resolve return values from functions (#964) ### Workflows[](https://docs.sqlc.dev/en/stable/reference/changelog.html#workflows "Link to this heading") * Only run tests once (#924) [1.7.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.7.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id180 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-02-28 ### Bug Fixes[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id181 "Link to this heading") * Struct tag formatting (#833) ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id182 "Link to this heading") * Include all the existing Markdown files (#877) * Split docs into four sections (#882) * Reorganize and consolidate documentation * Add link to Windows download (#888) * Shorten the README (#889) ### Features[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id183 "Link to this heading") * Adding support for pgx/v4 * Adding support for pgx/v4 ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#readme "Link to this heading") * Add Go Report Card badge (#891) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id184 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.3 to 0.5.4 (#813) * Bump github.com/lib/pq from 1.8.0 to 1.9.0 (#820) * Bump golang from 1.15.5 to 1.15.6 (#822) * Bump github.com/jackc/pgx/v4 from 4.9.2 to 4.10.0 (#823) * Bump github.com/jackc/pgx/v4 from 4.10.0 to 4.10.1 (#839) * Bump golang from 1.15.6 to 1.15.7 (#855) * Bump golang from 1.15.7 to 1.15.8 (#881) * Bump github.com/spf13/cobra from 1.1.1 to 1.1.2 (#892) * Bump golang from 1.15.8 to 1.16.0 (#897) * Bump github.com/lfittl/pg\_query\_go from 1.0.1 to 1.0.2 (#901) * Bump github.com/spf13/cobra from 1.1.2 to 1.1.3 (#893) ### Catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#catalog "Link to this heading") * Improve alter column type (#818) ### Ci[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id185 "Link to this heading") * Uprade to Go 1.15 (#887) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id186 "Link to this heading") * Allow config file location to be specified (#863) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id187 "Link to this heading") * Bump to version v1.6.1-devel (#807) * Bump version to v1.7.0 (#912) ### Codegen/golang[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id188 "Link to this heading") * Make sure to import net package (#858) ### Compiler[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id189 "Link to this heading") * Support UNION query ### Dolphin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#dolphin "Link to this heading") * Generate bools for tinyint(1) * Support joins in update statements (#883) * Add support for union query ### Endtoend[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id190 "Link to this heading") * Add tests for INTERSECT and EXCEPT ### Go.mod[](https://docs.sqlc.dev/en/stable/reference/changelog.html#go-mod "Link to this heading") * Update to go 1.15 and run ‘go mod tidy’ (#808) ### Mysql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id191 "Link to this heading") * Compile tinyint(1) to bool (#873) ### Sql/ast[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id192 "Link to this heading") * Add enum values for SetOperation [1.6.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.6.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id193 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-11-23 ### Dolphin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id194 "Link to this heading") * Implement Rename (#651) * Skip processing view drops (#653) ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id195 "Link to this heading") * Update language / database support (#698) ### Astutils[](https://docs.sqlc.dev/en/stable/reference/changelog.html#astutils "Link to this heading") * Fix Params rewrite call (#674) ### Build[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id196 "Link to this heading") * Bump golang from 1.14 to 1.15.3 (#765) * Bump docker/build-push-action from v1 to v2.1.0 (#764) * Bump github.com/google/go-cmp from 0.4.0 to 0.5.2 (#766) * Bump github.com/spf13/cobra from 1.0.0 to 1.1.1 (#767) * Bump github.com/jackc/pgx/v4 from 4.6.0 to 4.9.2 (#768) * Bump github.com/lfittl/pg\_query\_go from 1.0.0 to 1.0.1 (#773) * Bump github.com/google/go-cmp from 0.5.2 to 0.5.3 (#783) * Bump golang from 1.15.3 to 1.15.5 (#782) * Bump github.com/lib/pq from 1.4.0 to 1.8.0 (#769) ### Catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id197 "Link to this heading") * Improve variadic argument support (#804) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id198 "Link to this heading") * Bump to version v1.6.0 (#806) ### Codegen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id199 "Link to this heading") * Fix errant database/sql imports (#789) ### Compiler[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id200 "Link to this heading") * Use engine-specific reserved keywords (#677) ### Dolphi[](https://docs.sqlc.dev/en/stable/reference/changelog.html#dolphi "Link to this heading") * Add list of builtin functions (#795) ### Dolphin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id201 "Link to this heading") * Update to the latest MySQL parser (#665) * Add ENUM() support (#676) * Add test for table aliasing (#684) * Add MySQL ddl\_create\_table test (#685) * Implete TRUNCATE table (#697) * Represent tinyint as int32 (#797) * Add support for coalesce (#802) * Add function signatures (#796) ### Endtoend[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id202 "Link to this heading") * Add MySQL json test (#692) * Add MySQL update set multiple test (#696) ### Examples[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id203 "Link to this heading") * Use generated enum constants in db\_test (#678) * Port ondeck to MySQL (#680) * Add MySQL authors example (#682) ### Internal/cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-cmd "Link to this heading") * Print correct config file on parse failure (#749) ### Kotlin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id204 "Link to this heading") * Remove runtime dependency (#774) ### Metadata[](https://docs.sqlc.dev/en/stable/reference/changelog.html#metadata "Link to this heading") * Support multiple comment prefixes (#683) ### Postgresql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id205 "Link to this heading") * Support string concat operator (#701) ### Sql/catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sql-catalog "Link to this heading") * Add support for variadic functions (#798) [1.5.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.5.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id206 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-08-05 ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id207 "Link to this heading") * Build sqlc using Go 1.14 (#549) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id208 "Link to this heading") * Add debugging support (#573) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id209 "Link to this heading") * Bump version to v1.4.1-devel (#548) * Bump version to v1.5.0 ### Compiler[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id210 "Link to this heading") * Support calling functions with defaults (#635) * Skip func args without a paramRef (#636) * Return a single column from coalesce (#639) ### Config[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id211 "Link to this heading") * Add emit\_empty\_slices to version one (#552) ### Contrib[](https://docs.sqlc.dev/en/stable/reference/changelog.html#contrib "Link to this heading") * Add generated code for contrib ### Dinosql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#dinosql "Link to this heading") * Remove deprecated package (#554) ### Dolphin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id212 "Link to this heading") * Add support for column aliasing (#566) * Implement star expansion for subqueries (#619) * Implement exapansion with reserved words (#620) * Implement parameter refs (#621) * Implement limit and offest (#622) * Implement inserts (#623) * Implement delete (#624) * Implement simple update statements (#625) * Implement INSERT … SELECT (#626) * Use test driver instead of TiDB driver (#629) * Implement named parameters via sqlc.arg() (#632) ### Endtoend[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id213 "Link to this heading") * Add MySQL test for SELECT \* JOIN (#565) * Add MySQL test for inflection (#567) ### Engine[](https://docs.sqlc.dev/en/stable/reference/changelog.html#engine "Link to this heading") * Create engine package (#556) ### Equinox[](https://docs.sqlc.dev/en/stable/reference/changelog.html#equinox "Link to this heading") * Use the new equinox-io/setup action (#586) ### Examples[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id214 "Link to this heading") * Run tests for MySQL booktest (#627) ### Golang[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id215 "Link to this heading") * Add support for the money type (#561) * Generate correct types for int2 and int8 (#579) ### Internal[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal "Link to this heading") * Rm catalog, pg, postgres packages (#555) ### Mod[](https://docs.sqlc.dev/en/stable/reference/changelog.html#mod "Link to this heading") * Downgrade TiDB package to fix build (#603) ### Mysql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id216 "Link to this heading") * Upgrade to the latest vitess commit (#562) * Support to infer type of a duplicated arg (#615) * Allow some builtin functions to be nullable (#616) ### Postgresql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id217 "Link to this heading") * Generate all functions in pg\_catalog (#550) * Remove pg\_catalog schema from tests (#638) * Move contrib code to a package ### Sql/catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id218 "Link to this heading") * Fix comparison of pg\_catalog types (#637) ### Tools[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id219 "Link to this heading") * Generate functions for all of contrib ### Workflow[](https://docs.sqlc.dev/en/stable/reference/changelog.html#workflow "Link to this heading") * Migrate to equinox-io/setup-release-tool (#614) [1.4.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.4.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id220 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-06-17 ### Dockerfile[](https://docs.sqlc.dev/en/stable/reference/changelog.html#dockerfile "Link to this heading") * Add version build argument (#487) ### MySQL[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id221 "Link to this heading") * Prevent Panic when WHERE clause contains parenthesis. (#531) ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id222 "Link to this heading") * Document emit\_exact\_table\_names (#486) ### All[](https://docs.sqlc.dev/en/stable/reference/changelog.html#all "Link to this heading") * Remove the exp build tag (#507) ### Catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id223 "Link to this heading") * Support functions with table parameters (#541) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id224 "Link to this heading") * Bump to version 1.3.1-devel (#485) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id225 "Link to this heading") * Bump version to v1.4.0 (#547) ### Codegen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id226 "Link to this heading") * Add the new codegen packages (#513) * Add the :execresult query annotation (#542) ### Compiler[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id227 "Link to this heading") * Validate function calls (#505) * Port bottom of parseQuery (#510) * Don’t mutate table name (#517) * Enable experimental parser by default (#518) * Apply rename rules to enum constants (#523) * Temp fix for typecast function parameters (#530) ### Endtoend[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id228 "Link to this heading") * Standardize JSON formatting (#490) * Add per-test configuration files (#521) * Read expected stderr failures from disk (#527) ### Internal/dinosql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-dinosql "Link to this heading") * Check parameter style before ref (#488) * Remove unneeded column suffix (#492) * Support named function arguments (#494) ### Internal/postgresql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-postgresql "Link to this heading") * Fix NamedArgExpr rewrite (#491) ### Multierr[](https://docs.sqlc.dev/en/stable/reference/changelog.html#multierr "Link to this heading") * Move dinosql.ParserErr to a new package (#496) ### Named[](https://docs.sqlc.dev/en/stable/reference/changelog.html#named "Link to this heading") * Port parameter style validation to SQL (#504) ### Parser[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id229 "Link to this heading") * Support columns from subselect statements (#489) ### Rewrite[](https://docs.sqlc.dev/en/stable/reference/changelog.html#rewrite "Link to this heading") * Move parameter rewrite to package (#499) ### Sqlite[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id230 "Link to this heading") * Use convert functions instead of the listener (#519) ### Sqlpath[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sqlpath "Link to this heading") * Move ReadSQLFiles into a separate package (#495) ### Validation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#validation "Link to this heading") * Move query validation to separate package (#498) [1.3.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.3.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id231 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-05-12 ### Makefile[](https://docs.sqlc.dev/en/stable/reference/changelog.html#makefile "Link to this heading") * Update target (#449) ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id232 "Link to this heading") * Add Myles as a sponsor (#469) ### Testing[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id233 "Link to this heading") * Make sure all Go examples build (#480) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id234 "Link to this heading") * Bump version to v1.3.0 (#484) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id235 "Link to this heading") * Bump version to v1.2.1-devel (#442) ### Dinosql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id236 "Link to this heading") * Inline addFile (#446) * Add PostgreSQL support for TRUNCATE (#448) ### Gen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#gen "Link to this heading") * Emit json.RawMessage for JSON columns (#461) ### Go.mod[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id237 "Link to this heading") * Use latest lib/pq (#471) ### Parser[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id238 "Link to this heading") * Use same function to load SQL files (#483) ### Postgresql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id239 "Link to this heading") * Fix panic walking CreateTableAsStmt (#475) [1.2.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.2.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id240 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-04-07 ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id241 "Link to this heading") * Publish to Docker Hub (#422) ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id242 "Link to this heading") * Docker installation docs (#424) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id243 "Link to this heading") * Bump version to v1.1.1-devel (#407) * Bump version to v1.2.0 (#441) ### Gen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id244 "Link to this heading") * Add special case for “campus” (#435) * Properly quote reserved keywords on expansion (#436) ### Migrations[](https://docs.sqlc.dev/en/stable/reference/changelog.html#migrations "Link to this heading") * Move migration parsing to new package (#427) ### Parser[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id245 "Link to this heading") * Generate correct types for SELECT EXISTS (#411) [1.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.1.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id246 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-03-17 ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id247 "Link to this heading") * Add installation instructions (#350) * Add section on running tests (#357) * Fix typo (#371) ### Ast[](https://docs.sqlc.dev/en/stable/reference/changelog.html#ast "Link to this heading") * Add AST for ALTER TABLE ADD / DROP COLUMN (#376) * Add support for CREATE TYPE as ENUM (#388) * Add support for CREATE / DROP SCHEMA (#389) ### Astutils[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id248 "Link to this heading") * Apply changes to the ValuesList slice (#372) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id249 "Link to this heading") * Return v1.0.0 (#348) * Return next bug fix version (#349) ### Cmd/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id250 "Link to this heading") * Bump version to v1.1.0 (#406) ### Compiler[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id251 "Link to this heading") * Wire up the experimental parsers ### Config[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id252 "Link to this heading") * Remove “emit\_single\_file” option (#367) ### Dolphin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id253 "Link to this heading") * Add experimental parser for MySQL ### Gen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id254 "Link to this heading") * Add option to emit single file for Go (#366) * Add support for the ltree extension (#385) ### Go.mod[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id255 "Link to this heading") * Add packages for MySQL and SQLite parsers ### Internal/dinosql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id256 "Link to this heading") * Support Postgres macaddr type in Go (#358) ### Internal/endtoend[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-endtoend "Link to this heading") * Remove %w (#354) ### Kotlin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id257 "Link to this heading") * Add Query class to support timeout and cancellation (#368) ### Postgresql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id258 "Link to this heading") * Add experimental parser for MySQL ### Sql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sql "Link to this heading") * Add generic SQL AST ### Sql/ast[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id259 "Link to this heading") * Port support for COMMENT ON (#391) * Implement DROP TYPE (#397) * Implement ALTER TABLE RENAME (#398) * Implement ALTER TABLE RENAME column (#399) * Implement ALTER TABLE SET SCHEMA (#400) ### Sql/catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id260 "Link to this heading") * Port tests over from catalog pkg (#402) ### Sql/errors[](https://docs.sqlc.dev/en/stable/reference/changelog.html#sql-errors "Link to this heading") * Add a new errors package (#390) ### Sqlite[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id261 "Link to this heading") * Add experimental parser for SQLite [1.0.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.0.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id262 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-02-18 ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id263 "Link to this heading") * Add documentation for query commands (#270) * Add named parameter documentation (#332) ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id264 "Link to this heading") * Add sponsors section (#333) ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id265 "Link to this heading") * Remove parse subcommand (#322) ### Config[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id266 "Link to this heading") * Parse V2 config format * Add support for YAML (#336) ### Examples[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id267 "Link to this heading") * Add the jets and booktest examples (#237) * Move sqlc.json into examples folder (#238) * Add the authors example (#241) * Add build tag to authors tests (#319) ### Internal[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id268 "Link to this heading") * Allow CTE to be used with UPDATE (#268) * Remove the PackageMap from settings (#295) ### Internal/config[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id269 "Link to this heading") * Create new config package (#313) ### Internal/dinosql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id270 "Link to this heading") * Emit Querier interface (#240) * Strip leading “go-” or trailing “-go” from import (#262) * Overrides can now be basic types (#271) * Import needed types for Querier (#285) * Handle schema-scoped enums (#310) * Ignore golang-migrate rollbacks (#320) ### Internal/endtoend[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id271 "Link to this heading") * Move more tests to the record/replay framework * Add update test for named params (#329) ### Internal/mysql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-mysql "Link to this heading") * Fix flaky test (#242) * Port tests to endtoend package (#315) ### Internal/parser[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-parser "Link to this heading") * Resolve nested CTEs (#324) * Error if last query is missing (#325) * Support joins with aliases (#326) * Remove print statement (#327) ### Internal/sqlc[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-sqlc "Link to this heading") * Add support for composite types (#311) ### Kotlin[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id272 "Link to this heading") * Support primitives * Arrays, enums, and dates * Generate examples * README for examples * Factor out db setup extension * Fix enums, use List instead of Array * Port Go tests for examples * Rewrite numbered params to positional params * Always use use, fix indents * Unbox query params ### Parser[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id273 "Link to this heading") * Attach range vars to insert params * Attach range vars to insert params (#342) * Remove dead code (#343) [0.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v0.1.0) [](https://docs.sqlc.dev/en/stable/reference/changelog.html#id274 "Link to this heading") --------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-01-07 ### Documentation[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id275 "Link to this heading") * Replace remaining references to DinoSQL with sqlc (#149) ### README[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id276 "Link to this heading") * Fix download links (#66) * Add LIMIT 1 to query that should return one (#99) ### Catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id277 "Link to this heading") * Support “ALTER TABLE … DROP CONSTRAINT …” (#34) * Differentiate functions with different argument types (#51) ### Ci[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id278 "Link to this heading") * Enable tests on pull requests ### Cmd[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id279 "Link to this heading") * Include filenames in error messages (#69) * Do not output any changes on error (#72) ### Dinosql/internal[](https://docs.sqlc.dev/en/stable/reference/changelog.html#dinosql-internal "Link to this heading") * Add lower and upper functions (#215) * Ignore alter sequence commands (#219) ### Gen[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id280 "Link to this heading") * Add DO NOT EDIT comments to generated code (#50) * Include all schemas when generating models (#90) * Prefix structs with schema name (#91) * Generate single import for uuid package (#98) * Use same import logic for all Go files * Pick correct struct to return for queries (#107) * Create consistent JSON tags (#110) * Add Close method to Queries struct (#127) * Ignore empty override settings (#128) * Turn SQL comments into Go comments (#136) ### Internal/catalog[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-catalog "Link to this heading") * Parse unnamed function arguments (#166) ### Internal/dinosql[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id281 "Link to this heading") * Prepare() with no GoQueries still valid (#95) * Fix multiline comment rendering (#142) * Dereference alias nodes on walk (#158) * Ignore sql-migrate rollbacks (#160) * Sort imported packages (#165) * Add support for timestamptz (#169) * Error on missing queries (#180) * Use more database/sql null types (#182) * Support the pg\_temp schema (#183) * Override columns with array type (#184) * Implement robust expansion * Implement robust expansion (#186) * Add COMMENT ON support (#191) * Add DATE support * Add DATE support (#196) * Filter out invalid characters (#198) * Quote reserved keywords (#205) * Return parser errors first (#207) * Implement advisory locks (#212) * Error on duplicate query names (#221) * Fix incorrect enum names (#223) * Add support for numeric types * Add support for numeric types (#228) ### Internal/dinosql/testdata/ondeck[](https://docs.sqlc.dev/en/stable/reference/changelog.html#internal-dinosql-testdata-ondeck "Link to this heading") * Add Makefile (#156) ### Ondeck[](https://docs.sqlc.dev/en/stable/reference/changelog.html#ondeck "Link to this heading") * Move all tests to GitHub CI (#58) ### ParseQuery[](https://docs.sqlc.dev/en/stable/reference/changelog.html#parsequery "Link to this heading") * Return either a query or an error (#178) ### Parser[](https://docs.sqlc.dev/en/stable/reference/changelog.html#id282 "Link to this heading") * Use schema when resolving catalog refs (#82) * Support function calls in expressions (#104) * Correctly handle single files (#119) * Return error if missing RETURNING (#131) * Add support for mathmatical operators (#132) * Add support for simple case expressions (#134) * Error on mismatched INSERT input (#135) * Set IsArray on joined columns (#139) ### Pg[](https://docs.sqlc.dev/en/stable/reference/changelog.html#pg "Link to this heading") * Store functions in the catalog (#41) * Add location to errors (#73) --- # Changelog — sqlc 1.31.0 documentation * [](https://docs.sqlc.dev/en/v1.31.0/index.html) * Changelog * [View page source](https://docs.sqlc.dev/en/v1.31.0/_sources/reference/changelog.md.txt) * * * Changelog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#changelog "Link to this heading") ========================================================================================================= All notable changes to this project will be documented in this file. [1.31.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.31.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-31-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2026-04-19 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#bug-fixes "Link to this heading") * Strip psql meta-commands from schema files (#4390) * Emit pointers for nullable enum columns when `emit_pointers_for_null_types` is set (#4388) * Map xid8 to pgtype.Uint64 for pgx/v5 (#4387) * Rename `:one` return variable when it conflicts with a parameter (#4383) * Coerce SQLite JSONB output regardless of type casing (#4385) * Dedupe `sqlc.arg` parameters wrapped in a type cast for MySQL (#4384) * Preserve MySQL optimizer hints in generated query text (#4382) * Catch invalid `ON CONFLICT DO UPDATE` column references (#4366) * Replace manual loop with `copy()` builtin (#4166) * (native) Make MySQL connection check immediate on first attempt (#4254) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#documentation "Link to this heading") * Add link to community python plugin (#4157) * Add Claude Code remote environment setup instructions (#4246) * Add sqlc-gen-sqlx to community language support (#4371) * Add GitHub Topic to the plugins page (#4258) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#features "Link to this heading") * (sqlfile) Add `sqlfile.Split` (#4146) * (sqlite) Add database analyzer using ncruces/go-sqlite3 (#4199) * (ast) Implement comprehensive SQL AST formatting (#4205) * (mysql) Improve AST formatting and add DELETE JOIN support (#4206) * (sqlite) Add SQLite support to format tests (#4207) * (expander) Add star expander for `SELECT *` and `RETURNING *` (PostgreSQL, MySQL, SQLite) (#4203) * Add `SQLCEXPERIMENT` environment variable for experimental features (#4228) * Add native database support for e2e tests without Docker (#4236) * (postgresql) Add analyzerv2 experiment for database-only analysis (#4237) * Graduate parsecmd experiment (#4253) * Add parse subcommand with AST JSON output (#4240) * Add ClickHouse support to `sqlc parse` (#4267) * Add `sqlc-test-setup` command for database test environment setup (#4304) ### Refactor[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#refactor "Link to this heading") * (ast) Rename Formatter interface to Dialect (#4208) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#build "Link to this heading") * Upgrade Go toolchain to 1.26.2 (#4378) * Upgrade Go version to 1.26.0 (#4312) * Remove github.com/jackc/pgx/v4 dependency (#4379) * Upgrade github.com/pingcap/tidb/pkg/parser (#4389) * Install PostgreSQL from theseus-rs/postgresql-binaries instead of apt (#4310) * Skip CI/RTD builds when the change is irrelevant (#4381) * (deps) 35 dependabot bumps (collapsed from individual entries) [1.30.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.30.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-30-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-09-01 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id3 "Link to this heading") * (compiler/mysql) Prevent panic in convertSetOprSelectList() (#4042) * Range subselect alias pointer dereference (#3711) * (codegen/golang) Don’t omit enums used as arrays (#4058) * (codegen/golang) Handle `go_struct_tag` for `db_type` overrides (#4055) * (engine/dolphin) Remove references to deprecated `pcast.ChangeStmt` (#4057) * Normalize identifier usage for table names (#4045) * (engine/sqlite) Fix parsing of INSERT DEFAULT VALUES syntax (#4010) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id4 "Link to this heading") * Fix parameter syntax inconsistency for MySQL and SQLite (#4036) * Use correct configuration to generate the given output for JSON type override (#4049) * Clean up and add to docs regarding type overrides (#4060) * Try a different admonition format (#4061) * Use the correct admonition format (#4062) * Add multi-worded table example for renaming (#4067) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id5 "Link to this heading") * (docs) Add link to Gleam/parrot (#4038) * (engine/dolphin) Implement MATCH\_AGAINST conversion in SQL AST (#1192, #3091) (#4070) * (engine/sqlite) Coerce jsonb columns to json before returning to Go code (#3968) ### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#testing "Link to this heading") * (endtoend) Skip process\_plugin\_sqlc\_gen\_json (#4075) * (endtoend) Use Docker to start database servers (#4076) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id6 "Link to this heading") * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3941) * (deps) Bump packaging (#3940) * (deps) Bump golang from 1.24.2 to 1.24.4 (#3983) * (deps) Bump golang from 1.24.4 to 1.24.5 (#4014) * (deps) Bump urllib3 from 2.4.0 to 2.5.0 in /docs (#3994) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3989) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4027) * (deps) Bump modernc.org/sqlite (#4032) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4018) * (deps) Bump certifi in /docs in the production-dependencies group (#4041) * (deps) Bump google.golang.org/protobuf (#4043) * (deps) Bump actions/checkout from 4 to 5 (#4059) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#4071) * (deps) Bump requests in /docs in the production-dependencies group (#4068) * Upgrade to Go 1.25 (#4074) * (deps) Bump golang from 1.24.5 to 1.25.0 (#4063) * (deps) Bump github.com/google/cel-go (#4080) [1.29.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.29.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-29-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-04-14 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id8 "Link to this heading") * (docs) Correct spelling and grammar (#3645) * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) * (pgx) Do not wrap nil error (#3913) * (migrations) Normalize case for migration statement for all cases (#3919) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id9 "Link to this heading") * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Add changelog for 1.28.0 (#3797) * Add PHP DBAL plugin (#3813) * Fix PostGIS function name (#3829) * Add Zig plugin (#3824) * Add link to tandemdude/sqlc-gen-java (#3819) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id10 "Link to this heading") * (docs) How-to use transactions with pgx (#3557) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) * (mysql) Add a test for VECTOR column type (#3734) * (cli) Bump version from 1.27.0 to 1.28.0 (#3798) * (codegen/golang) Add an option to wrap query errors that includes query name (#3876) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#miscellaneous-tasks "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) * Update sqlc-gen-java supported engines (#3843) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id11 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) * (deps) Bump golang.org/x/net from 0.30.0 to 0.33.0 (#3796) * (deps) Bump golang from 1.23.5 to 1.23.6 (#3822) * Use govulncheck action (#3831) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3817) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3826) * (deps) Bump golang from 1.23.6 to 1.24.0 (#3842) * (deps) Bump myst-parser (#3841) * (deps) Bump modernc.org/sqlite (#3846) * (deps) Bump golang from 1.24.0 to 1.24.1 (#3870) * (deps) Bump jinja2 in /docs in the production-dependencies group (#3872) * Upgrade to wazero@v1.9.0 (#3887) * Upgrade to Go 1.24.1 (#3892) * Upgrade to latest version of MySQL parser (#3893) * (deps) Bump pyparsing (#3890) * (deps) Bump golang.org/x/net from 0.33.0 to 0.37.0 (#3894) * (deps) Bump the production-dependencies group across 1 directory with 8 updates (#3896) * (deps) Bump github.com/jackc/pgx/v5 (#3898) * (deps) Bump the production-dependencies group (#3899) * (deps) Bump modernc.org/sqlite (#3905) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3914) * (deps) Bump urllib3 in /docs in the production-dependencies group (#3926) * (deps) Bump golang from 1.24.1 to 1.24.2 (#3915) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3923) * (deps) Upgrade github.com/wasilibs/go-pgquery (#3927) [1.28.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.28.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-28-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-01-20 ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id13 "Link to this heading") * (mysql) Add a test for VECTOR column type (#3734) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id14 "Link to this heading") * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id15 "Link to this heading") * How-to use transactions with pgx (#3557) * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Correct spelling and grammar (#3645) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id16 "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id17 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) [1.27.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.27.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-27-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-08-05 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id19 "Link to this heading") * (dbmanager) Add leading slash to db uri path rewrite (#3493) * (verify) Include database engine in request (#3522) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id20 "Link to this heading") * (golang) Add initialisms configuration (#3308) * (compiler) Support subqueries in the FROM clause (second coming) (#3310) * Managed databases with any accessible server (#3421) * (vet) Use new dbmanager client (#3423) * (verify) Update verify to work with managed databases (#3425) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id21 "Link to this heading") * Fix typo in config (#3358) * Resolve a typo in configuration keys (#3349) * Add sponsorship information to README (#3413) * Update the language-support to include C# (#3408) * Add migration guide for hosted managed databases (#3417) * Fix readme links (#3424) * Update the managed db and verify documentation (#3426) * Add sponsor image (#3428) * Add Ruby as supported language (#3487) * Update migrating-to-sqlc-gen-kotlin.md (#3454) * Fix typo in comment (#3316) * Fix deprecated build tag format (#3361) ### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id22 "Link to this heading") * (endtoend) Re-use databases when possible (#3315) * Enabled MySQL database (#3318) * Remove internal/sqltest/hosted package (#3521) [1.26.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.26.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-26-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-03-28 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#release-notes "Link to this heading") This release is mainly a bug fix release. It also includes an [important security fix](https://github.com/sqlc-dev/sqlc/issues/3194) for users using output plugins. ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#changes "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id24 "Link to this heading") * (docker) Use distroless base image instead of scratch (#3111) * (generate) Ensure files are created inside output directory (#3195) * (mysql) BREAKING: Use `int16` for MySQL `SMALLINT` and `YEAR` (#3106) * (mysql) BREAKING: Use `int8` for MySQL TINYINT (#3298) * (mysql) Variables not resolving in ORDER BY statements (#3115) * (opts) Validate SQL package and driver options (#3241) * (postgres/batch) Ignore query\_parameter\_limit for batches * (scripts) Remove deprecated test output regeneration script (#3105) * (sqlite) Correctly skip unknown statements (#3239) #### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id25 "Link to this heading") * (postgres) Add instructions for PostGIS/GEOS (#3182) * Improve details on TEXT (#3247) #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id26 "Link to this heading") * (generate) Avoid generating empty Go imports (#3135) * (mysql) Add NEXTVAL() to the MySQL catalog (#3147) * (mysql) Support json.RawMessage for LOAD DATA INFILE (#3099) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id27 "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 to 5.5.5 (#3259) * (deps) Bump modernc.org/sqlite to 1.29.5 (#3200) * (deps) Bump github.com/go-sql-driver/mysql to 1.8.0 (#3257) * (deps) Bump github.com/tetratelabs/wazero to 1.7.0 (#3096) * (deps) Bump github.com/pganalyze/pg\_query\_go to v5 (#3096) [1.25.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.25.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-25-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-01-03 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id29 "Link to this heading") #### Add tags to push and verify[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#add-tags-to-push-and-verify "Link to this heading") You can add tags when [pushing](https://docs.sqlc.dev/en/v1.31.0/howto/push.html) schema and queries to [sqlc Cloud](https://dashboard.sqlc.dev/) . Tags operate like git tags, meaning you can overwrite previously-pushed tag values. We suggest tagging pushes to associate them with something relevant from your environment, e.g. a git tag or branch name. $ sqlc push --tag v1.0.0 Once you’ve created a tag, you can refer to it when [verifying](https://docs.sqlc.dev/en/v1.31.0/howto/verify.html) changes, allowing you to compare the existing schema against a known set of previous queries. $ sqlc verify --against v1.0.0 #### C-ya, `cgo`[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#c-ya-cgo "Link to this heading") Over the last month, we’ve switched out a few different modules to remove our reliance on [cgo](https://go.dev/blog/cgo) . Previously, we needed cgo for three separate functions: * Parsing PostgreSQL queries with [pganalyze/pg\_query\_go](https://github.com/pganalyze/pg_query_go) * Running SQLite databases with [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) * Executing WASM / WASI code with [bytecodealliance/wasmtime-go](https://github.com/bytecodealliance/wasmtime-go) With the help of the community, we found cgo-free alternatives for each module: * Parsing PostgreSQL queries, now using [wasilibs/go-pgquery](https://github.com/wasilibs/go-pgquery) * Running SQLite databases, now using [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) * Executing WASM / WASI code, now using [tetratelabs/wazero](https://github.com/tetratelabs/wazero) For the first time, Windows users can enjoy full PostgreSQL support without using [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) . It’s a Christmas miracle! If you run into any issues with the updated dependencies, please [open an issue](https://github.com/sqlc-dev/sqlc/issues) . ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id30 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id31 "Link to this heading") * (codegen) Wrong yaml annotation in go codegen options for output\_querier\_file\_name (#3006) * (codegen) Use derived ArrayDims instead of deprecated attndims (#3032) * (codegen) Take the maximum array dimensions (#3034) * (compiler) Skip analysis of queries without a `name` annotation (#3072) * (codegen/golang) Don’t import `"strings"` for `sqlc.slice()` with pgx (#3073) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id32 "Link to this heading") * Add name to query set configuration (#3011) * Add a sidebar link for `push`, add Go plugin link (#3023) * Update banner for sqlc-gen-typescript (#3036) * Add strict\_order\_by in doc (#3044) * Re-order the migration tools list (#3064) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id33 "Link to this heading") * (analyzer) Return zero values when encountering unexpected ast nodes (#3069) * (codegen/go) add omit\_sqlc\_version to Go code generation (#3019) * (codgen/go) Add `emit_sql_as_comment` option to Go code plugin (#2735) * (plugins) Use wazero instead of wasmtime (#3042) * (push) Add tag support (#3074) * (sqlite) Support emit\_pointers\_for\_null\_types (#3026) ### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id34 "Link to this heading") * (endtoend) Enable for more build targets (#3041) * (endtoend) Run MySQL and PostgreSQL locally on the runner (#3095) * (typescript) Test against sqlc-gen-typescript (#3046) * Add tests for omit\_sqlc\_version (#3020) * Split schema and query for test (#3094) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id35 "Link to this heading") * (deps) Bump idna from 3.4 to 3.6 in /docs (#3010) * (deps) Bump sphinx-rtd-theme from 1.3.0 to 2.0.0 in /docs (#3016) * (deps) Bump golang from 1.21.4 to 1.21.5 (#3043) * (deps) Bump actions/setup-go from 4 to 5 (#3047) * (deps) Bump github.com/jackc/pgx/v5 from 5.5.0 to 5.5.1 (#3050) * (deps) Upgrade to latest version of github.com/wasilibs/go-pgquery (#3052) * (deps) Bump google.golang.org/grpc from 1.59.0 to 1.60.0 (#3053) * (deps) Bump babel from 2.13.1 to 2.14.0 in /docs (#3055) * (deps) Bump actions/upload-artifact from 3 to 4 (#3061) * (deps) Bump modernc.org/sqlite from 1.27.0 to 1.28.0 (#3062) * (deps) Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#3068) * (deps) Bump google.golang.org/grpc from 1.60.0 to 1.60.1 (#3070) * (deps) Bump google.golang.org/protobuf from 1.31.0 to 1.32.0 (#3079) * (deps) Bump github.com/tetratelabs/wazero from 1.5.0 to 1.6.0 (#3096) * (sqlite) Update to antlr 4.13.1 (#3086) * (sqlite) Disable modernc for WASM (#3048) * (sqlite) Switch from mattn/go-sqlite3 to modernc.org/sqlite (#3040) [1.24.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.24.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-24-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-11-22 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id37 "Link to this heading") #### Verifying database schema changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#verifying-database-schema-changes "Link to this heading") Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. #### Rename `upload` command to `push`[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#rename-upload-command-to-push "Link to this heading") We’ve renamed the `upload` sub-command to `push`. We changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. We also add annotations to each push. By default, we include these environment variables if they are present: GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA Like upload, `push` should be run when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. #### MySQL support in `createdb`[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#mysql-support-in-createdb "Link to this heading") The `createdb` command, added in the last release, now supports MySQL. If you have a cloud project configured, you can use `sqlc createdb` to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html#with-other-tools) documentation. #### Plugin interface refactor[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#plugin-interface-refactor "Link to this heading") This release includes a refactored plugin interface to better support future functionality. Plugins now support different methods via a gRPC service interface, allowing plugins to support different functionality in a backwards-compatible way. By using gRPC interfaces, we can even (theoretically) support [remote plugins](https://github.com/sqlc-dev/sqlc/pull/2938) , but that’s something for another day. ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id38 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id39 "Link to this heading") * (engine/sqlite) Support CASE expr (#2926) * (engine/sqlite) Support -> and ->> operators (#2927) * (vet) Add a nil pointer check to prevent db/prepare panic (#2934) * (compiler) Prevent panic when compiler is nil (#2942) * (codegen/golang) Move more Go-specific config validation into the plugin (#2951) * (compiler) No panic on full-qualified column names (#2956) * (docs) Better discussion of type override nuances (#2972) * (codegen) Never generate return structs for :exec (#2976) * (generate) Update help text for generate to be more generic (#2981) * (generate) Return an error instead of generating duplicate Go names (#2962) * (codegen/golang) Pull opts into its own package (#2920) * (config) Make some struct and field names less confusing (#2922) #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id40 "Link to this heading") * (codegen) Remove Go specific overrides from codegen proto (#2929) * (plugin) Use gRPC interface for codegen plugin communication (#2930) * (plugin) Calculate SHA256 if it does not exist (#2935) * (sqlc-gen-go) Add script to mirror code to sqlc-gen-go (#2952) * (createdb) Add support for MySQL (#2980) * (verify) Add new command to verify queries and migrations (#2986) #### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id41 "Link to this heading") * (ci) New workflow for sqlc-gen-python (#2936) * (ci) Rely on go.mod to determine which Go version to use (#2971) * (tests) Add glob pattern tests to sqlpath.Glob (#2995) * (examples) Use hosted MySQL databases for tests (#2982) * (docs) Clean up a little, update LICENSE and README (#2941) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id42 "Link to this heading") * (deps) Bump babel from 2.13.0 to 2.13.1 in /docs (#2911) * (deps) Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2944) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.17 to 1.14.18 (#2945) * (deps) Bump golang.org/x/sync from 0.4.0 to 0.5.0 (#2946) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2947) * (deps) Change github.com/pingcap/tidb/parser to github.com/pingcap/tidb/pkg/parser * (deps) Bump github.com/google/cel-go from 0.18.1 to 0.18.2 (#2969) * (deps) Bump urllib3 from 2.0.7 to 2.1.0 in /docs (#2975) * (buf) Change root of Buf module (#2987) * (deps) Bump certifi from 2023.7.22 to 2023.11.17 in /docs (#2993) * (ci) Bump Go version from 1.21.3 to 1.21.4 in workflows and Dockerfile (#2961) [1.23.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.23.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-23-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-10-24 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id44 "Link to this heading") #### Database-backed query analysis[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#database-backed-query-analysis "Link to this heading") With a [database connection](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database) configured, `sqlc generate` will gather metadata from that database to support its query analysis. Turning this on resolves a [large number of issues](https://github.com/sqlc-dev/sqlc/issues?q=is%3Aissue+label%3Aanalyzer) in the backlog related to type inference and more complex queries. The easiest way to try it out is with [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html) . The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. #### New `createdb` command[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#new-createdb-command "Link to this heading") When you have a cloud project configured, you can use the new `sqlc createdb` command to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html#with-other-tools) documentation. #### Support for pgvector[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#support-for-pgvector "Link to this heading") If you’re using [pgvector](https://github.com/pgvector/pgvector) , say goodbye to custom overrides! sqlc now generates code using [pgvector-go](https://github.com/pgvector/pgvector-go#pgx) as long as you’re using `pgx`. The pgvector extension is also available in [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html) . #### Go build tags[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#go-build-tags "Link to this heading") With the new `emit_build_tags` configuration parameter you can set build tags for sqlc to add at the top of generated source files. ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id45 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id46 "Link to this heading") * (codegen) Correct column names in :copyfrom (#2838) * (compiler) Search SELECT and UPDATE the same way (#2841) * (dolphin) Support more UNIONs for MySQL (#2843) * (compiler) Account for parameters without parents (#2844) * (postgresql) Remove temporary pool config (#2851) * (golang) Escape reserved keywords (#2849) * (mysql) Handle simplified CASE statements (#2852) * (engine/dolphin) Support enum in ALTER definition (#2680) * (mysql) Add, drop, rename and change enum values (#2853) * (config) Validate `database` config in all cases (#2856) * (compiler) Use correct func signature for `CommentSyntax` on windows (#2867) * (codegen/go) Prevent filtering of embedded struct fields (#2868) * (compiler) Support functions with OUT params (#2865) * (compiler) Pull in array information from analyzer (#2864) * (analyzer) Error on unexpanded star expression (#2882) * (vet) Remove rollback statements from DDL (#2895) #### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id47 "Link to this heading") * Add stable anchors to changelog (#2784) * Fix typo in v1.22.0 changelog (#2796) * Add sqlc upload to CI / CD guide (#2797) * Fix broken link, add clarity to plugins doc (#2813) * Add clarity and reference to JSON tags (#2819) * Replace form with dashboard link (#2840) * (examples) Update examples to use pgx/v5 (#2863) * Use docker compose v2 and update MYSQL\_DATABASE env var (#2870) * Update getting started guides, use pgx for Postgres guide (#2891) * Use managed databases in PostgreSQL getting started guide (#2892) * Update managed databases doc to discuss codegen (#2897) * Add managed dbs to CI/CD and vet guides (#2896) * Document database-backed query analyzer (#2904) #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id48 "Link to this heading") * (codegen) Support setting Go build tags (#2012) (#2807) * (generate) Reorder codegen handlers to prefer plugins (#2814) * (devenv) Add vscode settings.json with auto newline (#2834) * (cmd) Support sqlc.yml configuration file (#2828) * (analyzer) Analyze queries using a running PostgreSQL database (#2805) * (sql/ast) Render AST to SQL (#2815) * (codegen) Include plugin information (#2846) * (postgresql) Add ALTER VIEW … SET SCHEMA (#2855) * (compiler) Parse query parameter metadata from comments (#2850) * (postgresql) Support system columns on tables (#2871) * (compiler) Support LEFT JOIN on aliased table (#2873) * Improve messaging for common cloud config and rpc errors (#2885) * Abort compiler when rpc fails as unauthenticated (#2887) * (codegen) Add support for pgvector and pgvector-go (#2888) * (analyzer) Cache query analysis (#2889) * (createdb) Create ephemeral databases (#2894) * (debug) Add databases=managed debug option (#2898) * (config) Remove managed database validation (#2901) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id49 "Link to this heading") * (endtoend) Fix test output for do tests (#2782) #### Refactor[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id50 "Link to this heading") * (codegen) Remove golang and json settings from plugin proto (#2822) * (codegen) Removed deprecated code and improved speed (#2899) #### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id51 "Link to this heading") * (endtoend) Split shema and queries (#2803) * Fix a few incorrect testcases (#2804) * (analyzer) Add more database analyzer test cases (#2854) * Add more analyzer test cases (#2866) * Add more test cases for new analyzer (#2879) * (endtoend) Enabled managed-db tests in CI (#2883) * Enabled pgvector tests for managed dbs (#2893) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id52 "Link to this heading") * (deps) Bump packaging from 23.1 to 23.2 in /docs (#2791) * (deps) Bump urllib3 from 2.0.5 to 2.0.6 in /docs (#2798) * (deps) Bump babel from 2.12.1 to 2.13.0 in /docs (#2799) * (deps) Bump golang.org/x/sync from 0.3.0 to 0.4.0 (#2810) * (deps) Bump golang from 1.21.1 to 1.21.2 (#2811) * (deps) Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (#2826) * (deps) Bump golang from 1.21.2 to 1.21.3 (#2824) * (deps) Bump google.golang.org/grpc from 1.58.2 to 1.58.3 (#2825) * (deps) Bump golang.org/x/net from 0.12.0 to 0.17.0 (#2836) * (deps) Bump urllib3 from 2.0.6 to 2.0.7 in /docs (#2872) * (deps) Bump google.golang.org/grpc from 1.58.3 to 1.59.0 (#2876) * (deps) Upgrade wasmtime-go from 13.0.0 to 14.0.0 (#2900) #### Ci[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#ci "Link to this heading") * Bump go version in workflows (#2835) [1.22.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.22.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-22-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-26 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id54 "Link to this heading") #### Managed databases for `sqlc vet`[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#managed-databases-for-sqlc-vet "Link to this heading") If you’re using [sqlc vet](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html) to write rules that require access to a running database, `sqlc` can now start and manage that database for you. PostgreSQL support is available today, with MySQL on the way. When you turn on managed databases, `sqlc` will use your schema to create a template database that it can copy to make future runs of `sqlc vet` very performant. This feature relies on configuration obtained via [sqlc Cloud](https://dashboard.sqlc.dev/) . Read more in the [managed databases](https://docs.sqlc.dev/en/v1.31.0/howto/managed-databases.html) documentation. ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id55 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id56 "Link to this heading") * (codegen/golang) Refactor imports code to match templates (#2709) * (codegen/golang) Support name type (#2715) * (wasm) Move Runner struct to shared file (#2725) * (engine/sqlite) Fix grammer to avoid missing join\_constraint (#2732) * (convert) Support YAML anchors in plugin options (#2733) * (mysql) Disallow time.Time in mysql :copyfrom queries, not all queries (#2768) * (engine/sqlite) Fix convert process for VALUES (#2737) #### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id57 "Link to this heading") * Clarify nullable override behavior (#2753) * Add managed databases to sidebar (#2764) * Pull renaming and type overrides into separate sections (#2774) * Update the docs banner for managed dbs (#2775) #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id58 "Link to this heading") * (config) Enables the configuration of copyfrom.go similar to quierer and friends (#2727) * (vet) Run rules against a managed database (#2751) * (upload) Point upload command at new endpoint (#2772) * (compiler) Support DO statements (#2777) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id59 "Link to this heading") * (endtoend) Skip tests missing secrets (#2763) * Skip certain tests on PRs (#2769) #### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id60 "Link to this heading") * (endtoend) Verify all schemas in endtoend (#2744) * (examples) Use a hosted database for example testing (#2749) * (endtoend) Pull region from environment (#2750) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id61 "Link to this heading") * (deps) Bump golang from 1.21.0 to 1.21.1 (#2711) * (deps) Bump google.golang.org/grpc from 1.57.0 to 1.58.1 (#2743) * (deps) Bump wasmtime-go from v12 to v13 (#2756) * (windows) Downgrade to mingw 11.2.0 (#2757) * (deps) Bump urllib3 from 2.0.4 to 2.0.5 in /docs (#2747) * (deps) Bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#2758) * (deps) Bump github.com/google/cel-go from 0.18.0 to 0.18.1 (#2778) #### Ci[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id62 "Link to this heading") * Bump go version to latest in ci workflows (#2722) [1.21.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.21.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-21-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-06 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id64 "Link to this heading") This is primarily a bugfix release, along with some documentation and testing improvements. #### MySQL engine improvements[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#mysql-engine-improvements "Link to this heading") `sqlc` previously didn’t know how to parse a `CALL` statement when using the MySQL engine, which meant it was impossible to use sqlc with stored procedures in MySQL databases. Additionally, `sqlc` now supports `IS [NOT] NULL` in queries. And `LIMIT` and `OFFSET` clauses now work with `UNION`. #### SQLite engine improvements[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sqlite-engine-improvements "Link to this heading") GitHub user [@orisano](https://github.com/orisano) continues to bring bugfixes and improvements to `sqlc`’s SQLite engine. See the “Changes” section below for the full list. #### Plugin access to environment variables[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#plugin-access-to-environment-variables "Link to this heading") If you’re authoring a [sqlc plugin](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#../guides/plugins.html) , you can now configure sqlc to pass your plugin the values of specific environment variables. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id65 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id66 "Link to this heading") * Myriad string formatting changes (#2558) * (engine/sqlite) Support quoted identifier (#2556) * (engine/sqlite) Fix compile error (#2564) * (engine/sqlite) Fixed detection of column alias without AS (#2560) * (ci) Bump go version to 1.20.7 (#2568) * Remove references to deprecated `--experimental` flag (#2567) * (postgres) Fixed a problem with array dimensions disappearing when using “ALTER TABLE ADD COLUMN” (#2572) * Remove GitHub sponsor integration (#2574) * (docs) Improve discussion of prepared statements support (#2604) * (docs) Remove multidimensional array qualification in datatypes.md (#2619) * (config) Go struct tag parsing (#2606) * (compiler) Fix to not scan children under ast.RangeSubselect when retrieving table listing (#2573) * (engine/sqlite) Support NOT IN (#2587) * (codegen/golang) Fixed detection of the used package (#2597) * (engine/dolphin) Fixed problem that LIMIT OFFSET cannot be used with `UNION ALL` (#2613) * (compiler) Support identifiers with schema (#2579) * (compiler) Fix column expansion to work with quoted non-keyword identifiers (#2576) * (codegen/go) Compare define type in codegen (#2263) (#2578) * (engine/sqlite) Fix ast when using compound operator (#2673) * (engine/sqlite) Fix to handle join clauses correctly (#2674) * (codegen) Use correct Go types for bit strings and cid/oid/tid/xid with pgx/v4 (#2668) * (endtoend) Ensure all SQL works against PostgreSQL (#2684) #### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id67 "Link to this heading") * Update Docker installation instructions (#2552) * Missing emit\_pointers\_for\_null\_types configuration option in version 2 (#2682) (#2683) * Fix typo (#2697) * Document sqlc.\* macros (#2698) * (mysql) Document parseTimet=true requirement (#2699) * Add atlas to the list of supported migration frameworks (#2700) * Minor updates to insert howto (#2701) #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id68 "Link to this heading") * (endtoend/testdata) Added two sqlite `CAST` tests and rearranged postgres tests for same (#2551) * (docs) Add a reference to type overriding in datatypes.md (#2557) * (engine/sqlite) Support COLLATE for sqlite WHERE clause (#2554) * (mysql) Add parser support for IS \[NOT\] NULL (#2651) * (engine/dolphin) Support CALL statement (#2614) * (codegen) Allow plugins to access environment variables (#2669) * (config) Add JSON schema files for configs (#2703) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id69 "Link to this heading") * Ignore Vim swap files (#2616) * Fix typo (#2696) #### Refactor[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id70 "Link to this heading") * (astutils) Remove redundant nil check in `Walk` (#2660) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id71 "Link to this heading") * (deps) Bump wasmtime from v8.0.0 to v11.0.0 (#2553) * (deps) Bump golang from 1.20.6 to 1.20.7 (#2563) * (deps) Bump chardet from 5.1.0 to 5.2.0 in /docs (#2562) * (deps) Bump github.com/pganalyze/pg\_query\_go/v4 (#2583) * (deps) Bump golang from 1.20.7 to 1.21.0 (#2596) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.2 to 5.4.3 (#2582) * (deps) Bump pygments from 2.15.1 to 2.16.1 in /docs (#2584) * (deps) Bump sphinxcontrib-applehelp from 1.0.4 to 1.0.7 in /docs (#2620) * (deps) Bump sphinxcontrib-qthelp from 1.0.3 to 1.0.6 in /docs (#2622) * (deps) Bump github.com/google/cel-go from 0.17.1 to 0.17.6 (#2650) * (deps) Bump sphinxcontrib-serializinghtml in /docs (#2641) * Upgrade from Go 1.20 to Go 1.21 (#2665) * (deps) Bump sphinxcontrib-devhelp from 1.0.2 to 1.0.5 in /docs (#2621) * (deps) Bump github.com/bytecodealliance/wasmtime-go from v11.0.0 to v12.0.0 (#2666) * (deps) Bump sphinx-rtd-theme from 1.2.2 to 1.3.0 in /docs (#2670) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.1 to 2.0.4 in /docs (#2671) * (deps) Bump github.com/google/cel-go from 0.17.6 to 0.18.0 (#2691) * (deps) Bump actions/checkout from 3 to 4 (#2694) * (deps) Bump pytz from 2023.3 to 2023.3.post1 in /docs (#2695) * (devenv) Bump go from 1.20.7 to 1.21.0 (#2702) [1.20.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.20.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#v1-20-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-31 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id73 "Link to this heading") #### `kyleconroy/sqlc` is now `sqlc-dev/sqlc`[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#kyleconroy-sqlc-is-now-sqlc-dev-sqlc "Link to this heading") We’ve completed our migration to the [sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc) repository. All existing links and installation instructions will continue to work. If you’re using the `go` tool to install `sqlc`, you’ll need to use the new import path to get v1.20.0 (and all future versions). \# INCORRECT: old import path go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.20.0 \# CORRECT: new import path go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.20.0 We designed the upgrade process to be as smooth as possible. If you run into any issues, please [file a bug report](https://github.com/sqlc-dev/sqlc/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=BUG_REPORT.yml) via GitHub. #### Use `EXPLAIN ...` output in lint rules[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#use-explain-output-in-lint-rules "Link to this heading") `sqlc vet` can now run `EXPLAIN` on your queries and include the results for use in your lint rules. For example, this rule checks that `SELECT` queries use an index. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- has-index rules: \- name: has-index rule: \> query.sql.startsWith("SELECT") && !(postgresql.explain.plan.plans.all(p, has(p.index\_name) || p.plans.all(p, has(p.index\_name)))) The expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.31.0/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. #### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; #### Bulk insert for MySQL[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#bulk-insert-for-mysql "Link to this heading") _Developed by [@Jille](https://github.com/Jille) _ MySQL now supports the `:copyfrom` query annotation. The generated code uses the [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) command to insert data quickly and efficiently. Use caution with this feature. Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use `SHOW WARNINGS` to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } `LOAD DATA` support must be enabled in the MySQL server. #### CAST support for MySQL[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#cast-support-for-mysql "Link to this heading") _Developed by [@ryanpbrewster](https://github.com/ryanpbrewster) and [@RadhiFadlillah](https://github.com/RadhiFadlillah) _ `sqlc` now understands `CAST` calls in MySQL queries, offering greater flexibility when generating code for complex queries. CREATE TABLE foo (bar BOOLEAN NOT NULL); \-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo; package querytest import ( "context" ) const selectColumnCast \= \`-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo \` func (q \*Queries) SelectColumnCast(ctx context.Context) (\[\]int64, error) { ... } #### SQLite improvements[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sqlite-improvements "Link to this heading") A slew of fixes landed for our SQLite implementation, bringing it closer to parity with MySQL and PostgreSQL. We want to thank [@orisano](https://github.com/orisano) for their continued dedication to improving `sqlc`’s SQLite support. ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id74 "Link to this heading") #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id75 "Link to this heading") * (debug) Add debug flag and docs for dumping vet rule variables (#2521) * (mysql) :copyfrom support via LOAD DATA INFILE (#2545) * (mysql) Implement cast function parser (#2473) * (postgresql) Add support for PostgreSQL multi-dimensional arrays (#2338) * (sql/catalog) Support ALTER TABLE IF EXISTS (#2542) * (sqlite) Virtual tables and fts5 supported (#2531) * (vet) Add default query parameters for explain queries (#2543) * (vet) Add output from `EXPLAIN ...` for queries to the CEL program environment (#2489) * (vet) Introduce a query annotation to opt out of sqlc vet rules (#2474) * Parse comment lines starting with `@symbol` as boolean flags associated with a query (#2464) #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id76 "Link to this heading") * (codegen/golang) Fix sqlc.embed to work with pq.Array (#2544) * (compiler) Correctly validate alias in order/group by clauses for joins (#2537) * (engine/sqlite) Added function to convert cast node (#2470) * (engine/sqlite) Fix join\_operator rule (#2434) * (engine/sqlite) Fix table\_alias rules (#2465) * (engine/sqlite) Fixed IN operator precedence (#2428) * (engine/sqlite) Fixed to be able to find relation from WITH clause (#2444) * (engine/sqlite) Lowercase ast.ResTarget.Name (#2433) * (engine/sqlite) Put logging statement behind debug flag (#2488) * (engine/sqlite) Support for repeated table\_option (#2482) * (mysql) Generate unsigned param (#2522) * (sql/catalog) Support pg\_dump output (#2508) * (sqlite) Code generation for sqlc.slice (#2431) * (vet) Clean up unnecessary `prepareable()` func and a var name (#2509) * (vet) Query.cmd was always set to “:” (#2525) * (vet) Report an error when a query is unpreparable, close prepared statement connection (#2486) * (vet) Split vet messages out of codegen.proto (#2511) #### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id77 "Link to this heading") * Add a description to the document for cases when a query result has no rows (#2462) * Update copyright and author (#2490) * Add example sqlc.yaml for migration parsing (#2479) * Small updates (#2506) * Point GitHub links to new repository location (#2534) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id78 "Link to this heading") * Rename kyleconroy/sqlc to sqlc-dev/sqlc (#2523) * (proto) Reformat protos using `buf format -w` (#2536) * Update FEATURE\_REQUEST.yml to include SQLite engine option * Finish migration to sqlc-dev/sqlc (#2548) * (compiler) Remove some duplicate code (#2546) #### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id79 "Link to this heading") * Add profiles to docker compose (#2503) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id80 "Link to this heading") * Run all supported versions of MySQL / PostgreSQL (#2463) * (deps) Bump pygments from 2.7.4 to 2.15.0 in /docs (#2485) * (deps) Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2483) * (deps) Bump github.com/google/cel-go from 0.16.0 to 0.17.1 (#2484) * (docs) Check Python dependencies via dependabot (#2497) * (deps) Bump idna from 2.10 to 3.4 in /docs (#2499) * (deps) Bump packaging from 20.9 to 23.1 in /docs (#2498) * (deps) Bump pygments from 2.15.0 to 2.15.1 in /docs (#2500) * (deps) Bump certifi from 2022.12.7 to 2023.7.22 in /docs (#2504) * (deps) Bump sphinx from 4.4.0 to 6.1.0 in /docs (#2505) * Add psql and mysqlsh to devenv (#2507) * (deps) Bump urllib3 from 1.26.5 to 2.0.4 in /docs (#2516) * (deps) Bump chardet from 4.0.0 to 5.1.0 in /docs (#2517) * (deps) Bump snowballstemmer from 2.1.0 to 2.2.0 in /docs (#2519) * (deps) Bump pytz from 2021.1 to 2023.3 in /docs (#2520) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.0 to 2.0.1 in /docs (#2518) * (deps) Bump pyparsing from 2.4.7 to 3.1.0 in /docs (#2530) * (deps) Bump alabaster from 0.7.12 to 0.7.13 in /docs (#2526) * (docs) Ignore updates for sphinx (#2532) * (deps) Bump babel from 2.9.1 to 2.12.1 in /docs (#2527) * (deps) Bump sphinxcontrib-applehelp from 1.0.2 to 1.0.4 in /docs (#2533) * (deps) Bump google.golang.org/grpc from 1.56.2 to 1.57.0 (#2535) * (deps) Bump pyparsing from 3.1.0 to 3.1.1 in /docs (#2547) [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id81 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id82 "Link to this heading") * Fix to traverse Sel in ast.In (#2414) * (compiler) Validate UNION … ORDER BY (#2446) * (golang) Prevent duplicate enum output (#2447) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id83 "Link to this heading") * Replace codegen, test and docs references to github.com/tabbed repos (#2418) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id84 "Link to this heading") * (deps) Bump google.golang.org/grpc from 1.56.1 to 1.56.2 (#2415) * (deps) Bump golang from 1.20.5 to 1.20.6 (#2437) * Pin Go to 1.20.6 (#2441) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.1 to 5.4.2 (#2436) [1.19.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id85 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-06 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id86 "Link to this heading") #### sqlc vet[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sqlc-vet "Link to this heading") [`sqlc vet`](https://docs.sqlc.dev/en/v1.31.0/howto/vet.html) runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.31.0/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, an error is reported using the given message. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ##### Database connectivity[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#database-connectivity "Link to this heading") `vet` also marks the first time that `sqlc` can connect to a live, running database server. We’ll expand this functionality over time, but for now it powers the `sqlc/db-prepare` built-in rule. When a [database](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#config.html#database) is configured, the `sqlc/db-preapre` rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Please note that `sqlc` does not manage or migrate your database. Use your migration tool of choice to create the necessary database tables and objects before running `sqlc vet`. #### Omit unused structs[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#omit-unused-structs "Link to this heading") Added a new configuration parameter `omit_unused_structs` which, when set to true, filters out table and enum structs that aren’t used in queries for a given package. #### Suggested CI/CD setup[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#suggested-ci-cd-setup "Link to this heading") With the addition of `sqlc diff` and `sqlc vet`, we encourage users to run sqlc in your CI/CD pipelines. See our [suggested CI/CD setup](https://docs.sqlc.dev/en/v1.31.0/howto/ci-cd.html) for more information. #### Simplified plugin development[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#simplified-plugin-development "Link to this heading") The [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) and [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) plugins have been updated use the upcoming [WASI](https://wasi.dev/) support in [Go 1.21](https://tip.golang.org/doc/go1.21#wasip1) . Building these plugins no longer requires [TinyGo](https://tinygo.org/) . ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id87 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id88 "Link to this heading") * Pointers overrides skip imports in generated query files (#2240) * CASE-ELSE clause is not properly parsed when a value is constant (#2238) * Fix toSnakeCase to handle input in CamelCase format (#2245) * Add location info to sqlite ast (#2298) * Add override tags to result struct (#1867) (#1887) * Override types of aliased columns and named parameters (#1884) * Resolve duplicate fields generated when inheriting multiple tables (#2089) * Check column references in ORDER BY (#1411) (#1915) * MySQL slice shadowing database/sql import (#2332) * Don’t defer rows.Close() if pgx.BatchResults.Query() failed (#2362) * Fix type overrides not working with sqlc.slice (#2351) * Type overrides on columns for parameters inside an IN clause (#2352) * Broken interaction between query\_parameter\_limit and pq.Array() (#2383) * (codegen/golang) Bring :execlastid in line with the rest (#2378) #### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id89 "Link to this heading") * Update changelog.md with some minor edits (#2235) * Add F# community plugin (#2295) * Add a ReadTheDocs config file (#2327) * Update query\_parameter\_limit documentation (#2374) * Add launch announcement banner #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id90 "Link to this heading") * PostgreSQL capture correct line and column numbers for parse error (#2289) * Add supporting COMMENT ON VIEW (#2249) * To allow spaces between function name and arguments of functions to be rewritten (#2250) * Add support for pgx/v5 emit\_pointers\_for\_null\_types flag (#2269) * (mysql) Support unsigned integers (#1746) * Allow use of table and column aliases for table functions returning unknown types (#2156) * Support “LIMIT ?” in UPDATE and DELETE for MySQL (#2365) * (internal/codegen/golang) Omit unused structs from output (#2369) * Improve default names for BETWEEN ? AND ? to have prefixes from\_ and to\_ (#2366) * (cmd/sqlc) Add the vet subcommand (#2344) * (sqlite) Add support for UPDATE/DELETE with a LIMIT clause (#2384) * Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) (#2373) * (cmd/vet) Prepare queries against a database (#2387) * (cmd/vet) Prepare queries for MySQL (#2388) * (cmd/vet) Prepare SQLite queries (#2389) * (cmd/vet) Simplify environment variable substiution (#2393) * (cmd/vet) Add built-in db-prepare rule * Add compiler support for NOTIFY and LISTEN (PostgreSQL) (#2363) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id91 "Link to this heading") * A few small staticcheck fixes (#2361) * Remove a bunch of dead code (#2360) * (scripts/regenerate) Should also update stderr.txt (#2379) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id92 "Link to this heading") * (deps) Bump requests from 2.25.1 to 2.31.0 in /docs (#2283) * (deps) Bump golang from 1.20.3 to 1.20.4 (#2256) * (deps) Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#2265) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 (#2293) * (deps) Bump golang.org/x/sync from 0.1.0 to 0.2.0 (#2266) * (deps) Bump golang from 1.20.4 to 1.20.5 (#2301) * Configure dependencies via devenv.sh (#2319) * Configure dependencies via devenv.sh (#2326) * (deps) Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#2328) * (deps) Bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#2333) * (deps) Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 (#2370) * (deps) Bump actions/checkout from 2 to 3 (#2357) * Run govulncheck on all builds (#2372) * (deps) Bump google.golang.org/grpc from 1.56.0 to 1.56.1 (#2358) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#cmd-sqlc "Link to this heading") * Show helpful output on missing subcommand (#2345) #### Codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#codegen "Link to this heading") * Use catalog’s default schema (#2310) * (go) Add tests for tables with dashes (#2312) * (go) Strip invalid characters from table and column names (#2314) * (go) Support JSON tags for nullable enum structs (#2121) #### Internal/config[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-config "Link to this heading") * Support golang overrides for slices (#2339) #### Kotlin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#kotlin "Link to this heading") * Use latest version of sqlc-gen-kotlin (#2356) #### Postgres[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#postgres "Link to this heading") * Column merging for table inheritence (#2315) #### Protos[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#protos "Link to this heading") * Add missing field name (#2354) #### Python[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#python "Link to this heading") * Use latest version of sqlc-gen-python (#2355) #### Remote[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#remote "Link to this heading") * Use user-id/password auth (#2262) #### Sqlite[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sqlite "Link to this heading") * Fixed sqlite column type override (#1986) [1.18.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.18.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id93 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-04-27 ### Release notes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id94 "Link to this heading") #### Remote code generation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#remote-code-generation "Link to this heading") _Developed by [@andrewmbenton](https://github.com/andrewmbenton) _ At its core, sqlc is powered by SQL engines, which include parsers, formatters, analyzers and more. While our goal is to support each engine on each operating system, it’s not always possible. For example, the PostgreSQL engine does not work on Windows. To bridge that gap, we’re announcing remote code generation, currently in private alpha. To join the private alpha, [sign up for the waitlist](https://docs.google.com/forms/d/e/1FAIpQLScDWrGtTgZWKt3mdlF5R2XCX6tL1pMkB4yuZx5yq684tTNN1Q/viewform?usp=sf_link) . Remote code generation works like local code generation, except the heavy lifting is performed in a consistent cloud environment. WASM-based plugins are supported in the remote environment, but process-based plugins are not. To configure remote generation, add a `cloud` block in `sqlc.json`. { "version": "2", "cloud": { "organization": "", "project": "", }, ... } You’ll also need to set the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\= When the `cloud` configuration block exists, `sqlc generate` will default to remote code generation. If you’d like to generate code locally without removing the `cloud` block from your config, pass the `--no-remote` option. sqlc generate \--no-remote Remote generation is off by default and requires an opt-in to use. #### sqlc.embed[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sqlc-embed "Link to this heading") _Developed by [@nickjackson](https://github.com/nickjackson) _ Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ) CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ) We want to select the student record and the highest score they got on a test. Here’s how we’d usually do that: \-- name: HighScore :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT students.\*, high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; When using Go, sqlc will produce a struct like this: type HighScoreRow struct { ID int64 Name sql.NullString Age sql.NullInt32 HighScore int32 } With embedding, the struct will contain a model for the table instead of a flattened list of columns. \-- name: HighScoreEmbed :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT sqlc.embed(students), high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; type HighScoreRow struct { Student Student HighScore int32 } #### sqlc.slice[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sqlc-slice "Link to this heading") _Developed by Paul Cameron and Jille Timmermans_ The MySQL Go driver does not support passing slices to the IN operator. The `sqlc.slice` function generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) func (q \*Queries) SelectStudents(ctx context.Context, ages \[\]int32) (\[\]Student, error) { This feature is only supported in MySQL and cannot be used with prepared queries. #### Batch operation improvements[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#batch-operation-improvements "Link to this heading") When using batches with pgx, the error returned when a batch is closed is exported by the generated package. This change allows for cleaner error handling using `errors.Is`. errors.Is(err, generated\_package.ErrBatchAlreadyClosed) Previously, you would have had to check match on the error message itself. err.Error() \== "batch already closed" The generated code for batch operations always lived in `batch.go`. This file name can now be configured via the `output_batch_file_name` configuration option. #### Configurable query parameter limits for Go[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#configurable-query-parameter-limits-for-go "Link to this heading") By default, sqlc will limit Go functions to a single parameter. If a query includes more than one parameter, the generated method will use an argument struct instead of positional arguments. This behavior can now be changed via the `query_parameter_limit` configuration option. If set to `0`, every genreated method will use a argument struct. ### Changes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id95 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id96 "Link to this heading") * Prevent variable redeclaration in single param conflict for pgx (#2058) * Retrieve Larg/Rarg join query after inner join (#2051) * Rename argument when conflicted to imported package (#2048) * Pgx closed batch return pointer if need #1959 (#1960) * Correct singularization of “waves” (#2194) * Honor Package level renames in v2 yaml config (#2001) * (mysql) Prevent UPDATE … JOIN panic #1590 (#2154) * Mysql delete join panic (#2197) * Missing import with pointer overrides, solves #2168 #2125 (#2217) #### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id97 "Link to this heading") * (config.md) Add `sqlite` as engine option (#2164) * Add first pass at pgx documentation (#2174) * Add missed configuration option (#2188) * `specifies parameter ":one" without containing a RETURNING clause` (#2173) #### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id98 "Link to this heading") * Add `sqlc.embed` to allow model re-use (#1615) * (Go) Add query\_parameter\_limit conf to codegen (#1558) * Add remote execution for codegen (#2214) #### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id99 "Link to this heading") * Skip tests if required plugins are missing (#2104) * Add tests for reanme fix in v2 (#2196) * Regenerate batch output for filename tests * Remove remote test (#2232) * Regenerate test output #### Bin/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#bin-sqlc "Link to this heading") * Add SQLCTMPDIR environment variable (#2189) #### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id100 "Link to this heading") * (deps) Bump github.com/antlr/antlr4/runtime/Go/antlr (#2109) * (deps) Bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 (#2119) * (deps) Bump golang from 1.20.1 to 1.20.2 (#2135) * (deps) Bump google.golang.org/protobuf from 1.28.1 to 1.29.0 (#2137) * (deps) Bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#2143) * (deps) Bump golang from 1.20.2 to 1.20.3 (#2192) * (deps) Bump actions/setup-go from 3 to 4 (#2150) * (deps) Bump google.golang.org/protobuf from 1.29.1 to 1.30.0 (#2151) * (deps) Bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#2193) * (deps) Bump github.com/lib/pq from 1.10.7 to 1.10.8 (#2211) * (deps) Bump github.com/lib/pq from 1.10.8 to 1.10.9 (#2229) * (deps) Bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 (#2228) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id101 "Link to this heading") * Remove –experimental flag (#2170) * Add option to disable process-based plugins (#2180) * Bump version to v1.18.0 #### Codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id102 "Link to this heading") * Correctly generate CopyFrom columns for single-column copyfroms (#2185) #### Config[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#config "Link to this heading") * Add top-level cloud configuration (#2204) #### Engine/postgres[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#engine-postgres "Link to this heading") * Upgrade to pg\_query\_go/v4 (#2114) #### Ext/wasm[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#ext-wasm "Link to this heading") * Check exit code on returned error (#2223) #### Parser[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#parser "Link to this heading") * Generate correct types for `SELECT NOT EXISTS` (#1972) #### Sqlite[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id103 "Link to this heading") * Add support for CREATE TABLE … STRICT (#2175) #### Wasm[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#wasm "Link to this heading") * Upgrade to wasmtime v8.0.0 (#2222) [1.17.2](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.2) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id104 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id105 "Link to this heading") * Fix build on Windows (#2102) [1.17.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.1) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id106 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id107 "Link to this heading") * Prefer to use \[\]T over pgype.Array\[T\] (#2090) * Revert changes to Dockerfile (#2091) * Do not throw error when IF NOT EXISTS is used on ADD COLUMN (#2092) ### MySQL[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#mysql "Link to this heading") * Add `float` support to MySQL (#2097) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id108 "Link to this heading") * (deps) Bump golang from 1.20.0 to 1.20.1 (#2082) [1.17.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id109 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id110 "Link to this heading") * Initialize generated code outside function (#1850) * (engine/mysql) Take into account column’s charset to distinguish text/blob, (var)char/(var)binary (#776) (#1895) * The enum Value method returns correct type (#1996) * Documentation for Inserting Rows (#2034) * Add import statements even if only pointer types exist (#2046) * Search from Rexpr if not found from Lexpr (#2056) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id111 "Link to this heading") * Change ENTRYPOINT to CMD (#1943) * Update samples for HOW-TO GUIDES (#1953) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id112 "Link to this heading") * Add the diff command (#1963) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id113 "Link to this heading") * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.15 to 1.14.16 (#1913) * (deps) Bump github.com/spf13/cobra from 1.6.0 to 1.6.1 (#1909) * Fix devcontainer (#1942) * Run sqlc-pg-gen via GitHub Actions (#1944) * Move large arrays out of functions (#1947) * Fix conflicts from pointer configuration (#1950) * (deps) Bump github.com/go-sql-driver/mysql from 1.6.0 to 1.7.0 (#1988) * (deps) Bump github.com/jackc/pgtype from 1.12.0 to 1.13.0 (#1978) * (deps) Bump golang from 1.19.3 to 1.19.4 (#1992) * (deps) Bump certifi from 2020.12.5 to 2022.12.7 in /docs (#1993) * (deps) Bump golang from 1.19.4 to 1.19.5 (#2016) * (deps) Bump golang from 1.19.5 to 1.20.0 (#2045) * (deps) Bump github.com/jackc/pgtype from 1.13.0 to 1.14.0 (#2062) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.0 (#2063) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#cmd "Link to this heading") * Generate packages in parallel (#2026) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id114 "Link to this heading") * Bump version to v1.17.0 ### Codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id115 "Link to this heading") * Remove built-in Kotlin support (#1935) * Remove built-in Python support (#1936) ### Internal/codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-codegen "Link to this heading") * Cache pattern matching compilations (#2028) ### Mysql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id116 "Link to this heading") * Add datatype tests (#1948) * Fix blob tests (#1949) ### Plugins[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#plugins "Link to this heading") * Upgrade to wasmtime 3.0.1 (#2009) ### Sqlite[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id117 "Link to this heading") * Supported between expr (#1958) (#1967) ### Tools[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#tools "Link to this heading") * Regenerate scripts skips dirs that contains diff exec command (#1987) ### Wasm[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id118 "Link to this heading") * Upgrade to wasmtime 5.0.0 (#2065) [1.16.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.16.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id119 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-11-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id120 "Link to this heading") * (validate) Sqlc.arg & sqlc.narg are not “missing” (#1814) * Emit correct comment for nullable enums (#1819) * 🐛 Correctly switch `coalesce()` result `.NotNull` value (#1664) * Prevent batch infinite loop with arg length (#1794) * Support version 2 in error message (#1839) * Handle empty column list in postgresql (#1843) * Batch imports filter queries, update cmds having ret type (#1842) * Named params contribute to batch parameter count (#1841) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id121 "Link to this heading") * Add a getting started guide for SQLite (#1798) * Various readability improvements (#1854) * Add documentation for codegen plugins (#1904) * Update migration guides with links (#1933) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id122 "Link to this heading") * Add HAVING support to MySQL (#1806) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id123 "Link to this heading") * Upgrade wasmtime version (#1827) * Bump wasmtime version to v1.0.0 (#1869) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id124 "Link to this heading") * (deps) Bump github.com/jackc/pgconn from 1.12.1 to 1.13.0 (#1785) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.13 to 1.14.15 (#1799) * (deps) Bump github.com/jackc/pgx/v4 from 4.16.1 to 4.17.0 (#1786) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.0 to 4.17.1 (#1825) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1826) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.1 to 4.17.2 (#1831) * (deps) Bump golang from 1.19.0 to 1.19.1 (#1834) * (deps) Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#1838) * (deps) Bump github.com/lib/pq from 1.10.6 to 1.10.7 (#1835) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1857) * (deps) Bump github.com/spf13/cobra from 1.5.0 to 1.6.0 (#1893) * (deps) Bump golang from 1.19.1 to 1.19.3 (#1920) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id125 "Link to this heading") * Bump to v1.16.0 ### Codgen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#codgen "Link to this heading") * Include serialized codegen options (#1890) ### Compiler[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#compiler "Link to this heading") * Move Kotlin parameter logic into codegen (#1910) ### Examples[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#examples "Link to this heading") * Port Python examples to WASM plugin (#1903) ### Pg-gen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#pg-gen "Link to this heading") * Make sqlc-pg-gen the complete source of truth for pg\_catalog.go (#1809) * Implement information\_schema shema (#1815) ### Python[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id126 "Link to this heading") * Port all Python tests to sqlc-gen-python (#1907) * Upgrade to sqlc-gen-python v1.0.0 (#1932) [1.15.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.15.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id127 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-08-07 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id128 "Link to this heading") * (mysql) Typo (#1700) * (postgresql) Add quotes for CamelCase columns (#1729) * Cannot parse SQLite upsert statement (#1732) * (sqlite) Regenerate test output for builtins (#1735) * (wasm) Version modules by wasmtime version (#1734) * Missing imports (#1637) * Missing slice import for querier (#1773) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id129 "Link to this heading") * Add process-based plugin docs (#1669) * Add links to downloads.sqlc.dev (#1681) * Update transactions how to example (#1775) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id130 "Link to this heading") * More SQL Syntax Support for SQLite (#1687) * (sqlite) Promote SQLite support to beta (#1699) * Codegen plugins, powered by WASM (#1684) * Set user-agent for plugin downloads (#1707) * Null enums types (#1485) * (sqlite) Support stdlib functions (#1712) * (sqlite) Add support for returning (#1741) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id131 "Link to this heading") * Add tests for quoting columns (#1733) * Remove catalog tests (#1762) ### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id132 "Link to this heading") * Add tests for fixing slice imports (#1736) * Add test cases for returning (#1737) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id133 "Link to this heading") * Upgrade to Go 1.19 (#1780) * Upgrade to go-wasmtime 0.39.0 (#1781) ### Plugins[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id134 "Link to this heading") * (wasm) Change default cache location (#1709) * (wasm) Change the SHA-256 config key (#1710) [1.14.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.14.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id135 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-06-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id136 "Link to this heading") * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) * (compiler) Fix left join nullability with table aliases (#1491) * Regenerate testdata for CREATE TABLE AS (#1516) * (bundler) Only close multipart writer once (#1528) * (endtoend) Regenerate testdata for exex\_lastid * (pgx) Copyfrom imports (#1626) * Validate sqlc function arguments (#1633) * Fixed typo `sql.narg` in doc (#1668) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id137 "Link to this heading") * (golang) Add Enum.Valid and AllEnumValues (#1613) * (sqlite) Start expanding support (#1410) * (pgx) Add support for batch operations (#1437) * (sqlite) Add support for delete statements (#1447) * (codegen) Insert comments in interfaces (#1458) * (sdk) Add the plugin SDK package (#1463) * Upload projects (#1436) * Add sqlc version to generated Kotlin code (#1512) * Add sqlc version to generated Go code (#1513) * Pass sqlc version in codegen request (#1514) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * Run sqlc with docker on windows cmd (#1557) * Add JSON “codegen” output (#1565) * Add sqlc.narg() for nullable named params (#1536) * Process-based codegen plugins (#1578) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id138 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id139 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) * (sql/catalog) Improve Readability (#1595) * Add basic fuzzing for config / overrides (#1500) [1.13.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.13.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id140 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-03-31 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id141 "Link to this heading") * (compiler) Fix left join nullability with table aliases (#1491) * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id142 "Link to this heading") * (cli) Upload projects (#1436) * (codegen) Add sqlc version to generated Go code (#1513) * (codegen) Add sqlc version to generated Kotlin code (#1512) * (codegen) Insert comments in interfaces (#1458) * (codegen) Pass sqlc version in codegen request (#1514) * (pgx) Add support for batch operations (#1437) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * (sdk) Add the plugin SDK package (#1463) * (sqlite) Add support for delete statements (#1447) * (sqlite) Start expanding support (#1410) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id143 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id144 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) ### Config[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id145 "Link to this heading") * Add basic fuzzing for config / overrides (#1500) [1.12.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.12.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id146 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-02-05 ### Bug[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#bug "Link to this heading") * ALTER TABLE SET SCHEMA (#1409) ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id147 "Link to this heading") * Update ANTLR v4 go.mod entry (#1336) * Check delete statements for CTEs (#1329) * Fix validation of GROUP BY on field aliases (#1348) * Fix imports when non-copyfrom queries needed imports that copyfrom queries didn’t (#1386) * Remove extra comment newline (#1395) * Enable strict function checking (#1405) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id148 "Link to this heading") * Bump version to 1.11.0 (#1308) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id149 "Link to this heading") * Inheritance (#1339) * Generate query code using ASTs instead of templates (#1338) * Add support for CREATE TABLE a ( LIKE b ) (#1355) * Add support for sql.NullInt16 (#1376) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id150 "Link to this heading") * Add tests for :exec{result,rows} (#1344) * Delete template-based codegen (#1345) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id151 "Link to this heading") * Bump github.com/jackc/pgx/v4 from 4.14.0 to 4.14.1 (#1316) * Bump golang from 1.17.3 to 1.17.4 (#1331) * Bump golang from 1.17.4 to 1.17.5 (#1337) * Bump github.com/spf13/cobra from 1.2.1 to 1.3.0 (#1343) * Remove devel Docker build * Bump golang from 1.17.5 to 1.17.6 (#1369) * Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 (#1382) * Format all Go code (#1387) [1.11.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.11.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id152 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-11-24 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id153 "Link to this heading") * Update incorrect signatures (#1180) * Correct aggregate func sig (#1182) * Jsonb\_build\_object (#1211) * Case-insensitive identifiers (#1216) * Incorrect handling of meta (#1228) * Detect invalid INSERT expression (#1231) * Respect alias name for coalesce (#1232) * Mark nullable when casting NULL (#1233) * Support nullable fields in joins for MySQL engine (#1249) * Fix between expression handling of table references (#1268) * Support nullable fields in joins on same table (#1270) * Fix missing binds in ORDER BY (#1273) * Set RV for TargetList items on updates (#1252) * Fix MySQL parser for query without trailing semicolon (#1282) * Validate table alias references (#1283) * Add support for MySQL ON DUPLICATE KEY UPDATE (#1286) * Support references to columns in joined tables in UPDATE statements (#1289) * Add validation for GROUP BY clause column references (#1285) * Prevent variable redeclaration in single param conflict (#1298) * Use common params struct field for same named params (#1296) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id154 "Link to this heading") * Replace deprecated go get with go install (#1181) * Fix package name referenced in tutorial (#1202) * Add environment variables (#1264) * Add go.17+ install instructions (#1280) * Warn about golang-migrate file order (#1302) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id155 "Link to this heading") * Instrument compiler via runtime/trace (#1258) * Add MySQL support for BETWEEN arguments (#1265) ### Refactor[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id156 "Link to this heading") * Move from io/ioutil to io and os package (#1164) ### Styling[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#styling "Link to this heading") * Apply gofmt to sample code (#1261) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id157 "Link to this heading") * Bump golang from 1.17.0 to 1.17.1 (#1173) * Bump eskatos/gradle-command-action from 1 to 2 (#1220) * Bump golang from 1.17.1 to 1.17.2 (#1227) * Bump github.com/pganalyze/pg\_query\_go/v2 (#1234) * Bump actions/checkout from 2.3.4 to 2.3.5 (#1238) * Bump babel from 2.9.0 to 2.9.1 in /docs (#1245) * Bump golang from 1.17.2 to 1.17.3 (#1272) * Bump actions/checkout from 2.3.5 to 2.4.0 (#1267) * Bump github.com/lib/pq from 1.10.3 to 1.10.4 (#1278) * Bump github.com/jackc/pgx/v4 from 4.13.0 to 4.14.0 (#1303) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id158 "Link to this heading") * Bump version to v1.11.0 [1.10.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.10.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id159 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-09-07 ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id160 "Link to this heading") * Fix invalid language support table (#1161) * Add a getting started guide for MySQL (#1163) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id161 "Link to this heading") * Bump golang from 1.16.7 to 1.17.0 (#1129) * Bump github.com/lib/pq from 1.10.2 to 1.10.3 (#1160) ### Ci[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id162 "Link to this heading") * Upgrade Go to 1.17 (#1130) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id163 "Link to this heading") * Bump version to v1.10.0 (#1165) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#codegen-golang "Link to this heading") * Consolidate import logic (#1139) * Add pgx support for range types (#1146) * Use pgtype for hstore when using pgx (#1156) ### Codgen/golang[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#codgen-golang "Link to this heading") * Use p\[gq\]type for network address types (#1142) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#endtoend "Link to this heading") * Run `go test` in CI (#1134) ### Engine/mysql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#engine-mysql "Link to this heading") * Add support for LIKE (#1162) ### Golang[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#golang "Link to this heading") * Output NullUUID when necessary (#1137) [1.9.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.9.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id164 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-08-13 ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id165 "Link to this heading") * Update documentation (a bit) for v1.9.0 (#1117) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id166 "Link to this heading") * Bump golang from 1.16.6 to 1.16.7 (#1107) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id167 "Link to this heading") * Bump version to v1.9.0 (#1121) ### Compiler[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id168 "Link to this heading") * Add tests for COALESCE behavior (#1112) * Handle subqueries in SELECT statements (#1113) [1.8.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.8.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id169 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-05-03 ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id170 "Link to this heading") * Add language support Matrix (#920) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id171 "Link to this heading") * Add case style config option (#905) ### Python[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id172 "Link to this heading") * Eliminate runtime package and use sqlalchemy (#939) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id173 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.4 to 0.5.5 (#926) * Bump github.com/lib/pq from 1.9.0 to 1.10.0 (#931) * Bump golang from 1.16.0 to 1.16.1 (#935) * Bump golang from 1.16.1 to 1.16.2 (#942) * Bump github.com/jackc/pgx/v4 from 4.10.1 to 4.11.0 (#956) * Bump github.com/go-sql-driver/mysql from 1.5.0 to 1.6.0 (#961) * Bump github.com/pganalyze/pg\_query\_go/v2 (#965) * Bump urllib3 from 1.26.3 to 1.26.4 in /docs (#968) * Bump golang from 1.16.2 to 1.16.3 (#963) * Bump github.com/lib/pq from 1.10.0 to 1.10.1 (#980) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id174 "Link to this heading") * Add the –experimental flag (#929) * Fix sqlc init (#959) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id175 "Link to this heading") * Bump version to v1.7.1-devel (#913) * Bump version to v1.8.0 ### Codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id176 "Link to this heading") * Generate valid enum names for symbols (#972) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#postgresql "Link to this heading") * Support generated columns * Add test for PRIMARY KEY INCLUDE * Add tests for CREATE TABLE PARTITION OF * CREATE TRIGGER EXECUTE FUNCTION * Add support for renaming types (#971) ### Sql/ast[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sql-ast "Link to this heading") * Resolve return values from functions (#964) ### Workflows[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#workflows "Link to this heading") * Only run tests once (#924) [1.7.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.7.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id177 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-02-28 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id178 "Link to this heading") * Struct tag formatting (#833) ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id179 "Link to this heading") * Include all the existing Markdown files (#877) * Split docs into four sections (#882) * Reorganize and consolidate documentation * Add link to Windows download (#888) * Shorten the README (#889) ### Features[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id180 "Link to this heading") * Adding support for pgx/v4 * Adding support for pgx/v4 ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#readme "Link to this heading") * Add Go Report Card badge (#891) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id181 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.3 to 0.5.4 (#813) * Bump github.com/lib/pq from 1.8.0 to 1.9.0 (#820) * Bump golang from 1.15.5 to 1.15.6 (#822) * Bump github.com/jackc/pgx/v4 from 4.9.2 to 4.10.0 (#823) * Bump github.com/jackc/pgx/v4 from 4.10.0 to 4.10.1 (#839) * Bump golang from 1.15.6 to 1.15.7 (#855) * Bump golang from 1.15.7 to 1.15.8 (#881) * Bump github.com/spf13/cobra from 1.1.1 to 1.1.2 (#892) * Bump golang from 1.15.8 to 1.16.0 (#897) * Bump github.com/lfittl/pg\_query\_go from 1.0.1 to 1.0.2 (#901) * Bump github.com/spf13/cobra from 1.1.2 to 1.1.3 (#893) ### Catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#catalog "Link to this heading") * Improve alter column type (#818) ### Ci[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id182 "Link to this heading") * Uprade to Go 1.15 (#887) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id183 "Link to this heading") * Allow config file location to be specified (#863) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id184 "Link to this heading") * Bump to version v1.6.1-devel (#807) * Bump version to v1.7.0 (#912) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id185 "Link to this heading") * Make sure to import net package (#858) ### Compiler[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id186 "Link to this heading") * Support UNION query ### Dolphin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#dolphin "Link to this heading") * Generate bools for tinyint(1) * Support joins in update statements (#883) * Add support for union query ### Endtoend[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id187 "Link to this heading") * Add tests for INTERSECT and EXCEPT ### Go.mod[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#go-mod "Link to this heading") * Update to go 1.15 and run ‘go mod tidy’ (#808) ### Mysql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id188 "Link to this heading") * Compile tinyint(1) to bool (#873) ### Sql/ast[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id189 "Link to this heading") * Add enum values for SetOperation [1.6.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.6.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id190 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-11-23 ### Dolphin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id191 "Link to this heading") * Implement Rename (#651) * Skip processing view drops (#653) ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id192 "Link to this heading") * Update language / database support (#698) ### Astutils[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#astutils "Link to this heading") * Fix Params rewrite call (#674) ### Build[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id193 "Link to this heading") * Bump golang from 1.14 to 1.15.3 (#765) * Bump docker/build-push-action from v1 to v2.1.0 (#764) * Bump github.com/google/go-cmp from 0.4.0 to 0.5.2 (#766) * Bump github.com/spf13/cobra from 1.0.0 to 1.1.1 (#767) * Bump github.com/jackc/pgx/v4 from 4.6.0 to 4.9.2 (#768) * Bump github.com/lfittl/pg\_query\_go from 1.0.0 to 1.0.1 (#773) * Bump github.com/google/go-cmp from 0.5.2 to 0.5.3 (#783) * Bump golang from 1.15.3 to 1.15.5 (#782) * Bump github.com/lib/pq from 1.4.0 to 1.8.0 (#769) ### Catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id194 "Link to this heading") * Improve variadic argument support (#804) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id195 "Link to this heading") * Bump to version v1.6.0 (#806) ### Codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id196 "Link to this heading") * Fix errant database/sql imports (#789) ### Compiler[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id197 "Link to this heading") * Use engine-specific reserved keywords (#677) ### Dolphi[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#dolphi "Link to this heading") * Add list of builtin functions (#795) ### Dolphin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id198 "Link to this heading") * Update to the latest MySQL parser (#665) * Add ENUM() support (#676) * Add test for table aliasing (#684) * Add MySQL ddl\_create\_table test (#685) * Implete TRUNCATE table (#697) * Represent tinyint as int32 (#797) * Add support for coalesce (#802) * Add function signatures (#796) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id199 "Link to this heading") * Add MySQL json test (#692) * Add MySQL update set multiple test (#696) ### Examples[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id200 "Link to this heading") * Use generated enum constants in db\_test (#678) * Port ondeck to MySQL (#680) * Add MySQL authors example (#682) ### Internal/cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-cmd "Link to this heading") * Print correct config file on parse failure (#749) ### Kotlin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id201 "Link to this heading") * Remove runtime dependency (#774) ### Metadata[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#metadata "Link to this heading") * Support multiple comment prefixes (#683) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id202 "Link to this heading") * Support string concat operator (#701) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sql-catalog "Link to this heading") * Add support for variadic functions (#798) [1.5.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.5.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id203 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-08-05 ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id204 "Link to this heading") * Build sqlc using Go 1.14 (#549) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id205 "Link to this heading") * Add debugging support (#573) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id206 "Link to this heading") * Bump version to v1.4.1-devel (#548) * Bump version to v1.5.0 ### Compiler[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id207 "Link to this heading") * Support calling functions with defaults (#635) * Skip func args without a paramRef (#636) * Return a single column from coalesce (#639) ### Config[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id208 "Link to this heading") * Add emit\_empty\_slices to version one (#552) ### Contrib[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#contrib "Link to this heading") * Add generated code for contrib ### Dinosql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#dinosql "Link to this heading") * Remove deprecated package (#554) ### Dolphin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id209 "Link to this heading") * Add support for column aliasing (#566) * Implement star expansion for subqueries (#619) * Implement exapansion with reserved words (#620) * Implement parameter refs (#621) * Implement limit and offest (#622) * Implement inserts (#623) * Implement delete (#624) * Implement simple update statements (#625) * Implement INSERT … SELECT (#626) * Use test driver instead of TiDB driver (#629) * Implement named parameters via sqlc.arg() (#632) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id210 "Link to this heading") * Add MySQL test for SELECT \* JOIN (#565) * Add MySQL test for inflection (#567) ### Engine[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#engine "Link to this heading") * Create engine package (#556) ### Equinox[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#equinox "Link to this heading") * Use the new equinox-io/setup action (#586) ### Examples[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id211 "Link to this heading") * Run tests for MySQL booktest (#627) ### Golang[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id212 "Link to this heading") * Add support for the money type (#561) * Generate correct types for int2 and int8 (#579) ### Internal[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal "Link to this heading") * Rm catalog, pg, postgres packages (#555) ### Mod[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#mod "Link to this heading") * Downgrade TiDB package to fix build (#603) ### Mysql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id213 "Link to this heading") * Upgrade to the latest vitess commit (#562) * Support to infer type of a duplicated arg (#615) * Allow some builtin functions to be nullable (#616) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id214 "Link to this heading") * Generate all functions in pg\_catalog (#550) * Remove pg\_catalog schema from tests (#638) * Move contrib code to a package ### Sql/catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id215 "Link to this heading") * Fix comparison of pg\_catalog types (#637) ### Tools[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id216 "Link to this heading") * Generate functions for all of contrib ### Workflow[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#workflow "Link to this heading") * Migrate to equinox-io/setup-release-tool (#614) [1.4.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.4.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id217 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-06-17 ### Dockerfile[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#dockerfile "Link to this heading") * Add version build argument (#487) ### MySQL[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id218 "Link to this heading") * Prevent Panic when WHERE clause contains parenthesis. (#531) ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id219 "Link to this heading") * Document emit\_exact\_table\_names (#486) ### All[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#all "Link to this heading") * Remove the exp build tag (#507) ### Catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id220 "Link to this heading") * Support functions with table parameters (#541) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id221 "Link to this heading") * Bump to version 1.3.1-devel (#485) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id222 "Link to this heading") * Bump version to v1.4.0 (#547) ### Codegen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id223 "Link to this heading") * Add the new codegen packages (#513) * Add the :execresult query annotation (#542) ### Compiler[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id224 "Link to this heading") * Validate function calls (#505) * Port bottom of parseQuery (#510) * Don’t mutate table name (#517) * Enable experimental parser by default (#518) * Apply rename rules to enum constants (#523) * Temp fix for typecast function parameters (#530) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id225 "Link to this heading") * Standardize JSON formatting (#490) * Add per-test configuration files (#521) * Read expected stderr failures from disk (#527) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-dinosql "Link to this heading") * Check parameter style before ref (#488) * Remove unneeded column suffix (#492) * Support named function arguments (#494) ### Internal/postgresql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-postgresql "Link to this heading") * Fix NamedArgExpr rewrite (#491) ### Multierr[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#multierr "Link to this heading") * Move dinosql.ParserErr to a new package (#496) ### Named[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#named "Link to this heading") * Port parameter style validation to SQL (#504) ### Parser[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id226 "Link to this heading") * Support columns from subselect statements (#489) ### Rewrite[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#rewrite "Link to this heading") * Move parameter rewrite to package (#499) ### Sqlite[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id227 "Link to this heading") * Use convert functions instead of the listener (#519) ### Sqlpath[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sqlpath "Link to this heading") * Move ReadSQLFiles into a separate package (#495) ### Validation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#validation "Link to this heading") * Move query validation to separate package (#498) [1.3.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.3.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id228 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-05-12 ### Makefile[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#makefile "Link to this heading") * Update target (#449) ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id229 "Link to this heading") * Add Myles as a sponsor (#469) ### Testing[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id230 "Link to this heading") * Make sure all Go examples build (#480) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id231 "Link to this heading") * Bump version to v1.3.0 (#484) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id232 "Link to this heading") * Bump version to v1.2.1-devel (#442) ### Dinosql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id233 "Link to this heading") * Inline addFile (#446) * Add PostgreSQL support for TRUNCATE (#448) ### Gen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#gen "Link to this heading") * Emit json.RawMessage for JSON columns (#461) ### Go.mod[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id234 "Link to this heading") * Use latest lib/pq (#471) ### Parser[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id235 "Link to this heading") * Use same function to load SQL files (#483) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id236 "Link to this heading") * Fix panic walking CreateTableAsStmt (#475) [1.2.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.2.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id237 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-04-07 ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id238 "Link to this heading") * Publish to Docker Hub (#422) ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id239 "Link to this heading") * Docker installation docs (#424) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id240 "Link to this heading") * Bump version to v1.1.1-devel (#407) * Bump version to v1.2.0 (#441) ### Gen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id241 "Link to this heading") * Add special case for “campus” (#435) * Properly quote reserved keywords on expansion (#436) ### Migrations[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#migrations "Link to this heading") * Move migration parsing to new package (#427) ### Parser[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id242 "Link to this heading") * Generate correct types for SELECT EXISTS (#411) [1.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.1.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id243 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-03-17 ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id244 "Link to this heading") * Add installation instructions (#350) * Add section on running tests (#357) * Fix typo (#371) ### Ast[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#ast "Link to this heading") * Add AST for ALTER TABLE ADD / DROP COLUMN (#376) * Add support for CREATE TYPE as ENUM (#388) * Add support for CREATE / DROP SCHEMA (#389) ### Astutils[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id245 "Link to this heading") * Apply changes to the ValuesList slice (#372) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id246 "Link to this heading") * Return v1.0.0 (#348) * Return next bug fix version (#349) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id247 "Link to this heading") * Bump version to v1.1.0 (#406) ### Compiler[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id248 "Link to this heading") * Wire up the experimental parsers ### Config[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id249 "Link to this heading") * Remove “emit\_single\_file” option (#367) ### Dolphin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id250 "Link to this heading") * Add experimental parser for MySQL ### Gen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id251 "Link to this heading") * Add option to emit single file for Go (#366) * Add support for the ltree extension (#385) ### Go.mod[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id252 "Link to this heading") * Add packages for MySQL and SQLite parsers ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id253 "Link to this heading") * Support Postgres macaddr type in Go (#358) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-endtoend "Link to this heading") * Remove %w (#354) ### Kotlin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id254 "Link to this heading") * Add Query class to support timeout and cancellation (#368) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id255 "Link to this heading") * Add experimental parser for MySQL ### Sql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sql "Link to this heading") * Add generic SQL AST ### Sql/ast[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id256 "Link to this heading") * Port support for COMMENT ON (#391) * Implement DROP TYPE (#397) * Implement ALTER TABLE RENAME (#398) * Implement ALTER TABLE RENAME column (#399) * Implement ALTER TABLE SET SCHEMA (#400) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id257 "Link to this heading") * Port tests over from catalog pkg (#402) ### Sql/errors[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#sql-errors "Link to this heading") * Add a new errors package (#390) ### Sqlite[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id258 "Link to this heading") * Add experimental parser for SQLite [1.0.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.0.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id259 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-02-18 ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id260 "Link to this heading") * Add documentation for query commands (#270) * Add named parameter documentation (#332) ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id261 "Link to this heading") * Add sponsors section (#333) ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id262 "Link to this heading") * Remove parse subcommand (#322) ### Config[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id263 "Link to this heading") * Parse V2 config format * Add support for YAML (#336) ### Examples[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id264 "Link to this heading") * Add the jets and booktest examples (#237) * Move sqlc.json into examples folder (#238) * Add the authors example (#241) * Add build tag to authors tests (#319) ### Internal[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id265 "Link to this heading") * Allow CTE to be used with UPDATE (#268) * Remove the PackageMap from settings (#295) ### Internal/config[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id266 "Link to this heading") * Create new config package (#313) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id267 "Link to this heading") * Emit Querier interface (#240) * Strip leading “go-” or trailing “-go” from import (#262) * Overrides can now be basic types (#271) * Import needed types for Querier (#285) * Handle schema-scoped enums (#310) * Ignore golang-migrate rollbacks (#320) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id268 "Link to this heading") * Move more tests to the record/replay framework * Add update test for named params (#329) ### Internal/mysql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-mysql "Link to this heading") * Fix flaky test (#242) * Port tests to endtoend package (#315) ### Internal/parser[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-parser "Link to this heading") * Resolve nested CTEs (#324) * Error if last query is missing (#325) * Support joins with aliases (#326) * Remove print statement (#327) ### Internal/sqlc[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-sqlc "Link to this heading") * Add support for composite types (#311) ### Kotlin[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id269 "Link to this heading") * Support primitives * Arrays, enums, and dates * Generate examples * README for examples * Factor out db setup extension * Fix enums, use List instead of Array * Port Go tests for examples * Rewrite numbered params to positional params * Always use use, fix indents * Unbox query params ### Parser[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id270 "Link to this heading") * Attach range vars to insert params * Attach range vars to insert params (#342) * Remove dead code (#343) [0.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v0.1.0) [](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id271 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-01-07 ### Documentation[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id272 "Link to this heading") * Replace remaining references to DinoSQL with sqlc (#149) ### README[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id273 "Link to this heading") * Fix download links (#66) * Add LIMIT 1 to query that should return one (#99) ### Catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id274 "Link to this heading") * Support “ALTER TABLE … DROP CONSTRAINT …” (#34) * Differentiate functions with different argument types (#51) ### Ci[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id275 "Link to this heading") * Enable tests on pull requests ### Cmd[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id276 "Link to this heading") * Include filenames in error messages (#69) * Do not output any changes on error (#72) ### Dinosql/internal[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#dinosql-internal "Link to this heading") * Add lower and upper functions (#215) * Ignore alter sequence commands (#219) ### Gen[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id277 "Link to this heading") * Add DO NOT EDIT comments to generated code (#50) * Include all schemas when generating models (#90) * Prefix structs with schema name (#91) * Generate single import for uuid package (#98) * Use same import logic for all Go files * Pick correct struct to return for queries (#107) * Create consistent JSON tags (#110) * Add Close method to Queries struct (#127) * Ignore empty override settings (#128) * Turn SQL comments into Go comments (#136) ### Internal/catalog[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-catalog "Link to this heading") * Parse unnamed function arguments (#166) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id278 "Link to this heading") * Prepare() with no GoQueries still valid (#95) * Fix multiline comment rendering (#142) * Dereference alias nodes on walk (#158) * Ignore sql-migrate rollbacks (#160) * Sort imported packages (#165) * Add support for timestamptz (#169) * Error on missing queries (#180) * Use more database/sql null types (#182) * Support the pg\_temp schema (#183) * Override columns with array type (#184) * Implement robust expansion * Implement robust expansion (#186) * Add COMMENT ON support (#191) * Add DATE support * Add DATE support (#196) * Filter out invalid characters (#198) * Quote reserved keywords (#205) * Return parser errors first (#207) * Implement advisory locks (#212) * Error on duplicate query names (#221) * Fix incorrect enum names (#223) * Add support for numeric types * Add support for numeric types (#228) ### Internal/dinosql/testdata/ondeck[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#internal-dinosql-testdata-ondeck "Link to this heading") * Add Makefile (#156) ### Ondeck[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#ondeck "Link to this heading") * Move all tests to GitHub CI (#58) ### ParseQuery[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#parsequery "Link to this heading") * Return either a query or an error (#178) ### Parser[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#id279 "Link to this heading") * Use schema when resolving catalog refs (#82) * Support function calls in expressions (#104) * Correctly handle single files (#119) * Return error if missing RETURNING (#131) * Add support for mathmatical operators (#132) * Add support for simple case expressions (#134) * Error on mismatched INSERT input (#135) * Set IsArray on joined columns (#139) ### Pg[](https://docs.sqlc.dev/en/v1.31.0/reference/changelog.html#pg "Link to this heading") * Store functions in the catalog (#41) * Add location to errors (#73) --- # Changelog — sqlc 1.31.1 documentation * [](https://docs.sqlc.dev/en/v1.31.1/index.html) * Changelog * [View page source](https://docs.sqlc.dev/en/v1.31.1/_sources/reference/changelog.md.txt) * * * Changelog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#changelog "Link to this heading") ========================================================================================================= All notable changes to this project will be documented in this file. [1.31.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.31.1) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-31-1 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2026-04-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#bug-fixes "Link to this heading") * Remove go.mod replace directive that breaks `go install ...@latest` (#4401) * Downgrade github.com/ncruces/go-sqlite3 to v0.32.0 (#4400) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#build "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 (#4398) [1.31.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.31.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-31-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2026-04-19 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id3 "Link to this heading") * Strip psql meta-commands from schema files (#4390) * Emit pointers for nullable enum columns when `emit_pointers_for_null_types` is set (#4388) * Map xid8 to pgtype.Uint64 for pgx/v5 (#4387) * Rename `:one` return variable when it conflicts with a parameter (#4383) * Coerce SQLite JSONB output regardless of type casing (#4385) * Dedupe `sqlc.arg` parameters wrapped in a type cast for MySQL (#4384) * Preserve MySQL optimizer hints in generated query text (#4382) * Catch invalid `ON CONFLICT DO UPDATE` column references (#4366) * Replace manual loop with `copy()` builtin (#4166) * (native) Make MySQL connection check immediate on first attempt (#4254) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#documentation "Link to this heading") * Add link to community python plugin (#4157) * Add Claude Code remote environment setup instructions (#4246) * Add sqlc-gen-sqlx to community language support (#4371) * Add GitHub Topic to the plugins page (#4258) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#features "Link to this heading") * (sqlfile) Add `sqlfile.Split` (#4146) * (sqlite) Add database analyzer using ncruces/go-sqlite3 (#4199) * (ast) Implement comprehensive SQL AST formatting (#4205) * (mysql) Improve AST formatting and add DELETE JOIN support (#4206) * (sqlite) Add SQLite support to format tests (#4207) * (expander) Add star expander for `SELECT *` and `RETURNING *` (PostgreSQL, MySQL, SQLite) (#4203) * Add `SQLCEXPERIMENT` environment variable for experimental features (#4228) * Add native database support for e2e tests without Docker (#4236) * (postgresql) Add analyzerv2 experiment for database-only analysis (#4237) * Graduate parsecmd experiment (#4253) * Add parse subcommand with AST JSON output (#4240) * Add ClickHouse support to `sqlc parse` (#4267) * Add `sqlc-test-setup` command for database test environment setup (#4304) ### Refactor[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#refactor "Link to this heading") * (ast) Rename Formatter interface to Dialect (#4208) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id4 "Link to this heading") * Upgrade Go toolchain to 1.26.2 (#4378) * Upgrade Go version to 1.26.0 (#4312) * Remove github.com/jackc/pgx/v4 dependency (#4379) * Upgrade github.com/pingcap/tidb/pkg/parser (#4389) * Install PostgreSQL from theseus-rs/postgresql-binaries instead of apt (#4310) * Skip CI/RTD builds when the change is irrelevant (#4381) * (deps) 35 dependabot bumps (collapsed from individual entries) [1.30.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.30.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-30-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-09-01 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id6 "Link to this heading") * (compiler/mysql) Prevent panic in convertSetOprSelectList() (#4042) * Range subselect alias pointer dereference (#3711) * (codegen/golang) Don’t omit enums used as arrays (#4058) * (codegen/golang) Handle `go_struct_tag` for `db_type` overrides (#4055) * (engine/dolphin) Remove references to deprecated `pcast.ChangeStmt` (#4057) * Normalize identifier usage for table names (#4045) * (engine/sqlite) Fix parsing of INSERT DEFAULT VALUES syntax (#4010) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id7 "Link to this heading") * Fix parameter syntax inconsistency for MySQL and SQLite (#4036) * Use correct configuration to generate the given output for JSON type override (#4049) * Clean up and add to docs regarding type overrides (#4060) * Try a different admonition format (#4061) * Use the correct admonition format (#4062) * Add multi-worded table example for renaming (#4067) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id8 "Link to this heading") * (docs) Add link to Gleam/parrot (#4038) * (engine/dolphin) Implement MATCH\_AGAINST conversion in SQL AST (#1192, #3091) (#4070) * (engine/sqlite) Coerce jsonb columns to json before returning to Go code (#3968) ### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#testing "Link to this heading") * (endtoend) Skip process\_plugin\_sqlc\_gen\_json (#4075) * (endtoend) Use Docker to start database servers (#4076) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id9 "Link to this heading") * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3941) * (deps) Bump packaging (#3940) * (deps) Bump golang from 1.24.2 to 1.24.4 (#3983) * (deps) Bump golang from 1.24.4 to 1.24.5 (#4014) * (deps) Bump urllib3 from 2.4.0 to 2.5.0 in /docs (#3994) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3989) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4027) * (deps) Bump modernc.org/sqlite (#4032) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#4018) * (deps) Bump certifi in /docs in the production-dependencies group (#4041) * (deps) Bump google.golang.org/protobuf (#4043) * (deps) Bump actions/checkout from 4 to 5 (#4059) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#4071) * (deps) Bump requests in /docs in the production-dependencies group (#4068) * Upgrade to Go 1.25 (#4074) * (deps) Bump golang from 1.24.5 to 1.25.0 (#4063) * (deps) Bump github.com/google/cel-go (#4080) [1.29.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.29.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-29-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-04-14 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id11 "Link to this heading") * (docs) Correct spelling and grammar (#3645) * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) * (pgx) Do not wrap nil error (#3913) * (migrations) Normalize case for migration statement for all cases (#3919) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id12 "Link to this heading") * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Add changelog for 1.28.0 (#3797) * Add PHP DBAL plugin (#3813) * Fix PostGIS function name (#3829) * Add Zig plugin (#3824) * Add link to tandemdude/sqlc-gen-java (#3819) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id13 "Link to this heading") * (docs) How-to use transactions with pgx (#3557) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) * (mysql) Add a test for VECTOR column type (#3734) * (cli) Bump version from 1.27.0 to 1.28.0 (#3798) * (codegen/golang) Add an option to wrap query errors that includes query name (#3876) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#miscellaneous-tasks "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) * Update sqlc-gen-java supported engines (#3843) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id14 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) * (deps) Bump golang.org/x/net from 0.30.0 to 0.33.0 (#3796) * (deps) Bump golang from 1.23.5 to 1.23.6 (#3822) * Use govulncheck action (#3831) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3817) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3826) * (deps) Bump golang from 1.23.6 to 1.24.0 (#3842) * (deps) Bump myst-parser (#3841) * (deps) Bump modernc.org/sqlite (#3846) * (deps) Bump golang from 1.24.0 to 1.24.1 (#3870) * (deps) Bump jinja2 in /docs in the production-dependencies group (#3872) * Upgrade to wazero@v1.9.0 (#3887) * Upgrade to Go 1.24.1 (#3892) * Upgrade to latest version of MySQL parser (#3893) * (deps) Bump pyparsing (#3890) * (deps) Bump golang.org/x/net from 0.33.0 to 0.37.0 (#3894) * (deps) Bump the production-dependencies group across 1 directory with 8 updates (#3896) * (deps) Bump github.com/jackc/pgx/v5 (#3898) * (deps) Bump the production-dependencies group (#3899) * (deps) Bump modernc.org/sqlite (#3905) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3914) * (deps) Bump urllib3 in /docs in the production-dependencies group (#3926) * (deps) Bump golang from 1.24.1 to 1.24.2 (#3915) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3923) * (deps) Upgrade github.com/wasilibs/go-pgquery (#3927) [1.28.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.28.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-28-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2025-01-20 ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id16 "Link to this heading") * (mysql) Add a test for VECTOR column type (#3734) * (quickdb) Remove unused func (#3576) * (vet) Allow selective disabling of rules per query (#3620) * (dolphin) Upgrade to latest TiDB parser (#3733) ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id17 "Link to this heading") * (dbmanager) Use correct SQL to drop databases (#3640) * (compiler) Don’t crash on WHERE x IN (… UNION …) (#3652) * (golang) Escape q field name (#3647) * Postgresql alter materialized view is not registered to statements (#3728) * Do not close wazero module on error (#3758) (#3759) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id18 "Link to this heading") * How-to use transactions with pgx (#3557) * Add missing documentation about copyfrom (#3583) * Add sqlc-gen-from-template (#3601) * Correct spelling and grammar (#3645) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id19 "Link to this heading") * Remove the triage label (#3527) * Upgrade to Go 1.22.8 to silence vulncheck (#3646) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id20 "Link to this heading") * (deps) Bump myst-parser (#3530) * (deps) Bump golang from 1.22.5 to 1.22.6 (#3532) * (deps) Bump modernc.org/sqlite (#3537) * (deps) Bump the production-dependencies group across 1 directory with 4 updates (#3566) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3565) * (deps) Bump golang from 1.22.6 to 1.23.0 (#3546) * (deps) Bump golang from 1.23.0 to 1.23.1 (#3586) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3644) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3642) * (deps) Bump sphinx-rtd-theme (#3648) * (deps) Bump pyparsing (#3653) * (deps) Bump markupsafe (#3666) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3707) * (deps) Bump golang from 1.23.2 to 1.23.3 (#3691) * (deps) Bump the production-dependencies group across 1 directory with 5 updates (#3721) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3731) * (deps) Bump certifi in /docs in the production-dependencies group (#3748) * (deps) Bump golang.org/x/crypto from 0.27.0 to 0.31.0 (#3740) * (deps) Bump golang from 1.23.3 to 1.23.4 (#3735) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3749) * (deps) Bump the production-dependencies group with 2 updates (#3753) * (deps) Bump the production-dependencies group across 1 directory with 3 updates (#3764) * (deps) Bump the production-dependencies group (#3761) * (deps) Bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3762) * (deps) Bump google.golang.org/protobuf (#3776) * (deps) Bump the production-dependencies group across 1 directory with 2 updates (#3777) * (deps) Bump google.golang.org/grpc (#3784) * (deps) Bump golang from 1.23.4 to 1.23.5 (#3791) * (deps) Bump the production-dependencies group with 2 updates (#3789) * Upgrade to Go 1.23.5 (#3795) [1.27.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.27.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-27-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-08-05 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id22 "Link to this heading") * (dbmanager) Add leading slash to db uri path rewrite (#3493) * (verify) Include database engine in request (#3522) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id23 "Link to this heading") * (golang) Add initialisms configuration (#3308) * (compiler) Support subqueries in the FROM clause (second coming) (#3310) * Managed databases with any accessible server (#3421) * (vet) Use new dbmanager client (#3423) * (verify) Update verify to work with managed databases (#3425) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id24 "Link to this heading") * Fix typo in config (#3358) * Resolve a typo in configuration keys (#3349) * Add sponsorship information to README (#3413) * Update the language-support to include C# (#3408) * Add migration guide for hosted managed databases (#3417) * Fix readme links (#3424) * Update the managed db and verify documentation (#3426) * Add sponsor image (#3428) * Add Ruby as supported language (#3487) * Update migrating-to-sqlc-gen-kotlin.md (#3454) * Fix typo in comment (#3316) * Fix deprecated build tag format (#3361) ### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id25 "Link to this heading") * (endtoend) Re-use databases when possible (#3315) * Enabled MySQL database (#3318) * Remove internal/sqltest/hosted package (#3521) [1.26.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.26.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-26-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-03-28 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#release-notes "Link to this heading") This release is mainly a bug fix release. It also includes an [important security fix](https://github.com/sqlc-dev/sqlc/issues/3194) for users using output plugins. ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#changes "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id27 "Link to this heading") * (docker) Use distroless base image instead of scratch (#3111) * (generate) Ensure files are created inside output directory (#3195) * (mysql) BREAKING: Use `int16` for MySQL `SMALLINT` and `YEAR` (#3106) * (mysql) BREAKING: Use `int8` for MySQL TINYINT (#3298) * (mysql) Variables not resolving in ORDER BY statements (#3115) * (opts) Validate SQL package and driver options (#3241) * (postgres/batch) Ignore query\_parameter\_limit for batches * (scripts) Remove deprecated test output regeneration script (#3105) * (sqlite) Correctly skip unknown statements (#3239) #### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id28 "Link to this heading") * (postgres) Add instructions for PostGIS/GEOS (#3182) * Improve details on TEXT (#3247) #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id29 "Link to this heading") * (generate) Avoid generating empty Go imports (#3135) * (mysql) Add NEXTVAL() to the MySQL catalog (#3147) * (mysql) Support json.RawMessage for LOAD DATA INFILE (#3099) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id30 "Link to this heading") * (deps) Bump github.com/jackc/pgx/v5 to 5.5.5 (#3259) * (deps) Bump modernc.org/sqlite to 1.29.5 (#3200) * (deps) Bump github.com/go-sql-driver/mysql to 1.8.0 (#3257) * (deps) Bump github.com/tetratelabs/wazero to 1.7.0 (#3096) * (deps) Bump github.com/pganalyze/pg\_query\_go to v5 (#3096) [1.25.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.25.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-25-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2024-01-03 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id32 "Link to this heading") #### Add tags to push and verify[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#add-tags-to-push-and-verify "Link to this heading") You can add tags when [pushing](https://docs.sqlc.dev/en/v1.31.1/howto/push.html) schema and queries to [sqlc Cloud](https://dashboard.sqlc.dev/) . Tags operate like git tags, meaning you can overwrite previously-pushed tag values. We suggest tagging pushes to associate them with something relevant from your environment, e.g. a git tag or branch name. $ sqlc push --tag v1.0.0 Once you’ve created a tag, you can refer to it when [verifying](https://docs.sqlc.dev/en/v1.31.1/howto/verify.html) changes, allowing you to compare the existing schema against a known set of previous queries. $ sqlc verify --against v1.0.0 #### C-ya, `cgo`[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#c-ya-cgo "Link to this heading") Over the last month, we’ve switched out a few different modules to remove our reliance on [cgo](https://go.dev/blog/cgo) . Previously, we needed cgo for three separate functions: * Parsing PostgreSQL queries with [pganalyze/pg\_query\_go](https://github.com/pganalyze/pg_query_go) * Running SQLite databases with [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) * Executing WASM / WASI code with [bytecodealliance/wasmtime-go](https://github.com/bytecodealliance/wasmtime-go) With the help of the community, we found cgo-free alternatives for each module: * Parsing PostgreSQL queries, now using [wasilibs/go-pgquery](https://github.com/wasilibs/go-pgquery) * Running SQLite databases, now using [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) * Executing WASM / WASI code, now using [tetratelabs/wazero](https://github.com/tetratelabs/wazero) For the first time, Windows users can enjoy full PostgreSQL support without using [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) . It’s a Christmas miracle! If you run into any issues with the updated dependencies, please [open an issue](https://github.com/sqlc-dev/sqlc/issues) . ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id33 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id34 "Link to this heading") * (codegen) Wrong yaml annotation in go codegen options for output\_querier\_file\_name (#3006) * (codegen) Use derived ArrayDims instead of deprecated attndims (#3032) * (codegen) Take the maximum array dimensions (#3034) * (compiler) Skip analysis of queries without a `name` annotation (#3072) * (codegen/golang) Don’t import `"strings"` for `sqlc.slice()` with pgx (#3073) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id35 "Link to this heading") * Add name to query set configuration (#3011) * Add a sidebar link for `push`, add Go plugin link (#3023) * Update banner for sqlc-gen-typescript (#3036) * Add strict\_order\_by in doc (#3044) * Re-order the migration tools list (#3064) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id36 "Link to this heading") * (analyzer) Return zero values when encountering unexpected ast nodes (#3069) * (codegen/go) add omit\_sqlc\_version to Go code generation (#3019) * (codgen/go) Add `emit_sql_as_comment` option to Go code plugin (#2735) * (plugins) Use wazero instead of wasmtime (#3042) * (push) Add tag support (#3074) * (sqlite) Support emit\_pointers\_for\_null\_types (#3026) ### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id37 "Link to this heading") * (endtoend) Enable for more build targets (#3041) * (endtoend) Run MySQL and PostgreSQL locally on the runner (#3095) * (typescript) Test against sqlc-gen-typescript (#3046) * Add tests for omit\_sqlc\_version (#3020) * Split schema and query for test (#3094) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id38 "Link to this heading") * (deps) Bump idna from 3.4 to 3.6 in /docs (#3010) * (deps) Bump sphinx-rtd-theme from 1.3.0 to 2.0.0 in /docs (#3016) * (deps) Bump golang from 1.21.4 to 1.21.5 (#3043) * (deps) Bump actions/setup-go from 4 to 5 (#3047) * (deps) Bump github.com/jackc/pgx/v5 from 5.5.0 to 5.5.1 (#3050) * (deps) Upgrade to latest version of github.com/wasilibs/go-pgquery (#3052) * (deps) Bump google.golang.org/grpc from 1.59.0 to 1.60.0 (#3053) * (deps) Bump babel from 2.13.1 to 2.14.0 in /docs (#3055) * (deps) Bump actions/upload-artifact from 3 to 4 (#3061) * (deps) Bump modernc.org/sqlite from 1.27.0 to 1.28.0 (#3062) * (deps) Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#3068) * (deps) Bump google.golang.org/grpc from 1.60.0 to 1.60.1 (#3070) * (deps) Bump google.golang.org/protobuf from 1.31.0 to 1.32.0 (#3079) * (deps) Bump github.com/tetratelabs/wazero from 1.5.0 to 1.6.0 (#3096) * (sqlite) Update to antlr 4.13.1 (#3086) * (sqlite) Disable modernc for WASM (#3048) * (sqlite) Switch from mattn/go-sqlite3 to modernc.org/sqlite (#3040) [1.24.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.24.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-24-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-11-22 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id40 "Link to this heading") #### Verifying database schema changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#verifying-database-schema-changes "Link to this heading") Schema updates and poorly-written queries often bring down production databases. That’s bad. Out of the box, `sqlc generate` catches some of these issues. Running `sqlc vet` with the `sqlc/db-prepare` rule catches more subtle problems. But there is a large class of issues that sqlc can’t prevent by looking at current schema and queries alone. For instance, when a schema change is proposed, existing queries and code running in production might fail when the schema change is applied. Enter `sqlc verify`, which analyzes existing queries against new schema changes and errors if there are any issues. Let’s look at an example. Assume you have these two tables in production. CREATE TABLE users ( id UUID PRIMARY KEY ); CREATE TABLE user\_actions ( id UUID PRIMARY KEY, user\_id UUID NOT NULL, action TEXT, created\_at TIMESTAMP ); Your application contains the following query to join user actions against the users table. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY created\_at; So far, so good. Then assume you propose this schema change: ALTER TABLE users ADD COLUMN created\_at TIMESTAMP; Running `sqlc generate` fails with this change, returning a `column reference "created_at" is ambiguous` error. You update your query to fix the issue. \-- name: GetUserActions :many SELECT \* FROM users u JOIN user\_actions ua ON u.id \= ua.user\_id ORDER BY u.created\_at; While that change fixes the issue, there’s a production outage waiting to happen. When the schema change is applied, the existing `GetUserActions` query will begin to fail. The correct way to fix this is to deploy the updated query before applying the schema migration. It ensures migrations are safe to deploy by sending your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries. Here `sqlc verify` alerts you to the fact that ORDER BY “created\_at” is ambiguous. $ sqlc verify FAIL: app query.sql \=== Failed \=== FAIL: app query.sql GetUserActions ERROR: column reference "created\_at" is ambiguous (SQLSTATE 42702) By the way, this scenario isn’t made up! It happened to us a few weeks ago. We’ve been happily testing early versions of `verify` for the last two weeks and haven’t had any issues since. This type of verification is only the start. If your application is deployed on-prem by your customers, `verify` could tell you if it’s safe for your customers to rollback to an older version of your app, even after schema migrations have been run. #### Rename `upload` command to `push`[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#rename-upload-command-to-push "Link to this heading") We’ve renamed the `upload` sub-command to `push`. We changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest](https://buf.build/sqlc/sqlc/docs/main:plugin#plugin.GenerateRequest) , which is the protocol buffer message we pass to codegen plugins. We also add annotations to each push. By default, we include these environment variables if they are present: GITHUB\_REPOSITORY GITHUB\_REF GITHUB\_REF\_NAME GITHUB\_REF\_TYPE GITHUB\_SHA Like upload, `push` should be run when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits. #### MySQL support in `createdb`[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#mysql-support-in-createdb "Link to this heading") The `createdb` command, added in the last release, now supports MySQL. If you have a cloud project configured, you can use `sqlc createdb` to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html#with-other-tools) documentation. #### Plugin interface refactor[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#plugin-interface-refactor "Link to this heading") This release includes a refactored plugin interface to better support future functionality. Plugins now support different methods via a gRPC service interface, allowing plugins to support different functionality in a backwards-compatible way. By using gRPC interfaces, we can even (theoretically) support [remote plugins](https://github.com/sqlc-dev/sqlc/pull/2938) , but that’s something for another day. ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id41 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id42 "Link to this heading") * (engine/sqlite) Support CASE expr (#2926) * (engine/sqlite) Support -> and ->> operators (#2927) * (vet) Add a nil pointer check to prevent db/prepare panic (#2934) * (compiler) Prevent panic when compiler is nil (#2942) * (codegen/golang) Move more Go-specific config validation into the plugin (#2951) * (compiler) No panic on full-qualified column names (#2956) * (docs) Better discussion of type override nuances (#2972) * (codegen) Never generate return structs for :exec (#2976) * (generate) Update help text for generate to be more generic (#2981) * (generate) Return an error instead of generating duplicate Go names (#2962) * (codegen/golang) Pull opts into its own package (#2920) * (config) Make some struct and field names less confusing (#2922) #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id43 "Link to this heading") * (codegen) Remove Go specific overrides from codegen proto (#2929) * (plugin) Use gRPC interface for codegen plugin communication (#2930) * (plugin) Calculate SHA256 if it does not exist (#2935) * (sqlc-gen-go) Add script to mirror code to sqlc-gen-go (#2952) * (createdb) Add support for MySQL (#2980) * (verify) Add new command to verify queries and migrations (#2986) #### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id44 "Link to this heading") * (ci) New workflow for sqlc-gen-python (#2936) * (ci) Rely on go.mod to determine which Go version to use (#2971) * (tests) Add glob pattern tests to sqlpath.Glob (#2995) * (examples) Use hosted MySQL databases for tests (#2982) * (docs) Clean up a little, update LICENSE and README (#2941) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id45 "Link to this heading") * (deps) Bump babel from 2.13.0 to 2.13.1 in /docs (#2911) * (deps) Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2944) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.17 to 1.14.18 (#2945) * (deps) Bump golang.org/x/sync from 0.4.0 to 0.5.0 (#2946) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2947) * (deps) Change github.com/pingcap/tidb/parser to github.com/pingcap/tidb/pkg/parser * (deps) Bump github.com/google/cel-go from 0.18.1 to 0.18.2 (#2969) * (deps) Bump urllib3 from 2.0.7 to 2.1.0 in /docs (#2975) * (buf) Change root of Buf module (#2987) * (deps) Bump certifi from 2023.7.22 to 2023.11.17 in /docs (#2993) * (ci) Bump Go version from 1.21.3 to 1.21.4 in workflows and Dockerfile (#2961) [1.23.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.23.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-23-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-10-24 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id47 "Link to this heading") #### Database-backed query analysis[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#database-backed-query-analysis "Link to this heading") With a [database connection](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database) configured, `sqlc generate` will gather metadata from that database to support its query analysis. Turning this on resolves a [large number of issues](https://github.com/sqlc-dev/sqlc/issues?q=is%3Aissue+label%3Aanalyzer) in the backlog related to type inference and more complex queries. The easiest way to try it out is with [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html) . The database-backed analyzer currently supports PostgreSQL, with [MySQL](https://github.com/sqlc-dev/sqlc/issues/2902) and [SQLite](https://github.com/sqlc-dev/sqlc/issues/2903) support planned in the future. #### New `createdb` command[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#new-createdb-command "Link to this heading") When you have a cloud project configured, you can use the new `sqlc createdb` command to spin up a new ephemeral database with your schema and print its connection string to standard output. This is useful for integrating with other tools. Read more in the [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html#with-other-tools) documentation. #### Support for pgvector[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#support-for-pgvector "Link to this heading") If you’re using [pgvector](https://github.com/pgvector/pgvector) , say goodbye to custom overrides! sqlc now generates code using [pgvector-go](https://github.com/pgvector/pgvector-go#pgx) as long as you’re using `pgx`. The pgvector extension is also available in [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html) . #### Go build tags[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#go-build-tags "Link to this heading") With the new `emit_build_tags` configuration parameter you can set build tags for sqlc to add at the top of generated source files. ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id48 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id49 "Link to this heading") * (codegen) Correct column names in :copyfrom (#2838) * (compiler) Search SELECT and UPDATE the same way (#2841) * (dolphin) Support more UNIONs for MySQL (#2843) * (compiler) Account for parameters without parents (#2844) * (postgresql) Remove temporary pool config (#2851) * (golang) Escape reserved keywords (#2849) * (mysql) Handle simplified CASE statements (#2852) * (engine/dolphin) Support enum in ALTER definition (#2680) * (mysql) Add, drop, rename and change enum values (#2853) * (config) Validate `database` config in all cases (#2856) * (compiler) Use correct func signature for `CommentSyntax` on windows (#2867) * (codegen/go) Prevent filtering of embedded struct fields (#2868) * (compiler) Support functions with OUT params (#2865) * (compiler) Pull in array information from analyzer (#2864) * (analyzer) Error on unexpanded star expression (#2882) * (vet) Remove rollback statements from DDL (#2895) #### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id50 "Link to this heading") * Add stable anchors to changelog (#2784) * Fix typo in v1.22.0 changelog (#2796) * Add sqlc upload to CI / CD guide (#2797) * Fix broken link, add clarity to plugins doc (#2813) * Add clarity and reference to JSON tags (#2819) * Replace form with dashboard link (#2840) * (examples) Update examples to use pgx/v5 (#2863) * Use docker compose v2 and update MYSQL\_DATABASE env var (#2870) * Update getting started guides, use pgx for Postgres guide (#2891) * Use managed databases in PostgreSQL getting started guide (#2892) * Update managed databases doc to discuss codegen (#2897) * Add managed dbs to CI/CD and vet guides (#2896) * Document database-backed query analyzer (#2904) #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id51 "Link to this heading") * (codegen) Support setting Go build tags (#2012) (#2807) * (generate) Reorder codegen handlers to prefer plugins (#2814) * (devenv) Add vscode settings.json with auto newline (#2834) * (cmd) Support sqlc.yml configuration file (#2828) * (analyzer) Analyze queries using a running PostgreSQL database (#2805) * (sql/ast) Render AST to SQL (#2815) * (codegen) Include plugin information (#2846) * (postgresql) Add ALTER VIEW … SET SCHEMA (#2855) * (compiler) Parse query parameter metadata from comments (#2850) * (postgresql) Support system columns on tables (#2871) * (compiler) Support LEFT JOIN on aliased table (#2873) * Improve messaging for common cloud config and rpc errors (#2885) * Abort compiler when rpc fails as unauthenticated (#2887) * (codegen) Add support for pgvector and pgvector-go (#2888) * (analyzer) Cache query analysis (#2889) * (createdb) Create ephemeral databases (#2894) * (debug) Add databases=managed debug option (#2898) * (config) Remove managed database validation (#2901) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id52 "Link to this heading") * (endtoend) Fix test output for do tests (#2782) #### Refactor[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id53 "Link to this heading") * (codegen) Remove golang and json settings from plugin proto (#2822) * (codegen) Removed deprecated code and improved speed (#2899) #### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id54 "Link to this heading") * (endtoend) Split shema and queries (#2803) * Fix a few incorrect testcases (#2804) * (analyzer) Add more database analyzer test cases (#2854) * Add more analyzer test cases (#2866) * Add more test cases for new analyzer (#2879) * (endtoend) Enabled managed-db tests in CI (#2883) * Enabled pgvector tests for managed dbs (#2893) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id55 "Link to this heading") * (deps) Bump packaging from 23.1 to 23.2 in /docs (#2791) * (deps) Bump urllib3 from 2.0.5 to 2.0.6 in /docs (#2798) * (deps) Bump babel from 2.12.1 to 2.13.0 in /docs (#2799) * (deps) Bump golang.org/x/sync from 0.3.0 to 0.4.0 (#2810) * (deps) Bump golang from 1.21.1 to 1.21.2 (#2811) * (deps) Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (#2826) * (deps) Bump golang from 1.21.2 to 1.21.3 (#2824) * (deps) Bump google.golang.org/grpc from 1.58.2 to 1.58.3 (#2825) * (deps) Bump golang.org/x/net from 0.12.0 to 0.17.0 (#2836) * (deps) Bump urllib3 from 2.0.6 to 2.0.7 in /docs (#2872) * (deps) Bump google.golang.org/grpc from 1.58.3 to 1.59.0 (#2876) * (deps) Upgrade wasmtime-go from 13.0.0 to 14.0.0 (#2900) #### Ci[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#ci "Link to this heading") * Bump go version in workflows (#2835) [1.22.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.22.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-22-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-26 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id57 "Link to this heading") #### Managed databases for `sqlc vet`[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#managed-databases-for-sqlc-vet "Link to this heading") If you’re using [sqlc vet](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html) to write rules that require access to a running database, `sqlc` can now start and manage that database for you. PostgreSQL support is available today, with MySQL on the way. When you turn on managed databases, `sqlc` will use your schema to create a template database that it can copy to make future runs of `sqlc vet` very performant. This feature relies on configuration obtained via [sqlc Cloud](https://dashboard.sqlc.dev/) . Read more in the [managed databases](https://docs.sqlc.dev/en/v1.31.1/howto/managed-databases.html) documentation. ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id58 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id59 "Link to this heading") * (codegen/golang) Refactor imports code to match templates (#2709) * (codegen/golang) Support name type (#2715) * (wasm) Move Runner struct to shared file (#2725) * (engine/sqlite) Fix grammer to avoid missing join\_constraint (#2732) * (convert) Support YAML anchors in plugin options (#2733) * (mysql) Disallow time.Time in mysql :copyfrom queries, not all queries (#2768) * (engine/sqlite) Fix convert process for VALUES (#2737) #### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id60 "Link to this heading") * Clarify nullable override behavior (#2753) * Add managed databases to sidebar (#2764) * Pull renaming and type overrides into separate sections (#2774) * Update the docs banner for managed dbs (#2775) #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id61 "Link to this heading") * (config) Enables the configuration of copyfrom.go similar to quierer and friends (#2727) * (vet) Run rules against a managed database (#2751) * (upload) Point upload command at new endpoint (#2772) * (compiler) Support DO statements (#2777) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id62 "Link to this heading") * (endtoend) Skip tests missing secrets (#2763) * Skip certain tests on PRs (#2769) #### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id63 "Link to this heading") * (endtoend) Verify all schemas in endtoend (#2744) * (examples) Use a hosted database for example testing (#2749) * (endtoend) Pull region from environment (#2750) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id64 "Link to this heading") * (deps) Bump golang from 1.21.0 to 1.21.1 (#2711) * (deps) Bump google.golang.org/grpc from 1.57.0 to 1.58.1 (#2743) * (deps) Bump wasmtime-go from v12 to v13 (#2756) * (windows) Downgrade to mingw 11.2.0 (#2757) * (deps) Bump urllib3 from 2.0.4 to 2.0.5 in /docs (#2747) * (deps) Bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#2758) * (deps) Bump github.com/google/cel-go from 0.18.0 to 0.18.1 (#2778) #### Ci[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id65 "Link to this heading") * Bump go version to latest in ci workflows (#2722) [1.21.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.21.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-21-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-09-06 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id67 "Link to this heading") This is primarily a bugfix release, along with some documentation and testing improvements. #### MySQL engine improvements[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#mysql-engine-improvements "Link to this heading") `sqlc` previously didn’t know how to parse a `CALL` statement when using the MySQL engine, which meant it was impossible to use sqlc with stored procedures in MySQL databases. Additionally, `sqlc` now supports `IS [NOT] NULL` in queries. And `LIMIT` and `OFFSET` clauses now work with `UNION`. #### SQLite engine improvements[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sqlite-engine-improvements "Link to this heading") GitHub user [@orisano](https://github.com/orisano) continues to bring bugfixes and improvements to `sqlc`’s SQLite engine. See the “Changes” section below for the full list. #### Plugin access to environment variables[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#plugin-access-to-environment-variables "Link to this heading") If you’re authoring a [sqlc plugin](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#../guides/plugins.html) , you can now configure sqlc to pass your plugin the values of specific environment variables. For example, if your plugin needs the `PATH` environment variable, add `PATH` to the `env` list in the `plugins` collection. version: '2' sql: \- schema: schema.sql queries: query.sql engine: postgresql codegen: \- out: gen plugin: test plugins: \- name: test env: \- PATH wasm: url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790 A variable named `SQLC_VERSION` is always included in the plugin’s environment, set to the version of the `sqlc` executable invoking it. ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id68 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id69 "Link to this heading") * Myriad string formatting changes (#2558) * (engine/sqlite) Support quoted identifier (#2556) * (engine/sqlite) Fix compile error (#2564) * (engine/sqlite) Fixed detection of column alias without AS (#2560) * (ci) Bump go version to 1.20.7 (#2568) * Remove references to deprecated `--experimental` flag (#2567) * (postgres) Fixed a problem with array dimensions disappearing when using “ALTER TABLE ADD COLUMN” (#2572) * Remove GitHub sponsor integration (#2574) * (docs) Improve discussion of prepared statements support (#2604) * (docs) Remove multidimensional array qualification in datatypes.md (#2619) * (config) Go struct tag parsing (#2606) * (compiler) Fix to not scan children under ast.RangeSubselect when retrieving table listing (#2573) * (engine/sqlite) Support NOT IN (#2587) * (codegen/golang) Fixed detection of the used package (#2597) * (engine/dolphin) Fixed problem that LIMIT OFFSET cannot be used with `UNION ALL` (#2613) * (compiler) Support identifiers with schema (#2579) * (compiler) Fix column expansion to work with quoted non-keyword identifiers (#2576) * (codegen/go) Compare define type in codegen (#2263) (#2578) * (engine/sqlite) Fix ast when using compound operator (#2673) * (engine/sqlite) Fix to handle join clauses correctly (#2674) * (codegen) Use correct Go types for bit strings and cid/oid/tid/xid with pgx/v4 (#2668) * (endtoend) Ensure all SQL works against PostgreSQL (#2684) #### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id70 "Link to this heading") * Update Docker installation instructions (#2552) * Missing emit\_pointers\_for\_null\_types configuration option in version 2 (#2682) (#2683) * Fix typo (#2697) * Document sqlc.\* macros (#2698) * (mysql) Document parseTimet=true requirement (#2699) * Add atlas to the list of supported migration frameworks (#2700) * Minor updates to insert howto (#2701) #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id71 "Link to this heading") * (endtoend/testdata) Added two sqlite `CAST` tests and rearranged postgres tests for same (#2551) * (docs) Add a reference to type overriding in datatypes.md (#2557) * (engine/sqlite) Support COLLATE for sqlite WHERE clause (#2554) * (mysql) Add parser support for IS \[NOT\] NULL (#2651) * (engine/dolphin) Support CALL statement (#2614) * (codegen) Allow plugins to access environment variables (#2669) * (config) Add JSON schema files for configs (#2703) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id72 "Link to this heading") * Ignore Vim swap files (#2616) * Fix typo (#2696) #### Refactor[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id73 "Link to this heading") * (astutils) Remove redundant nil check in `Walk` (#2660) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id74 "Link to this heading") * (deps) Bump wasmtime from v8.0.0 to v11.0.0 (#2553) * (deps) Bump golang from 1.20.6 to 1.20.7 (#2563) * (deps) Bump chardet from 5.1.0 to 5.2.0 in /docs (#2562) * (deps) Bump github.com/pganalyze/pg\_query\_go/v4 (#2583) * (deps) Bump golang from 1.20.7 to 1.21.0 (#2596) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.2 to 5.4.3 (#2582) * (deps) Bump pygments from 2.15.1 to 2.16.1 in /docs (#2584) * (deps) Bump sphinxcontrib-applehelp from 1.0.4 to 1.0.7 in /docs (#2620) * (deps) Bump sphinxcontrib-qthelp from 1.0.3 to 1.0.6 in /docs (#2622) * (deps) Bump github.com/google/cel-go from 0.17.1 to 0.17.6 (#2650) * (deps) Bump sphinxcontrib-serializinghtml in /docs (#2641) * Upgrade from Go 1.20 to Go 1.21 (#2665) * (deps) Bump sphinxcontrib-devhelp from 1.0.2 to 1.0.5 in /docs (#2621) * (deps) Bump github.com/bytecodealliance/wasmtime-go from v11.0.0 to v12.0.0 (#2666) * (deps) Bump sphinx-rtd-theme from 1.2.2 to 1.3.0 in /docs (#2670) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.1 to 2.0.4 in /docs (#2671) * (deps) Bump github.com/google/cel-go from 0.17.6 to 0.18.0 (#2691) * (deps) Bump actions/checkout from 3 to 4 (#2694) * (deps) Bump pytz from 2023.3 to 2023.3.post1 in /docs (#2695) * (devenv) Bump go from 1.20.7 to 1.21.0 (#2702) [1.20.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.20.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#v1-20-0 "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-31 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id76 "Link to this heading") #### `kyleconroy/sqlc` is now `sqlc-dev/sqlc`[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#kyleconroy-sqlc-is-now-sqlc-dev-sqlc "Link to this heading") We’ve completed our migration to the [sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc) repository. All existing links and installation instructions will continue to work. If you’re using the `go` tool to install `sqlc`, you’ll need to use the new import path to get v1.20.0 (and all future versions). \# INCORRECT: old import path go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.20.0 \# CORRECT: new import path go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.20.0 We designed the upgrade process to be as smooth as possible. If you run into any issues, please [file a bug report](https://github.com/sqlc-dev/sqlc/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=BUG_REPORT.yml) via GitHub. #### Use `EXPLAIN ...` output in lint rules[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#use-explain-output-in-lint-rules "Link to this heading") `sqlc vet` can now run `EXPLAIN` on your queries and include the results for use in your lint rules. For example, this rule checks that `SELECT` queries use an index. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" database: uri: "postgresql://postgres:postgres@localhost:5432/postgres" gen: go: package: "db" out: "db" rules: \- has-index rules: \- name: has-index rule: \> query.sql.startsWith("SELECT") && !(postgresql.explain.plan.plans.all(p, has(p.index\_name) || p.plans.all(p, has(p.index\_name)))) The expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](https://docs.sqlc.dev/en/v1.31.1/reference/config.html#database) . For the `postgresql` engine, `sqlc` runs EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ... where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message. For the `mysql` engine, `sqlc` runs EXPLAIN FORMAT\=JSON ... where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message. These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree. The output from `EXPLAIN ...` depends on the structure of your query so it’s a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information. ... rules: \- name: postgresql-query-too-costly message: "Query cost estimate is too high" rule: "postgresql.explain.plan.total\_cost \> 1.0" \- name: postgresql-no-seq-scan message: "Query plan results in a sequential scan" rule: "postgresql.explain.plan.node\_type \== 'Seq Scan'" \- name: mysql-query-too-costly message: "Query cost estimate is too high" rule: "has(mysql.explain.query\_block.cost\_info) && double(mysql.explain.query\_block.cost\_info.query\_cost) \> 2.0" \- name: mysql-must-use-primary-key message: "Query plan doesn't use primary key" rule: "has(mysql.explain.query\_block.table.key) && mysql.explain.query\_block.table.key != 'PRIMARY'" When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries. #### Opting-out of lint rules[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#opting-out-of-lint-rules "Link to this heading") For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation. /\* name: GetAuthor :one \*/ /\* @sqlc-vet-disable \*/ SELECT \* FROM authors WHERE id \= ? LIMIT 1; #### Bulk insert for MySQL[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#bulk-insert-for-mysql "Link to this heading") _Developed by [@Jille](https://github.com/Jille) _ MySQL now supports the `:copyfrom` query annotation. The generated code uses the [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) command to insert data quickly and efficiently. Use caution with this feature. Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use `SHOW WARNINGS` to check for any problems and roll back if necessary. Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information. CREATE TABLE foo (a text, b integer, c DATETIME, d DATE); \-- name: InsertValues :copyfrom INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?); func (q \*Queries) InsertValues(ctx context.Context, arg \[\]InsertValuesParams) (int64, error) { ... } `LOAD DATA` support must be enabled in the MySQL server. #### CAST support for MySQL[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#cast-support-for-mysql "Link to this heading") _Developed by [@ryanpbrewster](https://github.com/ryanpbrewster) and [@RadhiFadlillah](https://github.com/RadhiFadlillah) _ `sqlc` now understands `CAST` calls in MySQL queries, offering greater flexibility when generating code for complex queries. CREATE TABLE foo (bar BOOLEAN NOT NULL); \-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo; package querytest import ( "context" ) const selectColumnCast \= \`-- name: SelectColumnCast :many SELECT CAST(bar AS BIGINT) FROM foo \` func (q \*Queries) SelectColumnCast(ctx context.Context) (\[\]int64, error) { ... } #### SQLite improvements[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sqlite-improvements "Link to this heading") A slew of fixes landed for our SQLite implementation, bringing it closer to parity with MySQL and PostgreSQL. We want to thank [@orisano](https://github.com/orisano) for their continued dedication to improving `sqlc`’s SQLite support. ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id77 "Link to this heading") #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id78 "Link to this heading") * (debug) Add debug flag and docs for dumping vet rule variables (#2521) * (mysql) :copyfrom support via LOAD DATA INFILE (#2545) * (mysql) Implement cast function parser (#2473) * (postgresql) Add support for PostgreSQL multi-dimensional arrays (#2338) * (sql/catalog) Support ALTER TABLE IF EXISTS (#2542) * (sqlite) Virtual tables and fts5 supported (#2531) * (vet) Add default query parameters for explain queries (#2543) * (vet) Add output from `EXPLAIN ...` for queries to the CEL program environment (#2489) * (vet) Introduce a query annotation to opt out of sqlc vet rules (#2474) * Parse comment lines starting with `@symbol` as boolean flags associated with a query (#2464) #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id79 "Link to this heading") * (codegen/golang) Fix sqlc.embed to work with pq.Array (#2544) * (compiler) Correctly validate alias in order/group by clauses for joins (#2537) * (engine/sqlite) Added function to convert cast node (#2470) * (engine/sqlite) Fix join\_operator rule (#2434) * (engine/sqlite) Fix table\_alias rules (#2465) * (engine/sqlite) Fixed IN operator precedence (#2428) * (engine/sqlite) Fixed to be able to find relation from WITH clause (#2444) * (engine/sqlite) Lowercase ast.ResTarget.Name (#2433) * (engine/sqlite) Put logging statement behind debug flag (#2488) * (engine/sqlite) Support for repeated table\_option (#2482) * (mysql) Generate unsigned param (#2522) * (sql/catalog) Support pg\_dump output (#2508) * (sqlite) Code generation for sqlc.slice (#2431) * (vet) Clean up unnecessary `prepareable()` func and a var name (#2509) * (vet) Query.cmd was always set to “:” (#2525) * (vet) Report an error when a query is unpreparable, close prepared statement connection (#2486) * (vet) Split vet messages out of codegen.proto (#2511) #### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id80 "Link to this heading") * Add a description to the document for cases when a query result has no rows (#2462) * Update copyright and author (#2490) * Add example sqlc.yaml for migration parsing (#2479) * Small updates (#2506) * Point GitHub links to new repository location (#2534) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id81 "Link to this heading") * Rename kyleconroy/sqlc to sqlc-dev/sqlc (#2523) * (proto) Reformat protos using `buf format -w` (#2536) * Update FEATURE\_REQUEST.yml to include SQLite engine option * Finish migration to sqlc-dev/sqlc (#2548) * (compiler) Remove some duplicate code (#2546) #### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id82 "Link to this heading") * Add profiles to docker compose (#2503) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id83 "Link to this heading") * Run all supported versions of MySQL / PostgreSQL (#2463) * (deps) Bump pygments from 2.7.4 to 2.15.0 in /docs (#2485) * (deps) Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2483) * (deps) Bump github.com/google/cel-go from 0.16.0 to 0.17.1 (#2484) * (docs) Check Python dependencies via dependabot (#2497) * (deps) Bump idna from 2.10 to 3.4 in /docs (#2499) * (deps) Bump packaging from 20.9 to 23.1 in /docs (#2498) * (deps) Bump pygments from 2.15.0 to 2.15.1 in /docs (#2500) * (deps) Bump certifi from 2022.12.7 to 2023.7.22 in /docs (#2504) * (deps) Bump sphinx from 4.4.0 to 6.1.0 in /docs (#2505) * Add psql and mysqlsh to devenv (#2507) * (deps) Bump urllib3 from 1.26.5 to 2.0.4 in /docs (#2516) * (deps) Bump chardet from 4.0.0 to 5.1.0 in /docs (#2517) * (deps) Bump snowballstemmer from 2.1.0 to 2.2.0 in /docs (#2519) * (deps) Bump pytz from 2021.1 to 2023.3 in /docs (#2520) * (deps) Bump sphinxcontrib-htmlhelp from 2.0.0 to 2.0.1 in /docs (#2518) * (deps) Bump pyparsing from 2.4.7 to 3.1.0 in /docs (#2530) * (deps) Bump alabaster from 0.7.12 to 0.7.13 in /docs (#2526) * (docs) Ignore updates for sphinx (#2532) * (deps) Bump babel from 2.9.1 to 2.12.1 in /docs (#2527) * (deps) Bump sphinxcontrib-applehelp from 1.0.2 to 1.0.4 in /docs (#2533) * (deps) Bump google.golang.org/grpc from 1.56.2 to 1.57.0 (#2535) * (deps) Bump pyparsing from 3.1.0 to 3.1.1 in /docs (#2547) [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id84 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id85 "Link to this heading") * Fix to traverse Sel in ast.In (#2414) * (compiler) Validate UNION … ORDER BY (#2446) * (golang) Prevent duplicate enum output (#2447) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id86 "Link to this heading") * Replace codegen, test and docs references to github.com/tabbed repos (#2418) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id87 "Link to this heading") * (deps) Bump google.golang.org/grpc from 1.56.1 to 1.56.2 (#2415) * (deps) Bump golang from 1.20.5 to 1.20.6 (#2437) * Pin Go to 1.20.6 (#2441) * (deps) Bump github.com/jackc/pgx/v5 from 5.4.1 to 5.4.2 (#2436) [1.19.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id88 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-07-06 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id89 "Link to this heading") #### sqlc vet[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sqlc-vet "Link to this heading") [`sqlc vet`](https://docs.sqlc.dev/en/v1.31.1/howto/vet.html) runs queries through a set of lint rules. Rules are defined in the `sqlc` [configuration](https://docs.sqlc.dev/en/v1.31.1/reference/config.html) file. They consist of a name, message, and a [Common Expression Language (CEL)](https://github.com/google/cel-spec) expression. Expressions are evaluated using [cel-go](https://github.com/google/cel-go) . If an expression evaluates to `true`, an error is reported using the given message. While these examples are simplistic, they give you a flavor of the types of rules you can write. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" rules: \- no-pg \- no-delete \- only-one-param \- no-exec rules: \- name: no-pg message: "invalid engine: postgresql" rule: | config.engine == "postgresql" \- name: no-delete message: "don't use delete statements" rule: | query.sql.contains("DELETE") \- name: only-one-param message: "too many parameters" rule: | query.params.size() > 1 \- name: no-exec message: "don't use exec" rule: | query.cmd == "exec" ##### Database connectivity[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#database-connectivity "Link to this heading") `vet` also marks the first time that `sqlc` can connect to a live, running database server. We’ll expand this functionality over time, but for now it powers the `sqlc/db-prepare` built-in rule. When a [database](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#config.html#database) is configured, the `sqlc/db-preapre` rule will attempt to prepare each of your queries against the connected database and report any failures. version: 2 sql: \- schema: "query.sql" queries: "query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" database: uri: "postgresql://postgres:password@localhost:5432/postgres" rules: \- sqlc/db-prepare To see this in action, check out the [authors example](https://github.com/sqlc-dev/sqlc/blob/main/examples/authors/sqlc.yaml) . Please note that `sqlc` does not manage or migrate your database. Use your migration tool of choice to create the necessary database tables and objects before running `sqlc vet`. #### Omit unused structs[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#omit-unused-structs "Link to this heading") Added a new configuration parameter `omit_unused_structs` which, when set to true, filters out table and enum structs that aren’t used in queries for a given package. #### Suggested CI/CD setup[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#suggested-ci-cd-setup "Link to this heading") With the addition of `sqlc diff` and `sqlc vet`, we encourage users to run sqlc in your CI/CD pipelines. See our [suggested CI/CD setup](https://docs.sqlc.dev/en/v1.31.1/howto/ci-cd.html) for more information. #### Simplified plugin development[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#simplified-plugin-development "Link to this heading") The [sqlc-gen-kotlin](https://github.com/sqlc-dev/sqlc-gen-kotlin) and [sqlc-gen-python](https://github.com/sqlc-dev/sqlc-gen-python) plugins have been updated use the upcoming [WASI](https://wasi.dev/) support in [Go 1.21](https://tip.golang.org/doc/go1.21#wasip1) . Building these plugins no longer requires [TinyGo](https://tinygo.org/) . ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id90 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id91 "Link to this heading") * Pointers overrides skip imports in generated query files (#2240) * CASE-ELSE clause is not properly parsed when a value is constant (#2238) * Fix toSnakeCase to handle input in CamelCase format (#2245) * Add location info to sqlite ast (#2298) * Add override tags to result struct (#1867) (#1887) * Override types of aliased columns and named parameters (#1884) * Resolve duplicate fields generated when inheriting multiple tables (#2089) * Check column references in ORDER BY (#1411) (#1915) * MySQL slice shadowing database/sql import (#2332) * Don’t defer rows.Close() if pgx.BatchResults.Query() failed (#2362) * Fix type overrides not working with sqlc.slice (#2351) * Type overrides on columns for parameters inside an IN clause (#2352) * Broken interaction between query\_parameter\_limit and pq.Array() (#2383) * (codegen/golang) Bring :execlastid in line with the rest (#2378) #### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id92 "Link to this heading") * Update changelog.md with some minor edits (#2235) * Add F# community plugin (#2295) * Add a ReadTheDocs config file (#2327) * Update query\_parameter\_limit documentation (#2374) * Add launch announcement banner #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id93 "Link to this heading") * PostgreSQL capture correct line and column numbers for parse error (#2289) * Add supporting COMMENT ON VIEW (#2249) * To allow spaces between function name and arguments of functions to be rewritten (#2250) * Add support for pgx/v5 emit\_pointers\_for\_null\_types flag (#2269) * (mysql) Support unsigned integers (#1746) * Allow use of table and column aliases for table functions returning unknown types (#2156) * Support “LIMIT ?” in UPDATE and DELETE for MySQL (#2365) * (internal/codegen/golang) Omit unused structs from output (#2369) * Improve default names for BETWEEN ? AND ? to have prefixes from\_ and to\_ (#2366) * (cmd/sqlc) Add the vet subcommand (#2344) * (sqlite) Add support for UPDATE/DELETE with a LIMIT clause (#2384) * Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) (#2373) * (cmd/vet) Prepare queries against a database (#2387) * (cmd/vet) Prepare queries for MySQL (#2388) * (cmd/vet) Prepare SQLite queries (#2389) * (cmd/vet) Simplify environment variable substiution (#2393) * (cmd/vet) Add built-in db-prepare rule * Add compiler support for NOTIFY and LISTEN (PostgreSQL) (#2363) #### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id94 "Link to this heading") * A few small staticcheck fixes (#2361) * Remove a bunch of dead code (#2360) * (scripts/regenerate) Should also update stderr.txt (#2379) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id95 "Link to this heading") * (deps) Bump requests from 2.25.1 to 2.31.0 in /docs (#2283) * (deps) Bump golang from 1.20.3 to 1.20.4 (#2256) * (deps) Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#2265) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 (#2293) * (deps) Bump golang.org/x/sync from 0.1.0 to 0.2.0 (#2266) * (deps) Bump golang from 1.20.4 to 1.20.5 (#2301) * Configure dependencies via devenv.sh (#2319) * Configure dependencies via devenv.sh (#2326) * (deps) Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#2328) * (deps) Bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#2333) * (deps) Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 (#2370) * (deps) Bump actions/checkout from 2 to 3 (#2357) * Run govulncheck on all builds (#2372) * (deps) Bump google.golang.org/grpc from 1.56.0 to 1.56.1 (#2358) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#cmd-sqlc "Link to this heading") * Show helpful output on missing subcommand (#2345) #### Codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#codegen "Link to this heading") * Use catalog’s default schema (#2310) * (go) Add tests for tables with dashes (#2312) * (go) Strip invalid characters from table and column names (#2314) * (go) Support JSON tags for nullable enum structs (#2121) #### Internal/config[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-config "Link to this heading") * Support golang overrides for slices (#2339) #### Kotlin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#kotlin "Link to this heading") * Use latest version of sqlc-gen-kotlin (#2356) #### Postgres[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#postgres "Link to this heading") * Column merging for table inheritence (#2315) #### Protos[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#protos "Link to this heading") * Add missing field name (#2354) #### Python[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#python "Link to this heading") * Use latest version of sqlc-gen-python (#2355) #### Remote[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#remote "Link to this heading") * Use user-id/password auth (#2262) #### Sqlite[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sqlite "Link to this heading") * Fixed sqlite column type override (#1986) [1.18.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.18.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id96 "Link to this heading") ----------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2023-04-27 ### Release notes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id97 "Link to this heading") #### Remote code generation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#remote-code-generation "Link to this heading") _Developed by [@andrewmbenton](https://github.com/andrewmbenton) _ At its core, sqlc is powered by SQL engines, which include parsers, formatters, analyzers and more. While our goal is to support each engine on each operating system, it’s not always possible. For example, the PostgreSQL engine does not work on Windows. To bridge that gap, we’re announcing remote code generation, currently in private alpha. To join the private alpha, [sign up for the waitlist](https://docs.google.com/forms/d/e/1FAIpQLScDWrGtTgZWKt3mdlF5R2XCX6tL1pMkB4yuZx5yq684tTNN1Q/viewform?usp=sf_link) . Remote code generation works like local code generation, except the heavy lifting is performed in a consistent cloud environment. WASM-based plugins are supported in the remote environment, but process-based plugins are not. To configure remote generation, add a `cloud` block in `sqlc.json`. { "version": "2", "cloud": { "organization": "", "project": "", }, ... } You’ll also need to set the `SQLC_AUTH_TOKEN` environment variable. export SQLC\_AUTH\_TOKEN\= When the `cloud` configuration block exists, `sqlc generate` will default to remote code generation. If you’d like to generate code locally without removing the `cloud` block from your config, pass the `--no-remote` option. sqlc generate \--no-remote Remote generation is off by default and requires an opt-in to use. #### sqlc.embed[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sqlc-embed "Link to this heading") _Developed by [@nickjackson](https://github.com/nickjackson) _ Embedding allows you to reuse existing model structs in more queries, resulting in less manual serialization work. First, imagine we have the following schema with students and test scores. CREATE TABLE students ( id bigserial PRIMARY KEY, name text, age integer ) CREATE TABLE test\_scores ( student\_id bigint, score integer, grade text ) We want to select the student record and the highest score they got on a test. Here’s how we’d usually do that: \-- name: HighScore :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT students.\*, high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; When using Go, sqlc will produce a struct like this: type HighScoreRow struct { ID int64 Name sql.NullString Age sql.NullInt32 HighScore int32 } With embedding, the struct will contain a model for the table instead of a flattened list of columns. \-- name: HighScoreEmbed :many WITH high\_scores AS ( SELECT student\_id, max(score) as high\_score FROM test\_scores GROUP BY 1 ) SELECT sqlc.embed(students), high\_score::integer FROM students JOIN high\_scores ON high\_scores.student\_id \= students.id; type HighScoreRow struct { Student Student HighScore int32 } #### sqlc.slice[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sqlc-slice "Link to this heading") _Developed by Paul Cameron and Jille Timmermans_ The MySQL Go driver does not support passing slices to the IN operator. The `sqlc.slice` function generates a dynamic query at runtime with the correct number of parameters. /\* name: SelectStudents :many \*/ SELECT \* FROM students WHERE age IN (sqlc.slice("ages")) func (q \*Queries) SelectStudents(ctx context.Context, ages \[\]int32) (\[\]Student, error) { This feature is only supported in MySQL and cannot be used with prepared queries. #### Batch operation improvements[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#batch-operation-improvements "Link to this heading") When using batches with pgx, the error returned when a batch is closed is exported by the generated package. This change allows for cleaner error handling using `errors.Is`. errors.Is(err, generated\_package.ErrBatchAlreadyClosed) Previously, you would have had to check match on the error message itself. err.Error() \== "batch already closed" The generated code for batch operations always lived in `batch.go`. This file name can now be configured via the `output_batch_file_name` configuration option. #### Configurable query parameter limits for Go[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#configurable-query-parameter-limits-for-go "Link to this heading") By default, sqlc will limit Go functions to a single parameter. If a query includes more than one parameter, the generated method will use an argument struct instead of positional arguments. This behavior can now be changed via the `query_parameter_limit` configuration option. If set to `0`, every genreated method will use a argument struct. ### Changes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id98 "Link to this heading") #### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id99 "Link to this heading") * Prevent variable redeclaration in single param conflict for pgx (#2058) * Retrieve Larg/Rarg join query after inner join (#2051) * Rename argument when conflicted to imported package (#2048) * Pgx closed batch return pointer if need #1959 (#1960) * Correct singularization of “waves” (#2194) * Honor Package level renames in v2 yaml config (#2001) * (mysql) Prevent UPDATE … JOIN panic #1590 (#2154) * Mysql delete join panic (#2197) * Missing import with pointer overrides, solves #2168 #2125 (#2217) #### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id100 "Link to this heading") * (config.md) Add `sqlite` as engine option (#2164) * Add first pass at pgx documentation (#2174) * Add missed configuration option (#2188) * `specifies parameter ":one" without containing a RETURNING clause` (#2173) #### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id101 "Link to this heading") * Add `sqlc.embed` to allow model re-use (#1615) * (Go) Add query\_parameter\_limit conf to codegen (#1558) * Add remote execution for codegen (#2214) #### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id102 "Link to this heading") * Skip tests if required plugins are missing (#2104) * Add tests for reanme fix in v2 (#2196) * Regenerate batch output for filename tests * Remove remote test (#2232) * Regenerate test output #### Bin/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#bin-sqlc "Link to this heading") * Add SQLCTMPDIR environment variable (#2189) #### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id103 "Link to this heading") * (deps) Bump github.com/antlr/antlr4/runtime/Go/antlr (#2109) * (deps) Bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 (#2119) * (deps) Bump golang from 1.20.1 to 1.20.2 (#2135) * (deps) Bump google.golang.org/protobuf from 1.28.1 to 1.29.0 (#2137) * (deps) Bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#2143) * (deps) Bump golang from 1.20.2 to 1.20.3 (#2192) * (deps) Bump actions/setup-go from 3 to 4 (#2150) * (deps) Bump google.golang.org/protobuf from 1.29.1 to 1.30.0 (#2151) * (deps) Bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#2193) * (deps) Bump github.com/lib/pq from 1.10.7 to 1.10.8 (#2211) * (deps) Bump github.com/lib/pq from 1.10.8 to 1.10.9 (#2229) * (deps) Bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 (#2228) #### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id104 "Link to this heading") * Remove –experimental flag (#2170) * Add option to disable process-based plugins (#2180) * Bump version to v1.18.0 #### Codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id105 "Link to this heading") * Correctly generate CopyFrom columns for single-column copyfroms (#2185) #### Config[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#config "Link to this heading") * Add top-level cloud configuration (#2204) #### Engine/postgres[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#engine-postgres "Link to this heading") * Upgrade to pg\_query\_go/v4 (#2114) #### Ext/wasm[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#ext-wasm "Link to this heading") * Check exit code on returned error (#2223) #### Parser[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#parser "Link to this heading") * Generate correct types for `SELECT NOT EXISTS` (#1972) #### Sqlite[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id106 "Link to this heading") * Add support for CREATE TABLE … STRICT (#2175) #### Wasm[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#wasm "Link to this heading") * Upgrade to wasmtime v8.0.0 (#2222) [1.17.2](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.2) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id107 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id108 "Link to this heading") * Fix build on Windows (#2102) [1.17.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.1) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id109 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-22 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id110 "Link to this heading") * Prefer to use \[\]T over pgype.Array\[T\] (#2090) * Revert changes to Dockerfile (#2091) * Do not throw error when IF NOT EXISTS is used on ADD COLUMN (#2092) ### MySQL[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#mysql "Link to this heading") * Add `float` support to MySQL (#2097) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id111 "Link to this heading") * (deps) Bump golang from 1.20.0 to 1.20.1 (#2082) [1.17.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.17.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id112 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2023-02-13 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id113 "Link to this heading") * Initialize generated code outside function (#1850) * (engine/mysql) Take into account column’s charset to distinguish text/blob, (var)char/(var)binary (#776) (#1895) * The enum Value method returns correct type (#1996) * Documentation for Inserting Rows (#2034) * Add import statements even if only pointer types exist (#2046) * Search from Rexpr if not found from Lexpr (#2056) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id114 "Link to this heading") * Change ENTRYPOINT to CMD (#1943) * Update samples for HOW-TO GUIDES (#1953) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id115 "Link to this heading") * Add the diff command (#1963) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id116 "Link to this heading") * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.15 to 1.14.16 (#1913) * (deps) Bump github.com/spf13/cobra from 1.6.0 to 1.6.1 (#1909) * Fix devcontainer (#1942) * Run sqlc-pg-gen via GitHub Actions (#1944) * Move large arrays out of functions (#1947) * Fix conflicts from pointer configuration (#1950) * (deps) Bump github.com/go-sql-driver/mysql from 1.6.0 to 1.7.0 (#1988) * (deps) Bump github.com/jackc/pgtype from 1.12.0 to 1.13.0 (#1978) * (deps) Bump golang from 1.19.3 to 1.19.4 (#1992) * (deps) Bump certifi from 2020.12.5 to 2022.12.7 in /docs (#1993) * (deps) Bump golang from 1.19.4 to 1.19.5 (#2016) * (deps) Bump golang from 1.19.5 to 1.20.0 (#2045) * (deps) Bump github.com/jackc/pgtype from 1.13.0 to 1.14.0 (#2062) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.0 (#2063) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#cmd "Link to this heading") * Generate packages in parallel (#2026) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id117 "Link to this heading") * Bump version to v1.17.0 ### Codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id118 "Link to this heading") * Remove built-in Kotlin support (#1935) * Remove built-in Python support (#1936) ### Internal/codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-codegen "Link to this heading") * Cache pattern matching compilations (#2028) ### Mysql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id119 "Link to this heading") * Add datatype tests (#1948) * Fix blob tests (#1949) ### Plugins[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#plugins "Link to this heading") * Upgrade to wasmtime 3.0.1 (#2009) ### Sqlite[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id120 "Link to this heading") * Supported between expr (#1958) (#1967) ### Tools[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#tools "Link to this heading") * Regenerate scripts skips dirs that contains diff exec command (#1987) ### Wasm[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id121 "Link to this heading") * Upgrade to wasmtime 5.0.0 (#2065) [1.16.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.16.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id122 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-11-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id123 "Link to this heading") * (validate) Sqlc.arg & sqlc.narg are not “missing” (#1814) * Emit correct comment for nullable enums (#1819) * 🐛 Correctly switch `coalesce()` result `.NotNull` value (#1664) * Prevent batch infinite loop with arg length (#1794) * Support version 2 in error message (#1839) * Handle empty column list in postgresql (#1843) * Batch imports filter queries, update cmds having ret type (#1842) * Named params contribute to batch parameter count (#1841) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id124 "Link to this heading") * Add a getting started guide for SQLite (#1798) * Various readability improvements (#1854) * Add documentation for codegen plugins (#1904) * Update migration guides with links (#1933) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id125 "Link to this heading") * Add HAVING support to MySQL (#1806) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id126 "Link to this heading") * Upgrade wasmtime version (#1827) * Bump wasmtime version to v1.0.0 (#1869) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id127 "Link to this heading") * (deps) Bump github.com/jackc/pgconn from 1.12.1 to 1.13.0 (#1785) * (deps) Bump github.com/mattn/go-sqlite3 from 1.14.13 to 1.14.15 (#1799) * (deps) Bump github.com/jackc/pgx/v4 from 4.16.1 to 4.17.0 (#1786) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.0 to 4.17.1 (#1825) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1826) * (deps) Bump github.com/jackc/pgx/v4 from 4.17.1 to 4.17.2 (#1831) * (deps) Bump golang from 1.19.0 to 1.19.1 (#1834) * (deps) Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#1838) * (deps) Bump github.com/lib/pq from 1.10.6 to 1.10.7 (#1835) * (deps) Bump github.com/bytecodealliance/wasmtime-go (#1857) * (deps) Bump github.com/spf13/cobra from 1.5.0 to 1.6.0 (#1893) * (deps) Bump golang from 1.19.1 to 1.19.3 (#1920) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id128 "Link to this heading") * Bump to v1.16.0 ### Codgen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#codgen "Link to this heading") * Include serialized codegen options (#1890) ### Compiler[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#compiler "Link to this heading") * Move Kotlin parameter logic into codegen (#1910) ### Examples[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#examples "Link to this heading") * Port Python examples to WASM plugin (#1903) ### Pg-gen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#pg-gen "Link to this heading") * Make sqlc-pg-gen the complete source of truth for pg\_catalog.go (#1809) * Implement information\_schema shema (#1815) ### Python[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id129 "Link to this heading") * Port all Python tests to sqlc-gen-python (#1907) * Upgrade to sqlc-gen-python v1.0.0 (#1932) [1.15.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.15.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id130 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-08-07 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id131 "Link to this heading") * (mysql) Typo (#1700) * (postgresql) Add quotes for CamelCase columns (#1729) * Cannot parse SQLite upsert statement (#1732) * (sqlite) Regenerate test output for builtins (#1735) * (wasm) Version modules by wasmtime version (#1734) * Missing imports (#1637) * Missing slice import for querier (#1773) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id132 "Link to this heading") * Add process-based plugin docs (#1669) * Add links to downloads.sqlc.dev (#1681) * Update transactions how to example (#1775) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id133 "Link to this heading") * More SQL Syntax Support for SQLite (#1687) * (sqlite) Promote SQLite support to beta (#1699) * Codegen plugins, powered by WASM (#1684) * Set user-agent for plugin downloads (#1707) * Null enums types (#1485) * (sqlite) Support stdlib functions (#1712) * (sqlite) Add support for returning (#1741) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id134 "Link to this heading") * Add tests for quoting columns (#1733) * Remove catalog tests (#1762) ### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id135 "Link to this heading") * Add tests for fixing slice imports (#1736) * Add test cases for returning (#1737) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id136 "Link to this heading") * Upgrade to Go 1.19 (#1780) * Upgrade to go-wasmtime 0.39.0 (#1781) ### Plugins[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id137 "Link to this heading") * (wasm) Change default cache location (#1709) * (wasm) Change the SHA-256 config key (#1710) [1.14.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.14.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id138 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-06-09 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id139 "Link to this heading") * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) * (compiler) Fix left join nullability with table aliases (#1491) * Regenerate testdata for CREATE TABLE AS (#1516) * (bundler) Only close multipart writer once (#1528) * (endtoend) Regenerate testdata for exex\_lastid * (pgx) Copyfrom imports (#1626) * Validate sqlc function arguments (#1633) * Fixed typo `sql.narg` in doc (#1668) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id140 "Link to this heading") * (golang) Add Enum.Valid and AllEnumValues (#1613) * (sqlite) Start expanding support (#1410) * (pgx) Add support for batch operations (#1437) * (sqlite) Add support for delete statements (#1447) * (codegen) Insert comments in interfaces (#1458) * (sdk) Add the plugin SDK package (#1463) * Upload projects (#1436) * Add sqlc version to generated Kotlin code (#1512) * Add sqlc version to generated Go code (#1513) * Pass sqlc version in codegen request (#1514) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * Run sqlc with docker on windows cmd (#1557) * Add JSON “codegen” output (#1565) * Add sqlc.narg() for nullable named params (#1536) * Process-based codegen plugins (#1578) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id141 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id142 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) * (sql/catalog) Improve Readability (#1595) * Add basic fuzzing for config / overrides (#1500) [1.13.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.13.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id143 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-03-31 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id144 "Link to this heading") * (compiler) Fix left join nullability with table aliases (#1491) * (postgresql) Remove extra newline with db argument (#1417) * (sqlite) Fix DROP TABLE (#1443) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id145 "Link to this heading") * (cli) Upload projects (#1436) * (codegen) Add sqlc version to generated Go code (#1513) * (codegen) Add sqlc version to generated Kotlin code (#1512) * (codegen) Insert comments in interfaces (#1458) * (codegen) Pass sqlc version in codegen request (#1514) * (pgx) Add support for batch operations (#1437) * (postgresql) Add materialized view support (#1509) * (python) Graduate Python support to beta (#1520) * (sdk) Add the plugin SDK package (#1463) * (sqlite) Add support for delete statements (#1447) * (sqlite) Start expanding support (#1410) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id146 "Link to this heading") * Fix extra newline in comments for copyfrom (#1438) * Generate marshal/unmarshal with vtprotobuf (#1467) ### Refactor[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id147 "Link to this heading") * (codegen) Port Kotlin codegen package to use plugin types (#1416) * (codegen) Port Go to plugin types (#1460) * (cmd) Simplify codegen selection logic (#1466) ### Config[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id148 "Link to this heading") * Add basic fuzzing for config / overrides (#1500) [1.12.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.12.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id149 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2022-02-05 ### Bug[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#bug "Link to this heading") * ALTER TABLE SET SCHEMA (#1409) ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id150 "Link to this heading") * Update ANTLR v4 go.mod entry (#1336) * Check delete statements for CTEs (#1329) * Fix validation of GROUP BY on field aliases (#1348) * Fix imports when non-copyfrom queries needed imports that copyfrom queries didn’t (#1386) * Remove extra comment newline (#1395) * Enable strict function checking (#1405) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id151 "Link to this heading") * Bump version to 1.11.0 (#1308) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id152 "Link to this heading") * Inheritance (#1339) * Generate query code using ASTs instead of templates (#1338) * Add support for CREATE TABLE a ( LIKE b ) (#1355) * Add support for sql.NullInt16 (#1376) ### Miscellaneous Tasks[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id153 "Link to this heading") * Add tests for :exec{result,rows} (#1344) * Delete template-based codegen (#1345) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id154 "Link to this heading") * Bump github.com/jackc/pgx/v4 from 4.14.0 to 4.14.1 (#1316) * Bump golang from 1.17.3 to 1.17.4 (#1331) * Bump golang from 1.17.4 to 1.17.5 (#1337) * Bump github.com/spf13/cobra from 1.2.1 to 1.3.0 (#1343) * Remove devel Docker build * Bump golang from 1.17.5 to 1.17.6 (#1369) * Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 (#1382) * Format all Go code (#1387) [1.11.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.11.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id155 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-11-24 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id156 "Link to this heading") * Update incorrect signatures (#1180) * Correct aggregate func sig (#1182) * Jsonb\_build\_object (#1211) * Case-insensitive identifiers (#1216) * Incorrect handling of meta (#1228) * Detect invalid INSERT expression (#1231) * Respect alias name for coalesce (#1232) * Mark nullable when casting NULL (#1233) * Support nullable fields in joins for MySQL engine (#1249) * Fix between expression handling of table references (#1268) * Support nullable fields in joins on same table (#1270) * Fix missing binds in ORDER BY (#1273) * Set RV for TargetList items on updates (#1252) * Fix MySQL parser for query without trailing semicolon (#1282) * Validate table alias references (#1283) * Add support for MySQL ON DUPLICATE KEY UPDATE (#1286) * Support references to columns in joined tables in UPDATE statements (#1289) * Add validation for GROUP BY clause column references (#1285) * Prevent variable redeclaration in single param conflict (#1298) * Use common params struct field for same named params (#1296) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id157 "Link to this heading") * Replace deprecated go get with go install (#1181) * Fix package name referenced in tutorial (#1202) * Add environment variables (#1264) * Add go.17+ install instructions (#1280) * Warn about golang-migrate file order (#1302) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id158 "Link to this heading") * Instrument compiler via runtime/trace (#1258) * Add MySQL support for BETWEEN arguments (#1265) ### Refactor[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id159 "Link to this heading") * Move from io/ioutil to io and os package (#1164) ### Styling[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#styling "Link to this heading") * Apply gofmt to sample code (#1261) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id160 "Link to this heading") * Bump golang from 1.17.0 to 1.17.1 (#1173) * Bump eskatos/gradle-command-action from 1 to 2 (#1220) * Bump golang from 1.17.1 to 1.17.2 (#1227) * Bump github.com/pganalyze/pg\_query\_go/v2 (#1234) * Bump actions/checkout from 2.3.4 to 2.3.5 (#1238) * Bump babel from 2.9.0 to 2.9.1 in /docs (#1245) * Bump golang from 1.17.2 to 1.17.3 (#1272) * Bump actions/checkout from 2.3.5 to 2.4.0 (#1267) * Bump github.com/lib/pq from 1.10.3 to 1.10.4 (#1278) * Bump github.com/jackc/pgx/v4 from 4.13.0 to 4.14.0 (#1303) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id161 "Link to this heading") * Bump version to v1.11.0 [1.10.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.10.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id162 "Link to this heading") ------------------------------------------------------------------------------------------------------------------------------------------------------------ Released 2021-09-07 ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id163 "Link to this heading") * Fix invalid language support table (#1161) * Add a getting started guide for MySQL (#1163) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id164 "Link to this heading") * Bump golang from 1.16.7 to 1.17.0 (#1129) * Bump github.com/lib/pq from 1.10.2 to 1.10.3 (#1160) ### Ci[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id165 "Link to this heading") * Upgrade Go to 1.17 (#1130) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id166 "Link to this heading") * Bump version to v1.10.0 (#1165) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#codegen-golang "Link to this heading") * Consolidate import logic (#1139) * Add pgx support for range types (#1146) * Use pgtype for hstore when using pgx (#1156) ### Codgen/golang[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#codgen-golang "Link to this heading") * Use p\[gq\]type for network address types (#1142) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#endtoend "Link to this heading") * Run `go test` in CI (#1134) ### Engine/mysql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#engine-mysql "Link to this heading") * Add support for LIKE (#1162) ### Golang[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#golang "Link to this heading") * Output NullUUID when necessary (#1137) [1.9.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.9.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id167 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-08-13 ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id168 "Link to this heading") * Update documentation (a bit) for v1.9.0 (#1117) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id169 "Link to this heading") * Bump golang from 1.16.6 to 1.16.7 (#1107) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id170 "Link to this heading") * Bump version to v1.9.0 (#1121) ### Compiler[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id171 "Link to this heading") * Add tests for COALESCE behavior (#1112) * Handle subqueries in SELECT statements (#1113) [1.8.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.8.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id172 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-05-03 ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id173 "Link to this heading") * Add language support Matrix (#920) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id174 "Link to this heading") * Add case style config option (#905) ### Python[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id175 "Link to this heading") * Eliminate runtime package and use sqlalchemy (#939) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id176 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.4 to 0.5.5 (#926) * Bump github.com/lib/pq from 1.9.0 to 1.10.0 (#931) * Bump golang from 1.16.0 to 1.16.1 (#935) * Bump golang from 1.16.1 to 1.16.2 (#942) * Bump github.com/jackc/pgx/v4 from 4.10.1 to 4.11.0 (#956) * Bump github.com/go-sql-driver/mysql from 1.5.0 to 1.6.0 (#961) * Bump github.com/pganalyze/pg\_query\_go/v2 (#965) * Bump urllib3 from 1.26.3 to 1.26.4 in /docs (#968) * Bump golang from 1.16.2 to 1.16.3 (#963) * Bump github.com/lib/pq from 1.10.0 to 1.10.1 (#980) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id177 "Link to this heading") * Add the –experimental flag (#929) * Fix sqlc init (#959) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id178 "Link to this heading") * Bump version to v1.7.1-devel (#913) * Bump version to v1.8.0 ### Codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id179 "Link to this heading") * Generate valid enum names for symbols (#972) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#postgresql "Link to this heading") * Support generated columns * Add test for PRIMARY KEY INCLUDE * Add tests for CREATE TABLE PARTITION OF * CREATE TRIGGER EXECUTE FUNCTION * Add support for renaming types (#971) ### Sql/ast[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sql-ast "Link to this heading") * Resolve return values from functions (#964) ### Workflows[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#workflows "Link to this heading") * Only run tests once (#924) [1.7.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.7.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id180 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2021-02-28 ### Bug Fixes[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id181 "Link to this heading") * Struct tag formatting (#833) ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id182 "Link to this heading") * Include all the existing Markdown files (#877) * Split docs into four sections (#882) * Reorganize and consolidate documentation * Add link to Windows download (#888) * Shorten the README (#889) ### Features[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id183 "Link to this heading") * Adding support for pgx/v4 * Adding support for pgx/v4 ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#readme "Link to this heading") * Add Go Report Card badge (#891) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id184 "Link to this heading") * Bump github.com/google/go-cmp from 0.5.3 to 0.5.4 (#813) * Bump github.com/lib/pq from 1.8.0 to 1.9.0 (#820) * Bump golang from 1.15.5 to 1.15.6 (#822) * Bump github.com/jackc/pgx/v4 from 4.9.2 to 4.10.0 (#823) * Bump github.com/jackc/pgx/v4 from 4.10.0 to 4.10.1 (#839) * Bump golang from 1.15.6 to 1.15.7 (#855) * Bump golang from 1.15.7 to 1.15.8 (#881) * Bump github.com/spf13/cobra from 1.1.1 to 1.1.2 (#892) * Bump golang from 1.15.8 to 1.16.0 (#897) * Bump github.com/lfittl/pg\_query\_go from 1.0.1 to 1.0.2 (#901) * Bump github.com/spf13/cobra from 1.1.2 to 1.1.3 (#893) ### Catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#catalog "Link to this heading") * Improve alter column type (#818) ### Ci[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id185 "Link to this heading") * Uprade to Go 1.15 (#887) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id186 "Link to this heading") * Allow config file location to be specified (#863) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id187 "Link to this heading") * Bump to version v1.6.1-devel (#807) * Bump version to v1.7.0 (#912) ### Codegen/golang[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id188 "Link to this heading") * Make sure to import net package (#858) ### Compiler[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id189 "Link to this heading") * Support UNION query ### Dolphin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#dolphin "Link to this heading") * Generate bools for tinyint(1) * Support joins in update statements (#883) * Add support for union query ### Endtoend[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id190 "Link to this heading") * Add tests for INTERSECT and EXCEPT ### Go.mod[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#go-mod "Link to this heading") * Update to go 1.15 and run ‘go mod tidy’ (#808) ### Mysql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id191 "Link to this heading") * Compile tinyint(1) to bool (#873) ### Sql/ast[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id192 "Link to this heading") * Add enum values for SetOperation [1.6.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.6.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id193 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-11-23 ### Dolphin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id194 "Link to this heading") * Implement Rename (#651) * Skip processing view drops (#653) ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id195 "Link to this heading") * Update language / database support (#698) ### Astutils[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#astutils "Link to this heading") * Fix Params rewrite call (#674) ### Build[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id196 "Link to this heading") * Bump golang from 1.14 to 1.15.3 (#765) * Bump docker/build-push-action from v1 to v2.1.0 (#764) * Bump github.com/google/go-cmp from 0.4.0 to 0.5.2 (#766) * Bump github.com/spf13/cobra from 1.0.0 to 1.1.1 (#767) * Bump github.com/jackc/pgx/v4 from 4.6.0 to 4.9.2 (#768) * Bump github.com/lfittl/pg\_query\_go from 1.0.0 to 1.0.1 (#773) * Bump github.com/google/go-cmp from 0.5.2 to 0.5.3 (#783) * Bump golang from 1.15.3 to 1.15.5 (#782) * Bump github.com/lib/pq from 1.4.0 to 1.8.0 (#769) ### Catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id197 "Link to this heading") * Improve variadic argument support (#804) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id198 "Link to this heading") * Bump to version v1.6.0 (#806) ### Codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id199 "Link to this heading") * Fix errant database/sql imports (#789) ### Compiler[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id200 "Link to this heading") * Use engine-specific reserved keywords (#677) ### Dolphi[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#dolphi "Link to this heading") * Add list of builtin functions (#795) ### Dolphin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id201 "Link to this heading") * Update to the latest MySQL parser (#665) * Add ENUM() support (#676) * Add test for table aliasing (#684) * Add MySQL ddl\_create\_table test (#685) * Implete TRUNCATE table (#697) * Represent tinyint as int32 (#797) * Add support for coalesce (#802) * Add function signatures (#796) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id202 "Link to this heading") * Add MySQL json test (#692) * Add MySQL update set multiple test (#696) ### Examples[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id203 "Link to this heading") * Use generated enum constants in db\_test (#678) * Port ondeck to MySQL (#680) * Add MySQL authors example (#682) ### Internal/cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-cmd "Link to this heading") * Print correct config file on parse failure (#749) ### Kotlin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id204 "Link to this heading") * Remove runtime dependency (#774) ### Metadata[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#metadata "Link to this heading") * Support multiple comment prefixes (#683) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id205 "Link to this heading") * Support string concat operator (#701) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sql-catalog "Link to this heading") * Add support for variadic functions (#798) [1.5.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.5.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id206 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-08-05 ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id207 "Link to this heading") * Build sqlc using Go 1.14 (#549) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id208 "Link to this heading") * Add debugging support (#573) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id209 "Link to this heading") * Bump version to v1.4.1-devel (#548) * Bump version to v1.5.0 ### Compiler[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id210 "Link to this heading") * Support calling functions with defaults (#635) * Skip func args without a paramRef (#636) * Return a single column from coalesce (#639) ### Config[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id211 "Link to this heading") * Add emit\_empty\_slices to version one (#552) ### Contrib[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#contrib "Link to this heading") * Add generated code for contrib ### Dinosql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#dinosql "Link to this heading") * Remove deprecated package (#554) ### Dolphin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id212 "Link to this heading") * Add support for column aliasing (#566) * Implement star expansion for subqueries (#619) * Implement exapansion with reserved words (#620) * Implement parameter refs (#621) * Implement limit and offest (#622) * Implement inserts (#623) * Implement delete (#624) * Implement simple update statements (#625) * Implement INSERT … SELECT (#626) * Use test driver instead of TiDB driver (#629) * Implement named parameters via sqlc.arg() (#632) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id213 "Link to this heading") * Add MySQL test for SELECT \* JOIN (#565) * Add MySQL test for inflection (#567) ### Engine[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#engine "Link to this heading") * Create engine package (#556) ### Equinox[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#equinox "Link to this heading") * Use the new equinox-io/setup action (#586) ### Examples[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id214 "Link to this heading") * Run tests for MySQL booktest (#627) ### Golang[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id215 "Link to this heading") * Add support for the money type (#561) * Generate correct types for int2 and int8 (#579) ### Internal[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal "Link to this heading") * Rm catalog, pg, postgres packages (#555) ### Mod[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#mod "Link to this heading") * Downgrade TiDB package to fix build (#603) ### Mysql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id216 "Link to this heading") * Upgrade to the latest vitess commit (#562) * Support to infer type of a duplicated arg (#615) * Allow some builtin functions to be nullable (#616) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id217 "Link to this heading") * Generate all functions in pg\_catalog (#550) * Remove pg\_catalog schema from tests (#638) * Move contrib code to a package ### Sql/catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id218 "Link to this heading") * Fix comparison of pg\_catalog types (#637) ### Tools[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id219 "Link to this heading") * Generate functions for all of contrib ### Workflow[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#workflow "Link to this heading") * Migrate to equinox-io/setup-release-tool (#614) [1.4.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.4.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id220 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-06-17 ### Dockerfile[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#dockerfile "Link to this heading") * Add version build argument (#487) ### MySQL[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id221 "Link to this heading") * Prevent Panic when WHERE clause contains parenthesis. (#531) ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id222 "Link to this heading") * Document emit\_exact\_table\_names (#486) ### All[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#all "Link to this heading") * Remove the exp build tag (#507) ### Catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id223 "Link to this heading") * Support functions with table parameters (#541) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id224 "Link to this heading") * Bump to version 1.3.1-devel (#485) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id225 "Link to this heading") * Bump version to v1.4.0 (#547) ### Codegen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id226 "Link to this heading") * Add the new codegen packages (#513) * Add the :execresult query annotation (#542) ### Compiler[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id227 "Link to this heading") * Validate function calls (#505) * Port bottom of parseQuery (#510) * Don’t mutate table name (#517) * Enable experimental parser by default (#518) * Apply rename rules to enum constants (#523) * Temp fix for typecast function parameters (#530) ### Endtoend[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id228 "Link to this heading") * Standardize JSON formatting (#490) * Add per-test configuration files (#521) * Read expected stderr failures from disk (#527) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-dinosql "Link to this heading") * Check parameter style before ref (#488) * Remove unneeded column suffix (#492) * Support named function arguments (#494) ### Internal/postgresql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-postgresql "Link to this heading") * Fix NamedArgExpr rewrite (#491) ### Multierr[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#multierr "Link to this heading") * Move dinosql.ParserErr to a new package (#496) ### Named[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#named "Link to this heading") * Port parameter style validation to SQL (#504) ### Parser[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id229 "Link to this heading") * Support columns from subselect statements (#489) ### Rewrite[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#rewrite "Link to this heading") * Move parameter rewrite to package (#499) ### Sqlite[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id230 "Link to this heading") * Use convert functions instead of the listener (#519) ### Sqlpath[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sqlpath "Link to this heading") * Move ReadSQLFiles into a separate package (#495) ### Validation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#validation "Link to this heading") * Move query validation to separate package (#498) [1.3.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.3.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id231 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-05-12 ### Makefile[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#makefile "Link to this heading") * Update target (#449) ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id232 "Link to this heading") * Add Myles as a sponsor (#469) ### Testing[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id233 "Link to this heading") * Make sure all Go examples build (#480) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id234 "Link to this heading") * Bump version to v1.3.0 (#484) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id235 "Link to this heading") * Bump version to v1.2.1-devel (#442) ### Dinosql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id236 "Link to this heading") * Inline addFile (#446) * Add PostgreSQL support for TRUNCATE (#448) ### Gen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#gen "Link to this heading") * Emit json.RawMessage for JSON columns (#461) ### Go.mod[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id237 "Link to this heading") * Use latest lib/pq (#471) ### Parser[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id238 "Link to this heading") * Use same function to load SQL files (#483) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id239 "Link to this heading") * Fix panic walking CreateTableAsStmt (#475) [1.2.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.2.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id240 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-04-07 ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id241 "Link to this heading") * Publish to Docker Hub (#422) ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id242 "Link to this heading") * Docker installation docs (#424) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id243 "Link to this heading") * Bump version to v1.1.1-devel (#407) * Bump version to v1.2.0 (#441) ### Gen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id244 "Link to this heading") * Add special case for “campus” (#435) * Properly quote reserved keywords on expansion (#436) ### Migrations[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#migrations "Link to this heading") * Move migration parsing to new package (#427) ### Parser[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id245 "Link to this heading") * Generate correct types for SELECT EXISTS (#411) [1.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.1.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id246 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-03-17 ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id247 "Link to this heading") * Add installation instructions (#350) * Add section on running tests (#357) * Fix typo (#371) ### Ast[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#ast "Link to this heading") * Add AST for ALTER TABLE ADD / DROP COLUMN (#376) * Add support for CREATE TYPE as ENUM (#388) * Add support for CREATE / DROP SCHEMA (#389) ### Astutils[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id248 "Link to this heading") * Apply changes to the ValuesList slice (#372) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id249 "Link to this heading") * Return v1.0.0 (#348) * Return next bug fix version (#349) ### Cmd/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id250 "Link to this heading") * Bump version to v1.1.0 (#406) ### Compiler[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id251 "Link to this heading") * Wire up the experimental parsers ### Config[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id252 "Link to this heading") * Remove “emit\_single\_file” option (#367) ### Dolphin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id253 "Link to this heading") * Add experimental parser for MySQL ### Gen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id254 "Link to this heading") * Add option to emit single file for Go (#366) * Add support for the ltree extension (#385) ### Go.mod[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id255 "Link to this heading") * Add packages for MySQL and SQLite parsers ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id256 "Link to this heading") * Support Postgres macaddr type in Go (#358) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-endtoend "Link to this heading") * Remove %w (#354) ### Kotlin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id257 "Link to this heading") * Add Query class to support timeout and cancellation (#368) ### Postgresql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id258 "Link to this heading") * Add experimental parser for MySQL ### Sql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sql "Link to this heading") * Add generic SQL AST ### Sql/ast[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id259 "Link to this heading") * Port support for COMMENT ON (#391) * Implement DROP TYPE (#397) * Implement ALTER TABLE RENAME (#398) * Implement ALTER TABLE RENAME column (#399) * Implement ALTER TABLE SET SCHEMA (#400) ### Sql/catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id260 "Link to this heading") * Port tests over from catalog pkg (#402) ### Sql/errors[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#sql-errors "Link to this heading") * Add a new errors package (#390) ### Sqlite[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id261 "Link to this heading") * Add experimental parser for SQLite [1.0.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.0.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id262 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-02-18 ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id263 "Link to this heading") * Add documentation for query commands (#270) * Add named parameter documentation (#332) ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id264 "Link to this heading") * Add sponsors section (#333) ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id265 "Link to this heading") * Remove parse subcommand (#322) ### Config[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id266 "Link to this heading") * Parse V2 config format * Add support for YAML (#336) ### Examples[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id267 "Link to this heading") * Add the jets and booktest examples (#237) * Move sqlc.json into examples folder (#238) * Add the authors example (#241) * Add build tag to authors tests (#319) ### Internal[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id268 "Link to this heading") * Allow CTE to be used with UPDATE (#268) * Remove the PackageMap from settings (#295) ### Internal/config[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id269 "Link to this heading") * Create new config package (#313) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id270 "Link to this heading") * Emit Querier interface (#240) * Strip leading “go-” or trailing “-go” from import (#262) * Overrides can now be basic types (#271) * Import needed types for Querier (#285) * Handle schema-scoped enums (#310) * Ignore golang-migrate rollbacks (#320) ### Internal/endtoend[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id271 "Link to this heading") * Move more tests to the record/replay framework * Add update test for named params (#329) ### Internal/mysql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-mysql "Link to this heading") * Fix flaky test (#242) * Port tests to endtoend package (#315) ### Internal/parser[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-parser "Link to this heading") * Resolve nested CTEs (#324) * Error if last query is missing (#325) * Support joins with aliases (#326) * Remove print statement (#327) ### Internal/sqlc[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-sqlc "Link to this heading") * Add support for composite types (#311) ### Kotlin[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id272 "Link to this heading") * Support primitives * Arrays, enums, and dates * Generate examples * README for examples * Factor out db setup extension * Fix enums, use List instead of Array * Port Go tests for examples * Rewrite numbered params to positional params * Always use use, fix indents * Unbox query params ### Parser[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id273 "Link to this heading") * Attach range vars to insert params * Attach range vars to insert params (#342) * Remove dead code (#343) [0.1.0](https://github.com/sqlc-dev/sqlc/releases/tag/v0.1.0) [](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id274 "Link to this heading") ---------------------------------------------------------------------------------------------------------------------------------------------------------- Released 2020-01-07 ### Documentation[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id275 "Link to this heading") * Replace remaining references to DinoSQL with sqlc (#149) ### README[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id276 "Link to this heading") * Fix download links (#66) * Add LIMIT 1 to query that should return one (#99) ### Catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id277 "Link to this heading") * Support “ALTER TABLE … DROP CONSTRAINT …” (#34) * Differentiate functions with different argument types (#51) ### Ci[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id278 "Link to this heading") * Enable tests on pull requests ### Cmd[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id279 "Link to this heading") * Include filenames in error messages (#69) * Do not output any changes on error (#72) ### Dinosql/internal[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#dinosql-internal "Link to this heading") * Add lower and upper functions (#215) * Ignore alter sequence commands (#219) ### Gen[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id280 "Link to this heading") * Add DO NOT EDIT comments to generated code (#50) * Include all schemas when generating models (#90) * Prefix structs with schema name (#91) * Generate single import for uuid package (#98) * Use same import logic for all Go files * Pick correct struct to return for queries (#107) * Create consistent JSON tags (#110) * Add Close method to Queries struct (#127) * Ignore empty override settings (#128) * Turn SQL comments into Go comments (#136) ### Internal/catalog[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-catalog "Link to this heading") * Parse unnamed function arguments (#166) ### Internal/dinosql[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id281 "Link to this heading") * Prepare() with no GoQueries still valid (#95) * Fix multiline comment rendering (#142) * Dereference alias nodes on walk (#158) * Ignore sql-migrate rollbacks (#160) * Sort imported packages (#165) * Add support for timestamptz (#169) * Error on missing queries (#180) * Use more database/sql null types (#182) * Support the pg\_temp schema (#183) * Override columns with array type (#184) * Implement robust expansion * Implement robust expansion (#186) * Add COMMENT ON support (#191) * Add DATE support * Add DATE support (#196) * Filter out invalid characters (#198) * Quote reserved keywords (#205) * Return parser errors first (#207) * Implement advisory locks (#212) * Error on duplicate query names (#221) * Fix incorrect enum names (#223) * Add support for numeric types * Add support for numeric types (#228) ### Internal/dinosql/testdata/ondeck[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#internal-dinosql-testdata-ondeck "Link to this heading") * Add Makefile (#156) ### Ondeck[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#ondeck "Link to this heading") * Move all tests to GitHub CI (#58) ### ParseQuery[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#parsequery "Link to this heading") * Return either a query or an error (#178) ### Parser[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#id282 "Link to this heading") * Use schema when resolving catalog refs (#82) * Support function calls in expressions (#104) * Correctly handle single files (#119) * Return error if missing RETURNING (#131) * Add support for mathmatical operators (#132) * Add support for simple case expressions (#134) * Error on mismatched INSERT input (#135) * Set IsArray on joined columns (#139) ### Pg[](https://docs.sqlc.dev/en/v1.31.1/reference/changelog.html#pg "Link to this heading") * Store functions in the catalog (#41) * Add location to errors (#73) ---