Repository: sqlc-dev/sqlc
Pull request #2864 (2023-10-16 19:17:20)

fix(compiler): Pull in array information from analyzer
Fixes https://github.com/sqlc-dev/sqlc/issues/1532


Patch:
diff --git a/Makefile b/Makefile
index 3cd60dc97..3f1245147 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ sqlc-gen-json:
 	go build -o ~/bin/sqlc-gen-json ./cmd/sqlc-gen-json
 
 start:
-	docker-compose up -d
+	docker compose up -d
 
 fmt:
 	go fmt ./...
diff --git a/docker-compose.yml b/docker-compose.yml
index 07540c873..3087dcc6b 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -6,7 +6,7 @@ services:
       - "3306:3306"
     restart: always
     environment:
-      MYSQL_DATABASE: mysql
+      MYSQL_DATABASE: dinotest
       MYSQL_ROOT_PASSWORD: mysecretpassword
       MYSQL_ROOT_HOST: '%'
 
@@ -16,7 +16,7 @@ services:
       - "3305:3306"
     restart: always
     environment:
-      MYSQL_DATABASE: mysql
+      MYSQL_DATABASE: dinotest
       MYSQL_ROOT_PASSWORD: mysecretpassword
       MYSQL_ROOT_HOST: '%'
     profiles:
diff --git a/docs/guides/development.md b/docs/guides/development.md
index 5140f086e..7f0311583 100644
--- a/docs/guides/development.md
+++ b/docs/guides/development.md
@@ -24,7 +24,7 @@ These tests require locally-running database instances. Run these databases
 using [Docker Compose](https://docs.docker.com/compose/).
 
 ```
-docker-compose up -d
+docker compose up -d
 ```
 
 The tests use the following environment variables to connect to the
diff --git a/docs/requirements.txt b/docs/requirements.txt
index 3a2b3a1b2..20e1188ec 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -24,4 +24,4 @@ sphinxcontrib-serializinghtml==1.1.9
 sphinxcontrib-htmlhelp==2.0.4
 sphinxcontrib-jsmath==1.0.1
 sphinxcontrib-qthelp==1.0.6
-urllib3==2.0.6
+urllib3==2.0.7
diff --git a/examples/authors/postgresql/db.go b/examples/authors/postgresql/db.go
index f5d9de730..00b0ad854 100644
--- a/examples/authors/postgresql/db.go
+++ b/examples/authors/postgresql/db.go
@@ -6,14 +6,15 @@ package authors
 
 import (
 	"context"
-	"database/sql"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
 )
 
 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
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
 }
 
 func New(db DBTX) *Queries {
@@ -24,7 +25,7 @@ type Queries struct {
 	db DBTX
 }
 
-func (q *Queries) WithTx(tx *sql.Tx) *Queries {
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
 	return &Queries{
 		db: tx,
 	}
diff --git a/examples/authors/postgresql/models.go b/examples/authors/postgresql/models.go
index ec61702f5..6961baa5f 100644
--- a/examples/authors/postgresql/models.go
+++ b/examples/authors/postgresql/models.go
@@ -5,11 +5,11 @@
 package authors
 
 import (
-	"database/sql"
+	"github.com/jackc/pgx/v5/pgtype"
 )
 
 type Author struct {
 	ID   int64
 	Name string
-	Bio  sql.NullString
+	Bio  pgtype.Text
 }
diff --git a/examples/authors/postgresql/query.sql.go b/examples/authors/postgresql/query.sql.go
index a3864f0d9..a8c3d5996 100644
--- a/examples/authors/postgresql/query.sql.go
+++ b/examples/authors/postgresql/query.sql.go
@@ -7,7 +7,8 @@ package authors
 
 import (
 	"context"
-	"database/sql"
+
+	"github.com/jackc/pgx/v5/pgtype"
 )
 
 const createAuthor = `-- name: CreateAuthor :one
@@ -21,11 +22,11 @@ RETURNING id, name, bio
 
 type CreateAuthorParams struct {
 	Name string
-	Bio  sql.NullString
+	Bio  pgtype.Text
 }
 
 func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) {
-	row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio)
+	row := q.db.QueryRow(ctx, createAuthor, arg.Name, arg.Bio)
 	var i Author
 	err := row.Scan(&i.ID, &i.Name, &i.Bio)
 	return i, err
@@ -37,7 +38,7 @@ WHERE id = $1
 `
 
 func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error {
-	_, err := q.db.ExecContext(ctx, deleteAuthor, id)
+	_, err := q.db.Exec(ctx, deleteAuthor, id)
 	return err
 }
 
@@ -47,7 +48,7 @@ WHERE id = $1 LIMIT 1
 `
 
 func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) {
-	row := q.db.QueryRowContext(ctx, getAuthor, id)
+	row := q.db.QueryRow(ctx, getAuthor, id)
 	var i Author
 	err := row.Scan(&i.ID, &i.Name, &i.Bio)
 	return i, err
@@ -59,7 +60,7 @@ ORDER BY name
 `
 
 func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
-	rows, err := q.db.QueryContext(ctx, listAuthors)
+	rows, err := q.db.Query(ctx, listAuthors)
 	if err != nil {
 		return nil, err
 	}
@@ -72,9 +73,6 @@ func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
 		}
 		items = append(items, i)
 	}
-	if err := rows.Close(); err != nil {
-		return nil, err
-	}
 	if err := rows.Err(); err != nil {
 		return nil, err
 	}
diff --git a/examples/authors/sqlc.yaml b/examples/authors/sqlc.yaml
index 9ba523c0d..cc3694965 100644
--- a/examples/authors/sqlc.yaml
+++ b/examples/authors/sqlc.yaml
@@ -15,6 +15,7 @@ sql:
   gen:
     go:
       package: authors
+      sql_package: pgx/v5
       out: postgresql
 - schema: mysql/schema.sql
   queries: mysql/query.sql
@@ -45,4 +46,4 @@ rules:
   rule: "postgresql.explain.plan.total_cost > 300.0"
 - name: mysql-query-too-costly
   message: "Too costly"
-  rule: "has(mysql.explain.query_block.cost_info) && double(mysql.explain.query_block.cost_info.query_cost) > 2.0"
\ No newline at end of file
+  rule: "has(mysql.explain.query_block.cost_info) && double(mysql.explain.query_block.cost_info.query_cost) > 2.0"
diff --git a/examples/batch/postgresql/batch.go b/examples/batch/postgresql/batch.go
index aa905c88c..ca42f2a91 100644
--- a/examples/batch/postgresql/batch.go
+++ b/examples/batch/postgresql/batch.go
@@ -8,10 +8,9 @@ package batch
 import (
 	"context"
 	"errors"
-	"time"
 
-	"github.com/jackc/pgtype"
-	"github.com/jackc/pgx/v4"
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgtype"
 )
 
 var (
@@ -114,13 +113,13 @@ type CreateBookBatchResults struct {
 }
 
 type CreateBookParams struct {
-	AuthorID  int32     `json:"author_id"`
-	Isbn      string    `json:"isbn"`
-	BookType  BookType  `json:"book_type"`
-	Title     string    `json:"title"`
-	Year      int32     `json:"year"`
-	Available time.Time `json:"available"`
-	Tags      []string  `json:"tags"`
+	AuthorID  int32              `json:"author_id"`
+	Isbn      string             `json:"isbn"`
+	BookType  BookType           `json:"book_type"`
+	Title     string             `json:"title"`
+	Year      int32              `json:"year"`
+	Available pgtype.Timestamptz `json:"available"`
+	Tags      []string           `json:"tags"`
 }
 
 func (q *Queries) CreateBook(ctx context.Context, arg []CreateBookParams) *CreateBookBatchResults {
@@ -328,10 +327,10 @@ func (q *Queries) GetBiography(ctx context.Context, authorID []int32) *GetBiogra
 	return &GetBiographyBatchResults{br, len(authorID), false}
 }
 
-func (b *GetBiographyBatchResults) QueryRow(f func(int, pgtype.JSONB, error)) {
+func (b *GetBiographyBatchResults) QueryRow(f func(int, []byte, error)) {
 	defer b.br.Close()
 	for t := 0; t < b.tot; t++ {
-		var biography pgtype.JSONB
+		var biography []byte
 		if b.closed {
 			if f != nil {
 				f(t, biography, ErrBatchAlreadyClosed)
diff --git a/examples/batch/postgresql/db.go b/examples/batch/postgresql/db.go
index c9a9445f7..330c3e0f6 100644
--- a/examples/batch/postgresql/db.go
+++ b/examples/batch/postgresql/db.go
@@ -7,8 +7,8 @@ package batch
 import (
 	"context"
 
-	"github.com/jackc/pgconn"
-	"github.com/jackc/pgx/v4"
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
 )
 
 type DBTX interface {
diff --git a/examples/batch/postgresql/models.go b/examples/batch/postgresql/models.go
index fdb04683f..124769fad 100644
--- a/examples/batch/postgresql/models.go
+++ b/examples/batch/postgresql/models.go
@@ -7,9 +7,8 @@ package batch
 import (
 	"database/sql/driver"
 	"fmt"
-	"time"
 
-	"github.com/jackc/pgtype"
+	"github.com/jackc/pgx/v5/pgtype"
 )
 
 type BookType string
@@ -55,18 +54,18 @@ func (ns NullBookType) Value() (driver.Value, error) {
 }
 
 type Author struct {
-	AuthorID  int32        `json:"author_id"`
-	Name      string       `json:"name"`
-	Biography pgtype.JSONB `json:"biography"`
+	AuthorID  int32  `json:"author_id"`
+	Name      string `json:"name"`
+	Biography []byte `json:"biography"`
 }
 
 type Book struct {
-	BookID    int32     `json:"book_id"`
-	AuthorID  int32     `json:"author_id"`
-	Isbn      string    `json:"isbn"`
-	BookType  BookType  `json:"book_type"`
-	Title     string    `json:"title"`
-	Year      int32     `json:"year"`
-	Available time.Time `json:"available"`
-	Tags      []string  `json:"tags"`
+	BookID    int32              `json:"book_id"`
+	AuthorID  int32              `json:"author_id"`
+	Isbn      string             `json:"isbn"`
+	BookType  BookType           `json:"book_type"`
+	Title     string             `json:"title"`
+	Year      int32              `json:"year"`
+	Available pgtype.Timestamptz `json:"available"`
+	Tags      []string           `json:"tags"`
 }
diff --git a/examples/batch/postgresql/querier.go b/examples/batch/postgresql/querier.go
index b103b84ee..cca7f5871 100644
--- a/examples/batch/postgresql/querier.go
+++ b/examples/batch/postgresql/querier.go
@@ -7,7 +7,7 @@ package batch
 import (
 	"context"
 
-	"github.com/jackc/pgconn"
+	"github.com/jackc/pgx/v5/pgconn"
 )
 
 type Querier interface {
diff --git a/examples/batch/postgresql/query.sql.go b/examples/batch/postgresql/query.sql.go
index f6a6a42b5..08b6ae4bf 100644
--- a/examples/batch/postgresql/query.sql.go
+++ b/examples/batch/postgresql/query.sql.go
@@ -8,7 +8,7 @@ package batch
 import (
 	"context"
 
-	"github.com/jackc/pgconn"
+	"github.com/jackc/pgx/v5/pgconn"
 )
 
 const createAuthor = `-- name: CreateAuthor :one
diff --git a/examples/batch/sqlc.json b/examples/batch/sqlc.json
index 32124f395..5b81b4078 100644
--- a/examples/batch/sqlc.json
+++ b/examples/batch/sqlc.json
@@ -19,7 +19,7 @@
       "rules": [
         "sqlc/db-prepare"
       ],
-      "sql_package": "pgx/v4",
+      "sql_package": "pgx/v5",
       "emit_json_tags": true,
       "emit_prepared_queries": true,
       "emit_interface": true
diff --git a/examples/jets/postgresql/db.go b/examples/jets/postgresql/db.go
index bee0af264..96af127ff 100644
--- a/examples/jets/postgresql/db.go
+++ b/examples/jets/postgresql/db.go
@@ -6,14 +6,15 @@ package jets
 
 import (
 	"context"
-	"database/sql"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
 )
 
 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
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
 }
 
 func New(db DBTX) *Queries {
@@ -24,7 +25,7 @@ type Queries struct {
 	db DBTX
 }
 
-func (q *Queries) WithTx(tx *sql.Tx) *Queries {
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
 	return &Queries{
 		db: tx,
 	}
diff --git a/examples/jets/postgresql/query-building.sql.go b/examples/jets/postgresql/query-building.sql.go
index 64db2dfdf..15e4900d5 100644
--- a/examples/jets/postgresql/query-building.sql.go
+++ b/examples/jets/postgresql/query-building.sql.go
@@ -14,7 +14,7 @@ SELECT COUNT(*) FROM pilots
 `
 
 func (q *Queries) CountPilots(ctx context.Context) (int64, error) {
-	row := q.db.QueryRowContext(ctx, countPilots)
+	row := q.db.QueryRow(ctx, countPilots)
 	var count int64
 	err := row.Scan(&count)
 	return count, err
@@ -25,7 +25,7 @@ DELETE FROM pilots WHERE id = $1
 `
 
 func (q *Queries) DeletePilot(ctx context.Context, id int32) error {
-	_, err := q.db.ExecContext(ctx, deletePilot, id)
+	_, err := q.db.Exec(ctx, deletePilot, id)
 	return err
 }
 
@@ -34,7 +34,7 @@ SELECT id, name FROM pilots LIMIT 5
 `
 
 func (q *Queries) ListPilots(ctx context.Context) ([]Pilot, error) {
-	rows, err := q.db.QueryContext(ctx, listPilots)
+	rows, err := q.db.Query(ctx, listPilots)
 	if err != nil {
 		return nil, err
 	}
@@ -47,9 +47,6 @@ func (q *Queries) ListPilots(ctx context.Context) ([]Pilot, error) {
 		}
 		items = append(items, i)
 	}
-	if err := rows.Close(); err != nil {
-		return nil, err
-	}
 	if err := rows.Err(); err != nil {
 		return nil, err
 	}
diff --git a/examples/jets/sqlc.json b/examples/jets/sqlc.json
index 14e80c429..d66496675 100644
--- a/examples/jets/sqlc.json
+++ b/examples/jets/sqlc.json
@@ -10,6 +10,7 @@
       "schema": "postgresql/schema.sql",
       "queries": "postgresql/query-building.sql",
       "engine": "postgresql",
+      "sql_package": "pgx/v5",
       "database": {
         "managed": true
       },
diff --git a/examples/ondeck/sqlc.json b/examples/ondeck/sqlc.json
index 0eed50f9d..2e94b30d9 100644
--- a/examples/ondeck/sqlc.json
+++ b/examples/ondeck/sqlc.json
@@ -10,6 +10,7 @@
       "schema": "postgresql/schema",
       "queries": "postgresql/query",
       "engine": "postgresql",
+      "sql_package": "database/sql",
       "database": {
         "managed": true
       },
@@ -56,4 +57,4 @@
       "emit_interface": true
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/go.mod b/go.mod
index 05edd4d2d..532b10ff9 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,6 @@ require (
 	github.com/go-sql-driver/mysql v1.7.1
 	github.com/google/cel-go v0.18.1
 	github.com/google/go-cmp v0.6.0
-	github.com/jackc/pgconn v1.14.1
 	github.com/jackc/pgx/v4 v4.18.1
 	github.com/jackc/pgx/v5 v5.4.3
 	github.com/jinzhu/inflection v1.0.0
@@ -22,19 +21,20 @@ require (
 	github.com/spf13/pflag v1.0.5
 	github.com/xeipuuv/gojsonschema v1.2.0
 	golang.org/x/sync v0.4.0
-	google.golang.org/grpc v1.58.3
+	google.golang.org/grpc v1.59.0
 	google.golang.org/protobuf v1.31.0
 	gopkg.in/yaml.v3 v3.0.1
 )
 
 require (
 	github.com/benbjohnson/clock v1.3.5 // indirect
+	github.com/jackc/pgconn v1.14.1 // indirect
 	github.com/jackc/puddle/v2 v2.2.1 // indirect
 	github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c // indirect
 	github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
 	github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
-	google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect
-	google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 // indirect
+	google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
+	google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
 )
 
 require (
@@ -47,7 +47,7 @@ require (
 	github.com/jackc/pgpassfile v1.0.0 // indirect
 	github.com/jackc/pgproto3/v2 v2.3.2 // indirect
 	github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
-	github.com/jackc/pgtype v1.14.0
+	github.com/jackc/pgtype v1.14.0 // indirect
 	github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
 	github.com/pingcap/log v1.1.0 // indirect
 	github.com/pingcap/tidb/parser v0.0.0-20231010133155-38cb4f3312be
diff --git a/go.sum b/go.sum
index f780baa8d..a5e0c2934 100644
--- a/go.sum
+++ b/go.sum
@@ -100,7 +100,6 @@ github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSlj
 github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
 github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
 github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
-github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
 github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
 github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
 github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
@@ -140,8 +139,6 @@ github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c h1:CgbKAHto5CQgW
 github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew=
 github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8=
 github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
-github.com/pingcap/tidb/parser v0.0.0-20230815160630-b69fa21942d1 h1:FvX5fDJ32eblK9f6KJIOVujjtu3FDEfcRGHsEDfJ4kI=
-github.com/pingcap/tidb/parser v0.0.0-20230815160630-b69fa21942d1/go.mod h1:pWA6mNa/o7UTDKrg+4H75NdpRgpWRTox/cqQjaQ4ZBU=
 github.com/pingcap/tidb/parser v0.0.0-20231010133155-38cb4f3312be h1:4HUBkIZs+4j+tbXGm5/B0yjB66OTz218HDKA6VrhO7U=
 github.com/pingcap/tidb/parser v0.0.0-20231010133155-38cb4f3312be/go.mod h1:cwq4bKUlftpWuznB+rqNwbN0xy6/i5SL/nYvEKeJn4s=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -300,12 +297,12 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 h1:nIgk/EEq3/YlnmVVXVnm14rC2oxgs1o0ong4sD/rd44=
-google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5/go.mod h1:5DZzOUPCLYL3mNkQ0ms0F3EuUNZ7py1Bqeq6sxzI7/Q=
-google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 h1:eSaPbMR4T7WfH9FvABk36NBMacoTUKdWCvV0dx+KfOg=
-google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5/go.mod h1:zBEcrKX2ZOcEkHWxBPAIvYUWOKKMIhYcmNiUIu2ji3I=
-google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ=
-google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
+google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q=
+google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
+google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
+google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
diff --git a/internal/cmd/shim.go b/internal/cmd/shim.go
index 4453d47a3..587c8bff6 100644
--- a/internal/cmd/shim.go
+++ b/internal/cmd/shim.go
@@ -209,13 +209,13 @@ func pluginQueries(r *compiler.Result) []*plugin.Query {
 			}
 		}
 		out = append(out, &plugin.Query{
-			Name:            q.Name,
-			Cmd:             q.Cmd,
+			Name:            q.Metadata.Name,
+			Cmd:             q.Metadata.Cmd,
 			Text:            q.SQL,
-			Comments:        q.Comments,
+			Comments:        q.Metadata.Comments,
 			Columns:         columns,
 			Params:          params,
-			Filename:        q.Filename,
+			Filename:        q.Metadata.Filename,
 			InsertIntoTable: iit,
 		})
 	}
diff --git a/internal/cmd/vet.go b/internal/cmd/vet.go
index 31aa3ec33..4f79fc8e8 100644
--- a/internal/cmd/vet.go
+++ b/internal/cmd/vet.go
@@ -545,7 +545,7 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
 	req := codeGenRequest(result, combo)
 	cfg := vetConfig(req)
 	for i, query := range req.Queries {
-		if result.Queries[i].Flags[QueryFlagSqlcVetDisable] {
+		if result.Queries[i].Metadata.Flags[QueryFlagSqlcVetDisable] {
 			if debug.Active {
 				log.Printf("Skipping vet rules for query: %s\n", query.Name)
 			}
diff --git a/internal/codegen/golang/gen.go b/internal/codegen/golang/gen.go
index c5f1956e0..ea3d8384c 100644
--- a/internal/codegen/golang/gen.go
+++ b/internal/codegen/golang/gen.go
@@ -345,6 +345,9 @@ func filterUnusedStructs(enums []Enum, structs []Struct, queries []Query) ([]Enu
 			if query.Ret.IsStruct() {
 				for _, field := range query.Ret.Struct.Fields {
 					keepTypes[field.Type] = struct{}{}
+					for _, embedField := range field.EmbedFields {
+						keepTypes[embedField.Type] = struct{}{}
+					}
 				}
 			}
 		}
diff --git a/internal/compiler/analyze.go b/internal/compiler/analyze.go
index 739cd0799..584042f97 100644
--- a/internal/compiler/analyze.go
+++ b/internal/compiler/analyze.go
@@ -58,6 +58,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
 	if len(prev.Columns) == len(cols) {
 		for i := range prev.Columns {
 			prev.Columns[i].DataType = cols[i].DataType
+			prev.Columns[i].IsArray = cols[i].IsArray
+			prev.Columns[i].ArrayDims = cols[i].ArrayDims
 		}
 	} else {
 		embedding := false
@@ -73,6 +75,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
 	if len(prev.Parameters) == len(params) {
 		for i := range prev.Parameters {
 			prev.Parameters[i].Column.DataType = params[i].Column.DataType
+			prev.Parameters[i].Column.IsArray = params[i].Column.IsArray
+			prev.Parameters[i].Column.ArrayDims = params[i].Column.ArrayDims
 		}
 	} else {
 		prev.Parameters = params
diff --git a/internal/compiler/compile.go b/internal/compiler/compile.go
index a6744fc6d..9f4a5170e 100644
--- a/internal/compiler/compile.go
+++ b/internal/compiler/compile.go
@@ -8,10 +8,10 @@ import (
 	"path/filepath"
 	"strings"
 
-	"github.com/sqlc-dev/sqlc/internal/metadata"
 	"github.com/sqlc-dev/sqlc/internal/migrations"
 	"github.com/sqlc-dev/sqlc/internal/multierr"
 	"github.com/sqlc-dev/sqlc/internal/opts"
+	"github.com/sqlc-dev/sqlc/internal/source"
 	"github.com/sqlc-dev/sqlc/internal/sql/ast"
 	"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
 	"github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
@@ -20,7 +20,7 @@ import (
 // TODO: Rename this interface Engine
 type Parser interface {
 	Parse(io.Reader) ([]ast.Statement, error)
-	CommentSyntax() metadata.CommentSyntax
+	CommentSyntax() source.CommentSyntax
 	IsReservedKeyword(string) bool
 }
 
@@ -90,14 +90,15 @@ func (c *Compiler) parseQueries(o opts.Parser) (*Result, error) {
 				merr.Add(filename, src, loc, err)
 				continue
 			}
-			if query.Name != "" {
-				if _, exists := set[query.Name]; exists {
-					merr.Add(filename, src, stmt.Raw.Pos(), fmt.Errorf("duplicate query name: %s", query.Name))
+			queryName := query.Metadata.Name
+			if queryName != "" {
+				if _, exists := set[queryName]; exists {
+					merr.Add(filename, src, stmt.Raw.Pos(), fmt.Errorf("duplicate query name: %s", queryName))
 					continue
 				}
-				set[query.Name] = struct{}{}
+				set[queryName] = struct{}{}
 			}
-			query.Filename = filepath.Base(filename)
+			query.Metadata.Filename = filepath.Base(filename)
 			if query != nil {
 				q = append(q, query)
 			}
diff --git a/internal/compiler/output_columns.go b/internal/compiler/output_columns.go
index 6ced89ae2..49b166137 100644
--- a/internal/compiler/output_columns.go
+++ b/internal/compiler/output_columns.go
@@ -403,7 +403,8 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
 				continue
 			}
 			for _, f := range n.FromClause.Items {
-				if res := isTableRequired(f, col, tableRequired); res != tableNotFound {
+				res := isTableRequired(f, col, tableRequired)
+				if res != tableNotFound {
 					col.NotNull = res == tableRequired
 					break
 				}
@@ -423,10 +424,12 @@ const (
 func isTableRequired(n ast.Node, col *Column, prior int) int {
 	switch n := n.(type) {
 	case *ast.RangeVar:
-		if n.Alias == nil && *n.Relname == col.Table.Name {
-			return prior
+		tableMatch := *n.Relname == col.Table.Name
+		aliasMatch := true
+		if n.Alias != nil && col.TableAlias != "" {
+			aliasMatch = *n.Alias.Aliasname == col.TableAlias
 		}
-		if n.Alias != nil && *n.Alias.Aliasname == col.TableAlias && *n.Relname == col.Table.Name {
+		if aliasMatch && tableMatch {
 			return prior
 		}
 	case *ast.JoinExpr:
@@ -550,12 +553,15 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
 			if err != nil {
 				continue
 			}
-			table, err := qc.GetTable(&ast.TableName{
-				Catalog: fn.ReturnType.Catalog,
-				Schema:  fn.ReturnType.Schema,
-				Name:    fn.ReturnType.Name,
-			})
-			if err != nil {
+			var table *Table
+			if fn.ReturnType != nil {
+				table, err = qc.GetTable(&ast.TableName{
+					Catalog: fn.ReturnType.Catalog,
+					Schema:  fn.ReturnType.Schema,
+					Name:    fn.ReturnType.Name,
+				})
+			}
+			if table == nil || err != nil {
 				if n.Alias != nil && len(n.Alias.Colnames.Items) > 0 {
 					table = &Table{}
 					for _, colName := range n.Alias.Colnames.Items {
@@ -575,12 +581,22 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
 							Schema:  fn.Rel.Schema,
 							Name:    fn.Rel.Name,
 						},
-						Columns: []*Column{
+					}
+					if len(fn.Outs) > 0 {
+						for _, arg := range fn.Outs {
+							table.Columns = append(table.Columns, &Column{
+								Name:     arg.Name,
+								DataType: arg.Type.Name,
+							})
+						}
+					}
+					if fn.ReturnType != nil {
+						table.Columns = []*Column{
 							{
 								Name:     colName,
 								DataType: fn.ReturnType.Name,
 							},
-						},
+						}
 					}
 				}
 			}
@@ -660,13 +676,13 @@ func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef)
 			continue
 		}
 		for _, c := range t.Columns {
+
 			if c.Name == name {
 				found += 1
 				cname := c.Name
 				if res.Name != nil {
 					cname = *res.Name
 				}
-
 				cols = append(cols, &Column{
 					Name:         cname,
 					Type:         c.Type,
diff --git a/internal/compiler/parse.go b/internal/compiler/parse.go
index 53e3043c7..0b626e108 100644
--- a/internal/compiler/parse.go
+++ b/internal/compiler/parse.go
@@ -43,14 +43,31 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
 		return nil, errors.New("missing semicolon at end of file")
 	}
 
-	name, cmd, err := metadata.ParseQueryNameAndType(strings.TrimSpace(rawSQL), c.parser.CommentSyntax())
+	name, cmd, err := metadata.ParseQueryNameAndType(rawSQL, metadata.CommentSyntax(c.parser.CommentSyntax()))
 	if err != nil {
 		return nil, err
 	}
+
 	if err := validate.Cmd(raw.Stmt, name, cmd); err != nil {
 		return nil, err
 	}
 
+	md := metadata.Metadata{
+		Name: name,
+		Cmd:  cmd,
+	}
+
+	// TODO eventually can use this for name and type/cmd parsing too
+	cleanedComments, err := source.CleanedComments(rawSQL, c.parser.CommentSyntax())
+	if err != nil {
+		return nil, err
+	}
+
+	md.Params, md.Flags, err = metadata.ParseParamsAndFlags(cleanedComments)
+	if err != nil {
+		return nil, err
+	}
+
 	var anlys *analysis
 	if c.analyzer != nil {
 		// TODO: Handle panics
@@ -90,17 +107,11 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
 		return nil, err
 	}
 
-	flags, err := metadata.ParseQueryFlags(comments)
-	if err != nil {
-		return nil, err
-	}
+	md.Comments = comments
 
 	return &Query{
 		RawStmt:         raw,
-		Cmd:             cmd,
-		Comments:        comments,
-		Name:            name,
-		Flags:           flags,
+		Metadata:        md,
 		Params:          anlys.Parameters,
 		Columns:         anlys.Columns,
 		SQL:             trimmed,
diff --git a/internal/compiler/query.go b/internal/compiler/query.go
index 117cf4481..b3cf9d615 100644
--- a/internal/compiler/query.go
+++ b/internal/compiler/query.go
@@ -1,12 +1,15 @@
 package compiler
 
 import (
+	"github.com/sqlc-dev/sqlc/internal/metadata"
 	"github.com/sqlc-dev/sqlc/internal/sql/ast"
+	"github.com/sqlc-dev/sqlc/internal/sql/catalog"
 )
 
 type Function struct {
 	Rel        *ast.FuncName
 	ReturnType *ast.TypeName
+	Outs       []*catalog.Argument
 }
 
 type Table struct {
@@ -41,15 +44,9 @@ type Column struct {
 
 type Query struct {
 	SQL      string
-	Name     string
-	Cmd      string // TODO: Pick a better name. One of: one, many, exec, execrows, copyFrom
-	Flags    map[string]bool
+	Metadata metadata.Metadata
 	Columns  []*Column
 	Params   []Parameter
-	Comments []string
-
-	// XXX: Hack
-	Filename string
 
 	// Needed for CopyFrom
 	InsertIntoTable *ast.TableName
diff --git a/internal/compiler/query_catalog.go b/internal/compiler/query_catalog.go
index 42088446d..80b59d876 100644
--- a/internal/compiler/query_catalog.go
+++ b/internal/compiler/query_catalog.go
@@ -103,6 +103,7 @@ func (qc QueryCatalog) GetFunc(rel *ast.FuncName) (*Function, error) {
 	}
 	return &Function{
 		Rel:        rel,
+		Outs:       funcs[0].OutArgs(),
 		ReturnType: funcs[0].ReturnType,
 	}, nil
 }
diff --git a/internal/engine/dolphin/parse.go b/internal/engine/dolphin/parse.go
index 676362c44..22d3a1d22 100644
--- a/internal/engine/dolphin/parse.go
+++ b/internal/engine/dolphin/parse.go
@@ -10,7 +10,7 @@ import (
 	"github.com/pingcap/tidb/parser"
 	_ "github.com/pingcap/tidb/parser/test_driver"
 
-	"github.com/sqlc-dev/sqlc/internal/metadata"
+	"github.com/sqlc-dev/sqlc/internal/source"
 	"github.com/sqlc-dev/sqlc/internal/sql/ast"
 	"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
 )
@@ -86,8 +86,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
 }
 
 // https://dev.mysql.com/doc/refman/8.0/en/comments.html
-func (p *Parser) CommentSyntax() metadata.CommentSyntax {
-	return metadata.CommentSyntax{
+func (p *Parser) CommentSyntax() source.CommentSyntax {
+	return source.CommentSyntax{
 		Dash:      true,
 		SlashStar: true,
 		Hash:      true,
diff --git a/internal/engine/postgresql/analyzer/analyze.go b/internal/engine/postgresql/analyzer/analyze.go
index ab34eb348..fe07b840e 100644
--- a/internal/engine/postgresql/analyzer/analyze.go
+++ b/internal/engine/postgresql/analyzer/analyze.go
@@ -101,7 +101,7 @@ func (a *Analyzer) columnInfo(ctx context.Context, field pgconn.FieldDescription
 	if ok {
 		return cinfo.(*pgColumn), nil
 	}
-	rows, err := a.pool.Query(ctx, columnQuery, field.TableOID, field.TableAttributeNumber)
+	rows, err := a.pool.Query(ctx, columnQuery, field.TableOID, int16(field.TableAttributeNumber))
 	if err != nil {
 		return nil, err
 	}
diff --git a/internal/engine/postgresql/parse.go b/internal/engine/postgresql/parse.go
index 49ec98148..296a14e85 100644
--- a/internal/engine/postgresql/parse.go
+++ b/internal/engine/postgresql/parse.go
@@ -12,7 +12,7 @@ import (
 	nodes "github.com/pganalyze/pg_query_go/v4"
 	"github.com/pganalyze/pg_query_go/v4/parser"
 
-	"github.com/sqlc-dev/sqlc/internal/metadata"
+	"github.com/sqlc-dev/sqlc/internal/source"
 	"github.com/sqlc-dev/sqlc/internal/sql/ast"
 	"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
 )
@@ -199,8 +199,8 @@ func normalizeErr(err error) error {
 }
 
 // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-COMMENTS
-func (p *Parser) CommentSyntax() metadata.CommentSyntax {
-	return metadata.CommentSyntax{
+func (p *Parser) CommentSyntax() source.CommentSyntax {
+	return source.CommentSyntax{
 		Dash:      true,
 		SlashStar: true,
 	}
diff --git a/internal/engine/postgresql/parse_disabled.go b/internal/engine/postgresql/parse_disabled.go
index ecc5158d4..b07817b43 100644
--- a/internal/engine/postgresql/parse_disabled.go
+++ b/internal/engine/postgresql/parse_disabled.go
@@ -8,7 +8,7 @@ import (
 	"io"
 	"runtime"
 
-	"github.com/sqlc-dev/sqlc/internal/metadata"
+	"github.com/sqlc-dev/sqlc/internal/source"
 	"github.com/sqlc-dev/sqlc/internal/sql/ast"
 )
 
@@ -27,8 +27,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
 }
 
 // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-COMMENTS
-func (p *Parser) CommentSyntax() metadata.CommentSyntax {
-	return metadata.CommentSyntax{
+func (p *Parser) CommentSyntax() source.CommentSyntax {
+	return source.CommentSyntax{
 		Dash:      true,
 		SlashStar: true,
 	}
diff --git a/internal/engine/sqlite/parse.go b/internal/engine/sqlite/parse.go
index bf0bacad9..56005dd2e 100644
--- a/internal/engine/sqlite/parse.go
+++ b/internal/engine/sqlite/parse.go
@@ -8,7 +8,7 @@ import (
 	"github.com/antlr/antlr4/runtime/Go/antlr/v4"
 
 	"github.com/sqlc-dev/sqlc/internal/engine/sqlite/parser"
-	"github.com/sqlc-dev/sqlc/internal/metadata"
+	"github.com/sqlc-dev/sqlc/internal/source"
 	"github.com/sqlc-dev/sqlc/internal/sql/ast"
 )
 
@@ -86,8 +86,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
 	return stmts, nil
 }
 
-func (p *Parser) CommentSyntax() metadata.CommentSyntax {
-	return metadata.CommentSyntax{
+func (p *Parser) CommentSyntax() source.CommentSyntax {
+	return source.CommentSyntax{
 		Dash:      true,
 		Hash:      false,
 		SlashStar: true,
diff --git a/internal/metadata/meta.go b/internal/metadata/meta.go
index 4176da1e2..97ff36dbd 100644
--- a/internal/metadata/meta.go
+++ b/internal/metadata/meta.go
@@ -1,15 +1,24 @@
 package metadata
 
 import (
+	"bufio"
 	"fmt"
 	"strings"
 	"unicode"
+
+	"github.com/sqlc-dev/sqlc/internal/source"
 )
 
-type CommentSyntax struct {
-	Dash      bool
-	Hash      bool
-	SlashStar bool
+type CommentSyntax source.CommentSyntax
+
+type Metadata struct {
+	Name     string
+	Cmd      string
+	Comments []string
+	Params   map[string]string
+	Flags    map[string]bool
+
+	Filename string
 }
 
 const (
@@ -83,7 +92,7 @@ func ParseQueryNameAndType(t string, commentStyle CommentSyntax) (string, string
 		if prefix == "/*" {
 			part = part[:len(part)-1] // removes the trailing "*/" element
 		}
-		if len(part) == 2 {
+		if len(part) == 3 {
 			return "", "", fmt.Errorf("missing query type [':one', ':many', ':exec', ':execrows', ':execlastid', ':execresult', ':copyfrom', 'batchexec', 'batchmany', 'batchone']: %s", line)
 		}
 		if len(part) != 4 {
@@ -104,19 +113,39 @@ func ParseQueryNameAndType(t string, commentStyle CommentSyntax) (string, string
 	return "", "", nil
 }
 
-func ParseQueryFlags(comments []string) (map[string]bool, error) {
+func ParseParamsAndFlags(comments []string) (map[string]string, map[string]bool, error) {
+	params := make(map[string]string)
 	flags := make(map[string]bool)
+
 	for _, line := range comments {
-		cleanLine := strings.TrimPrefix(line, "--")
-		cleanLine = strings.TrimPrefix(cleanLine, "/*")
-		cleanLine = strings.TrimPrefix(cleanLine, "#")
-		cleanLine = strings.TrimSuffix(cleanLine, "*/")
-		cleanLine = strings.TrimSpace(cleanLine)
-		if strings.HasPrefix(cleanLine, "@") {
-			flagName := strings.SplitN(cleanLine, " ", 2)[0]
-			flags[flagName] = true
+		s := bufio.NewScanner(strings.NewReader(line))
+		s.Split(bufio.ScanWords)
+
+		s.Scan()
+		token := s.Text()
+
+		if !strings.HasPrefix(token, "@") {
 			continue
 		}
+
+		switch token {
+		case "@param":
+			s.Scan()
+			name := s.Text()
+			var rest []string
+			for s.Scan() {
+				paramToken := s.Text()
+				rest = append(rest, paramToken)
+			}
+			params[name] = strings.Join(rest, " ")
+		default:
+			flags[token] = true
+		}
+
+		if s.Err() != nil {
+			return params, flags, s.Err()
+		}
 	}
-	return flags, nil
+
+	return params, flags, nil
 }
diff --git a/internal/source/code.go b/internal/source/code.go
index f34e3e368..8b88a2413 100644
--- a/internal/source/code.go
+++ b/internal/source/code.go
@@ -15,6 +15,12 @@ type Edit struct {
 	OldFunc  func(string) int
 }
 
+type CommentSyntax struct {
+	Dash      bool
+	Hash      bool
+	SlashStar bool
+}
+
 func LineNumber(source string, head int) (int, int) {
 	// Calculate the true line and column number for a query, ignoring spaces
 	var comment bool
@@ -101,6 +107,9 @@ func StripComments(sql string) (string, []string, error) {
 		if strings.HasPrefix(t, "/* name:") && strings.HasSuffix(t, "*/") {
 			continue
 		}
+		if strings.HasPrefix(t, "# name:") {
+			continue
+		}
 		if strings.HasPrefix(t, "--") {
 			comments = append(comments, strings.TrimPrefix(t, "--"))
 			continue
@@ -111,7 +120,46 @@ func StripComments(sql string) (string, []string, error) {
 			comments = append(comments, t)
 			continue
 		}
+		if strings.HasPrefix(t, "#") {
+			comments = append(comments, strings.TrimPrefix(t, "#"))
+			continue
+		}
 		lines = append(lines, t)
 	}
 	return strings.Join(lines, "\n"), comments, s.Err()
 }
+
+func CleanedComments(rawSQL string, cs CommentSyntax) ([]string, error) {
+	s := bufio.NewScanner(strings.NewReader(strings.TrimSpace(rawSQL)))
+	var comments []string
+	for s.Scan() {
+		line := s.Text()
+		var prefix string
+		if strings.HasPrefix(line, "--") {
+			if !cs.Dash {
+				continue
+			}
+			prefix = "--"
+		}
+		if strings.HasPrefix(line, "/*") {
+			if !cs.SlashStar {
+				continue
+			}
+			prefix = "/*"
+		}
+		if strings.HasPrefix(line, "#") {
+			if !cs.Hash {
+				continue
+			}
+			prefix = "#"
+		}
+		if prefix == "" {
+			continue
+		}
+
+		rest := line[len(prefix):]
+		rest = strings.TrimSuffix(rest, "*/")
+		comments = append(comments, rest)
+	}
+	return comments, s.Err()
+}
diff --git a/internal/sql/catalog/func.go b/internal/sql/catalog/func.go
index 7cc712492..e17077731 100644
--- a/internal/sql/catalog/func.go
+++ b/internal/sql/catalog/func.go
@@ -39,6 +39,17 @@ func (f *Function) InArgs() []*Argument {
 	return args
 }
 
+func (f *Function) OutArgs() []*Argument {
+	var args []*Argument
+	for _, a := range f.Args {
+		switch a.Mode {
+		case ast.FuncParamOut:
+			args = append(args, a)
+		}
+	}
+	return args
+}
+
 func (c *Catalog) createFunction(stmt *ast.CreateFunctionStmt) error {
 	ns := stmt.Func.Schema
 	if ns == "" {


Test patch:
diff --git a/examples/authors/postgresql/db_test.go b/examples/authors/postgresql/db_test.go
index d2df436ae..bdcd90a54 100644
--- a/examples/authors/postgresql/db_test.go
+++ b/examples/authors/postgresql/db_test.go
@@ -5,23 +5,23 @@ package authors
 
 import (
 	"context"
-	"database/sql"
 	"testing"
 
-	_ "github.com/lib/pq"
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgtype"
 
 	"github.com/sqlc-dev/sqlc/internal/sqltest/hosted"
 )
 
 func TestAuthors(t *testing.T) {
+	ctx := context.Background()
 	uri := hosted.PostgreSQL(t, []string{"schema.sql"})
-	db, err := sql.Open("postgres", uri)
+	db, err := pgx.Connect(ctx, uri)
 	if err != nil {
 		t.Fatal(err)
 	}
-	defer db.Close()
+	defer db.Close(ctx)
 
-	ctx := context.Background()
 	q := New(db)
 
 	// list all authors
@@ -34,7 +34,7 @@ func TestAuthors(t *testing.T) {
 	// create an author
 	insertedAuthor, err := q.CreateAuthor(ctx, CreateAuthorParams{
 		Name: "Brian Kernighan",
-		Bio:  sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true},
+		Bio:  pgtype.Text{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true},
 	})
 	if err != nil {
 		t.Fatal(err)
diff --git a/examples/batch/postgresql/db_test.go b/examples/batch/postgresql/db_test.go
index fd3ce4e72..c39bd0b5e 100644
--- a/examples/batch/postgresql/db_test.go
+++ b/examples/batch/postgresql/db_test.go
@@ -8,7 +8,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/jackc/pgx/v4"
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgtype"
 	"github.com/sqlc-dev/sqlc/internal/sqltest/hosted"
 )
 
@@ -31,7 +32,7 @@ func TestBatchBooks(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	now := time.Now()
+	now := pgtype.Timestamptz{Time: time.Now(), Valid: true}
 
 	// batch insert new books
 	newBooksParams := []CreateBookParams{
@@ -114,7 +115,7 @@ func TestBatchBooks(t *testing.T) {
 	})
 
 	for _, book := range books0 {
-		t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Format(time.RFC822Z))
+		t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Time.Format(time.RFC822Z))
 		author, err := dq.GetAuthor(ctx, book.AuthorID)
 		if err != nil {
 			t.Fatal(err)
diff --git a/examples/booktest/postgresql/db.go b/examples/booktest/postgresql/db.go
index 301436443..34e435ebe 100644
--- a/examples/booktest/postgresql/db.go
+++ b/examples/booktest/postgresql/db.go
@@ -6,14 +6,15 @@ package booktest
 
 import (
 	"context"
-	"database/sql"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
 )
 
 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
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
 }
 
 func New(db DBTX) *Queries {
@@ -24,7 +25,7 @@ type Queries struct {
 	db DBTX
 }
 
-func (q *Queries) WithTx(tx *sql.Tx) *Queries {
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
 	return &Queries{
 		db: tx,
 	}
diff --git a/examples/booktest/postgresql/db_test.go b/examples/booktest/postgresql/db_test.go
index 9716f5684..8eeb10518 100644
--- a/examples/booktest/postgresql/db_test.go
+++ b/examples/booktest/postgresql/db_test.go
@@ -5,24 +5,24 @@ package booktest
 
 import (
 	"context"
-	"database/sql"
 	"testing"
 	"time"
 
-	_ "github.com/lib/pq"
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgtype"
 
 	"github.com/sqlc-dev/sqlc/internal/sqltest/hosted"
 )
 
 func TestBooks(t *testing.T) {
+	ctx := context.Background()
 	uri := hosted.PostgreSQL(t, []string{"schema.sql"})
-	db, err := sql.Open("postgres", uri)
+	db, err := pgx.Connect(ctx, uri)
 	if err != nil {
 		t.Fatal(err)
 	}
-	defer db.Close()
+	defer db.Close(ctx)
 
-	ctx := context.Background()
 	dq := New(db)
 
 	// create an author
@@ -32,7 +32,7 @@ func TestBooks(t *testing.T) {
 	}
 
 	// create transaction
-	tx, err := db.Begin()
+	tx, err := db.Begin(ctx)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -40,7 +40,7 @@ func TestBooks(t *testing.T) {
 	tq := dq.WithTx(tx)
 
 	// save first book
-	now := time.Now()
+	now := pgtype.Timestamptz{Time: time.Now(), Valid: true}
 	_, err = tq.CreateBook(ctx, CreateBookParams{
 		AuthorID:  a.AuthorID,
 		Isbn:      "1",
@@ -107,7 +107,7 @@ func TestBooks(t *testing.T) {
 	}
 
 	// tx commit
-	err = tx.Commit()
+	err = tx.Commit(ctx)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -132,7 +132,7 @@ func TestBooks(t *testing.T) {
 		t.Fatal(err)
 	}
 	for _, book := range books0 {
-		t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Format(time.RFC822Z))
+		t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Time.Format(time.RFC822Z))
 		author, err := dq.GetAuthor(ctx, book.AuthorID)
 		if err != nil {
 			t.Fatal(err)
diff --git a/examples/booktest/postgresql/models.go b/examples/booktest/postgresql/models.go
index 3bfe237f7..d5b27acee 100644
--- a/examples/booktest/postgresql/models.go
+++ b/examples/booktest/postgresql/models.go
@@ -7,7 +7,8 @@ package booktest
 import (
 	"database/sql/driver"
 	"fmt"
-	"time"
+
+	"github.com/jackc/pgx/v5/pgtype"
 )
 
 type BookType string
@@ -64,6 +65,6 @@ type Book struct {
 	BookType  BookType
 	Title     string
 	Year      int32
-	Available time.Time
+	Available pgtype.Timestamptz
 	Tags      []string
 }
diff --git a/examples/booktest/postgresql/query.sql.go b/examples/booktest/postgresql/query.sql.go
index 34e55ad96..9cc621bee 100644
--- a/examples/booktest/postgresql/query.sql.go
+++ b/examples/booktest/postgresql/query.sql.go
@@ -7,10 +7,8 @@ package booktest
 
 import (
 	"context"
-	"database/sql"
-	"time"
 
-	"github.com/lib/pq"
+	"github.com/jackc/pgx/v5/pgtype"
 )
 
 const booksByTags = `-- name: BooksByTags :many
@@ -28,13 +26,13 @@ WHERE tags && $1::varchar[]
 type BooksByTagsRow struct {
 	BookID int32
 	Title  string
-	Name   sql.NullString
+	Name   pgtype.Text
 	Isbn   string
 	Tags   []string
 }
 
 func (q *Queries) BooksByTags(ctx context.Context, dollar_1 []string) ([]BooksByTagsRow, error) {
-	rows, err := q.db.QueryContext(ctx, booksByTags, pq.Array(dollar_1))
+	rows, err := q.db.Query(ctx, booksByTags, dollar_1)
 	if err != nil {
 		return nil, err
 	}
@@ -47,15 +45,12 @@ func (q *Queries) BooksByTags(ctx context.Context, dollar_1 []string) ([]BooksBy
 			&i.Title,
 			&i.Name,
 			&i.Isbn,
-			pq.Array(&i.Tags),
+			&i.Tags,
 		); 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
 	}
@@ -73,7 +68,7 @@ type BooksByTitleYearParams struct {
 }
 
 func (q *Queries) BooksByTitleYear(ctx context.Context, arg BooksByTitleYearParams) ([]Book, error) {
-	rows, err := q.db.QueryContext(ctx, booksByTitleYear, arg.Title, arg.Year)
+	rows, err := q.db.Query(ctx, booksByTitleYear, arg.Title, arg.Year)
 	if err != nil {
 		return nil, err
 	}
@@ -89,15 +84,12 @@ func (q *Queries) BooksByTitleYear(ctx context.Context, arg BooksByTitleYearPara
 			&i.Title,
 			&i.Year,
 			&i.Available,
-			pq.Array(&i.Tags),
+			&i.Tags,
 		); 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
 	}
@@ -110,7 +102,7 @@ RETURNING author_id, name
 `
 
 func (q *Queries) CreateAuthor(ctx context.Context, name string) (Author, error) {
-	row := q.db.QueryRowContext(ctx, createAuthor, name)
+	row := q.db.QueryRow(ctx, createAuthor, name)
 	var i Author
 	err := row.Scan(&i.AuthorID, &i.Name)
 	return i, err
@@ -143,19 +135,19 @@ type CreateBookParams struct {
 	BookType  BookType
 	Title     string
 	Year      int32
-	Available time.Time
+	Available pgtype.Timestamptz
 	Tags      []string
 }
 
 func (q *Queries) CreateBook(ctx context.Context, arg CreateBookParams) (Book, error) {
-	row := q.db.QueryRowContext(ctx, createBook,
+	row := q.db.QueryRow(ctx, createBook,
 		arg.AuthorID,
 		arg.Isbn,
 		arg.BookType,
 		arg.Title,
 		arg.Year,
 		arg.Available,
-		pq.Array(arg.Tags),
+		arg.Tags,
 	)
 	var i Book
 	err := row.Scan(
@@ -166,7 +158,7 @@ func (q *Queries) CreateBook(ctx context.Context, arg CreateBookParams) (Book, e
 		&i.Title,
 		&i.Year,
 		&i.Available,
-		pq.Array(&i.Tags),
+		&i.Tags,
 	)
 	return i, err
 }
@@ -177,7 +169,7 @@ WHERE book_id = $1
 `
 
 func (q *Queries) DeleteBook(ctx context.Context, bookID int32) error {
-	_, err := q.db.ExecContext(ctx, deleteBook, bookID)
+	_, err := q.db.Exec(ctx, deleteBook, bookID)
 	return err
 }
 
@@ -187,7 +179,7 @@ WHERE author_id = $1
 `
 
 func (q *Queries) GetAuthor(ctx context.Context, authorID int32) (Author, error) {
-	row := q.db.QueryRowContext(ctx, getAuthor, authorID)
+	row := q.db.QueryRow(ctx, getAuthor, authorID)
 	var i Author
 	err := row.Scan(&i.AuthorID, &i.Name)
 	return i, err
@@ -199,7 +191,7 @@ WHERE book_id = $1
 `
 
 func (q *Queries) GetBook(ctx context.Context, bookID int32) (Book, error) {
-	row := q.db.QueryRowContext(ctx, getBook, bookID)
+	row := q.db.QueryRow(ctx, getBook, bookID)
 	var i Book
 	err := row.Scan(
 		&i.BookID,
@@ -209,7 +201,7 @@ func (q *Queries) GetBook(ctx context.Context, bookID int32) (Book, error) {
 		&i.Title,
 		&i.Year,
 		&i.Available,
-		pq.Array(&i.Tags),
+		&i.Tags,
 	)
 	return i, err
 }
@@ -227,7 +219,7 @@ type UpdateBookParams struct {
 }
 
 func (q *Queries) UpdateBook(ctx context.Context, arg UpdateBookParams) error {
-	_, err := q.db.ExecContext(ctx, updateBook, arg.Title, pq.Array(arg.Tags), arg.BookID)
+	_, err := q.db.Exec(ctx, updateBook, arg.Title, arg.Tags, arg.BookID)
 	return err
 }
 
@@ -245,9 +237,9 @@ type UpdateBookISBNParams struct {
 }
 
 func (q *Queries) UpdateBookISBN(ctx context.Context, arg UpdateBookISBNParams) error {
-	_, err := q.db.ExecContext(ctx, updateBookISBN,
+	_, err := q.db.Exec(ctx, updateBookISBN,
 		arg.Title,
-		pq.Array(arg.Tags),
+		arg.Tags,
 		arg.BookID,
 		arg.Isbn,
 	)
diff --git a/examples/booktest/sqlc.json b/examples/booktest/sqlc.json
index b1453a2e3..8f5ddad6e 100644
--- a/examples/booktest/sqlc.json
+++ b/examples/booktest/sqlc.json
@@ -10,6 +10,7 @@
       "schema": "postgresql/schema.sql",
       "queries": "postgresql/query.sql",
       "engine": "postgresql",
+      "sql_package": "pgx/v5",
       "database": {
         "managed": true
       },
@@ -47,4 +48,4 @@
       ]
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/internal/endtoend/testdata/column_alias/issue.md b/internal/endtoend/testdata/column_alias/issue.md
new file mode 100644
index 000000000..fc16c2a58
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1739
diff --git a/internal/endtoend/testdata/column_alias/stdlib/exec.json b/internal/endtoend/testdata/column_alias/stdlib/exec.json
new file mode 100644
index 000000000..e5dfda781
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/stdlib/exec.json
@@ -0,0 +1,3 @@
+{
+    "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/column_alias/stdlib/go/db.go b/internal/endtoend/testdata/column_alias/stdlib/go/db.go
new file mode 100644
index 000000000..a457fb76b
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/stdlib/go/db.go
@@ -0,0 +1,31 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+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,
+	}
+}
diff --git a/internal/endtoend/testdata/column_alias/stdlib/go/models.go b/internal/endtoend/testdata/column_alias/stdlib/go/models.go
new file mode 100644
index 000000000..e8547ba6c
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/stdlib/go/models.go
@@ -0,0 +1,18 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"time"
+)
+
+type User struct {
+	ID        int32
+	Fname     string
+	Lname     string
+	Email     string
+	EncPasswd string
+	CreatedAt time.Time
+}
diff --git a/internal/endtoend/testdata/column_alias/stdlib/go/query.sql.go b/internal/endtoend/testdata/column_alias/stdlib/go/query.sql.go
new file mode 100644
index 000000000..71fdbdbff
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/stdlib/go/query.sql.go
@@ -0,0 +1,80 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+	"database/sql"
+	"time"
+)
+
+const getUsers = `-- name: GetUsers :many
+SELECT 
+    users.id,
+    users.fname,
+    users.lname,
+    users.email,
+    users.created_at,
+    rank_email,
+    rank_fname,
+    rank_lname,
+    similarity
+FROM 
+    users, 
+    to_tsvector(users.email || users.fname || users.lname) document,
+    to_tsquery($1::TEXT) query,
+    NULLIF(ts_rank(to_tsvector(users.email), query), 0) rank_email,
+    NULLIF(ts_rank(to_tsvector(users.fname), query), 0) rank_fname,
+    NULLIF(ts_rank(to_tsvector(users.lname), query), 0) rank_lname,
+    SIMILARITY($1::TEXT, users.email || users.fname || users.lname) similarity
+WHERE query @@ document OR similarity > 0
+ORDER BY rank_email, rank_lname, rank_fname, similarity DESC NULLS LAST
+`
+
+type GetUsersRow struct {
+	ID         int32
+	Fname      string
+	Lname      string
+	Email      string
+	CreatedAt  time.Time
+	RankEmail  sql.NullFloat64
+	RankFname  sql.NullFloat64
+	RankLname  sql.NullFloat64
+	Similarity sql.NullFloat64
+}
+
+func (q *Queries) GetUsers(ctx context.Context, searchTerm string) ([]GetUsersRow, error) {
+	rows, err := q.db.QueryContext(ctx, getUsers, searchTerm)
+	if err != nil {
+		return nil, err
+	}
+	defer rows.Close()
+	var items []GetUsersRow
+	for rows.Next() {
+		var i GetUsersRow
+		if err := rows.Scan(
+			&i.ID,
+			&i.Fname,
+			&i.Lname,
+			&i.Email,
+			&i.CreatedAt,
+			&i.RankEmail,
+			&i.RankFname,
+			&i.RankLname,
+			&i.Similarity,
+		); 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
+}
diff --git a/internal/endtoend/testdata/column_alias/stdlib/query.sql b/internal/endtoend/testdata/column_alias/stdlib/query.sql
new file mode 100644
index 000000000..9877fadde
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/stdlib/query.sql
@@ -0,0 +1,21 @@
+-- name: GetUsers :many
+SELECT 
+    users.id,
+    users.fname,
+    users.lname,
+    users.email,
+    users.created_at,
+    rank_email,
+    rank_fname,
+    rank_lname,
+    similarity
+FROM 
+    users, 
+    to_tsvector(users.email || users.fname || users.lname) document,
+    to_tsquery(@search_term::TEXT) query,
+    NULLIF(ts_rank(to_tsvector(users.email), query), 0) rank_email,
+    NULLIF(ts_rank(to_tsvector(users.fname), query), 0) rank_fname,
+    NULLIF(ts_rank(to_tsvector(users.lname), query), 0) rank_lname,
+    SIMILARITY(@search_term::TEXT, users.email || users.fname || users.lname) similarity
+WHERE query @@ document OR similarity > 0
+ORDER BY rank_email, rank_lname, rank_fname, similarity DESC NULLS LAST;
diff --git a/internal/endtoend/testdata/column_alias/stdlib/schema.sql b/internal/endtoend/testdata/column_alias/stdlib/schema.sql
new file mode 100644
index 000000000..9205a149e
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/stdlib/schema.sql
@@ -0,0 +1,12 @@
+CREATE EXTENSION pg_trgm;
+CREATE EXTENSION pgcrypto;
+
+CREATE TABLE users(
+    id INT GENERATED ALWAYS AS IDENTITY NOT NULL,
+    fname VARCHAR(100) NOT NULL,
+    lname VARCHAR(100) NOT NULL,
+    email VARCHAR(100) NOT NULL UNIQUE,
+    enc_passwd TEXT NOT NULL,
+    created_at TIMESTAMP WITH TIME ZONE NOT NULL default (NOW() AT TIME ZONE 'utc'),
+    PRIMARY KEY(id)
+);
diff --git a/internal/endtoend/testdata/column_alias/stdlib/sqlc.yaml b/internal/endtoend/testdata/column_alias/stdlib/sqlc.yaml
new file mode 100644
index 000000000..8c68222b4
--- /dev/null
+++ b/internal/endtoend/testdata/column_alias/stdlib/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "database/sql"
diff --git a/internal/endtoend/testdata/comment_syntax/mysql/go/query.sql.go b/internal/endtoend/testdata/comment_syntax/mysql/go/query.sql.go
index 7f4b91615..29909a8da 100644
--- a/internal/endtoend/testdata/comment_syntax/mysql/go/query.sql.go
+++ b/internal/endtoend/testdata/comment_syntax/mysql/go/query.sql.go
@@ -22,7 +22,6 @@ func (q *Queries) DoubleDash(ctx context.Context) (sql.NullString, error) {
 }
 
 const hash = `-- name: Hash :one
-# name: Hash :one
 SELECT bar FROM foo LIMIT 1
 `
 
diff --git a/internal/endtoend/testdata/cte_recursive_employees/issue.md b/internal/endtoend/testdata/cte_recursive_employees/issue.md
index 2bc033582..11f5771fd 100644
--- a/internal/endtoend/testdata/cte_recursive_employees/issue.md
+++ b/internal/endtoend/testdata/cte_recursive_employees/issue.md
@@ -1,1 +1,2 @@
-https://github.com/sqlc-dev/sqlc/issues/1219
\ No newline at end of file
+https://github.com/sqlc-dev/sqlc/issues/1219
+https://github.com/sqlc-dev/sqlc/issues/1912
diff --git a/internal/endtoend/testdata/cte_recursive_star/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/cte_recursive_star/postgresql/pgx/go/query.sql.go
index d96dd07b0..357101c95 100644
--- a/internal/endtoend/testdata/cte_recursive_star/postgresql/pgx/go/query.sql.go
+++ b/internal/endtoend/testdata/cte_recursive_star/postgresql/pgx/go/query.sql.go
@@ -26,7 +26,7 @@ type GetDictTreeRow struct {
 	ParentCode string
 	Label      string
 	Value      pgtype.Text
-	Path       pgtype.Text
+	Path       []string
 	Depth      int32
 }
 
diff --git a/internal/endtoend/testdata/cte_update_multiple/issue.md b/internal/endtoend/testdata/cte_update_multiple/issue.md
new file mode 100644
index 000000000..fc662de1e
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1916
diff --git a/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/exec.json b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/db.go b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/models.go b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..799810784
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/models.go
@@ -0,0 +1,37 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type Address struct {
+	ID          int64
+	AddressLine string
+	Region      string
+	City        string
+	CreatedAt   pgtype.Timestamptz
+	UpdatedAt   pgtype.Timestamptz
+}
+
+type User struct {
+	ID             int64
+	Username       string
+	Email          string
+	Password       string
+	Telephone      int32
+	DefaultPayment pgtype.Int8
+	CreatedAt      pgtype.Timestamptz
+	UpdatedAt      pgtype.Timestamptz
+}
+
+type UserAddress struct {
+	UserID         int64
+	AddressID      int64
+	DefaultAddress pgtype.Int8
+	CreatedAt      pgtype.Timestamptz
+	UpdatedAt      pgtype.Timestamptz
+}
diff --git a/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..abfd049e3
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,83 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const updateUserAddressWithAddress = `-- name: UpdateUserAddressWithAddress :one
+WITH t1 AS (
+    UPDATE "address" as a
+    SET
+    address_line = COALESCE($1,address_line), 
+    region = COALESCE($2,region), 
+    city= COALESCE($3,city)
+    WHERE id = COALESCE($4,id)
+    RETURNING a.id, a.address_line, a.region, a.city
+   ),
+   
+    t2 AS (
+    UPDATE "user_address"
+    SET
+    default_address = COALESCE($5,default_address)
+    WHERE
+    user_id = COALESCE($6,user_id)
+    AND address_id = COALESCE($7,address_id)
+    RETURNING user_id, address_id, default_address
+	)
+	
+SELECT 
+user_id,
+address_id,
+default_address,
+address_line,
+region,
+city From t1,t2
+`
+
+type UpdateUserAddressWithAddressParams struct {
+	AddressLine    pgtype.Text
+	Region         pgtype.Text
+	City           pgtype.Text
+	ID             pgtype.Int8
+	DefaultAddress pgtype.Int8
+	UserID         pgtype.Int8
+	AddressID      pgtype.Int8
+}
+
+type UpdateUserAddressWithAddressRow struct {
+	UserID         int64
+	AddressID      int64
+	DefaultAddress pgtype.Int8
+	AddressLine    string
+	Region         string
+	City           string
+}
+
+func (q *Queries) UpdateUserAddressWithAddress(ctx context.Context, arg UpdateUserAddressWithAddressParams) (UpdateUserAddressWithAddressRow, error) {
+	row := q.db.QueryRow(ctx, updateUserAddressWithAddress,
+		arg.AddressLine,
+		arg.Region,
+		arg.City,
+		arg.ID,
+		arg.DefaultAddress,
+		arg.UserID,
+		arg.AddressID,
+	)
+	var i UpdateUserAddressWithAddressRow
+	err := row.Scan(
+		&i.UserID,
+		&i.AddressID,
+		&i.DefaultAddress,
+		&i.AddressLine,
+		&i.Region,
+		&i.City,
+	)
+	return i, err
+}
diff --git a/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/query.sql b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/query.sql
new file mode 100644
index 000000000..9cb15e5b6
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/query.sql
@@ -0,0 +1,28 @@
+-- name: UpdateUserAddressWithAddress :one
+WITH t1 AS (
+    UPDATE "address" as a
+    SET
+    address_line = COALESCE(sqlc.narg(address_line),address_line), 
+    region = COALESCE(sqlc.narg(region),region), 
+    city= COALESCE(sqlc.narg(city),city)
+    WHERE id = COALESCE(sqlc.arg(id),id)
+    RETURNING a.id, a.address_line, a.region, a.city
+   ),
+   
+    t2 AS (
+    UPDATE "user_address"
+    SET
+    default_address = COALESCE(sqlc.narg(default_address),default_address)
+    WHERE
+    user_id = COALESCE(sqlc.arg(user_id),user_id)
+    AND address_id = COALESCE(sqlc.arg(address_id),address_id)
+    RETURNING user_id, address_id, default_address
+	)
+	
+SELECT 
+user_id,
+address_id,
+default_address,
+address_line,
+region,
+city From t1,t2;
diff --git a/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/schema.sql b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..7ec7b1a82
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/schema.sql
@@ -0,0 +1,27 @@
+CREATE TABLE "user" (
+  "id" bigserial PRIMARY KEY NOT NULL,
+  "username" varchar NOT NULL,
+  "email" varchar UNIQUE NOT NULL,
+  "password" varchar NOT NULL,
+  "telephone" int NOT NULL DEFAULT 0,
+  "default_payment" bigint,
+  "created_at" timestamptz NOT NULL DEFAULT (now()),
+  "updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
+);
+
+CREATE TABLE "address" (
+  "id" bigserial PRIMARY KEY NOT NULL,
+  "address_line" varchar NOT NULL,
+  "region" varchar NOT NULL,
+  "city" varchar NOT NULL,
+  "created_at" timestamptz NOT NULL DEFAULT (now()),
+  "updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
+);
+
+CREATE TABLE "user_address" (
+  "user_id" bigint NOT NULL,
+  "address_id" bigint UNIQUE NOT NULL,
+  "default_address" bigint,
+  "created_at" timestamptz NOT NULL DEFAULT (now()),
+  "updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
+);
diff --git a/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/ddl_create_table_unknown_type/issue.md b/internal/endtoend/testdata/ddl_create_table_unknown_type/issue.md
new file mode 100644
index 000000000..39b617cc6
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_create_table_unknown_type/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1917
diff --git a/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/exec.json b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/query.sql b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/query.sql
new file mode 100644
index 000000000..299eb45e2
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/query.sql
@@ -0,0 +1,2 @@
+-- name: SelectOne :one
+SELECT 1;
diff --git a/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/schema.sql b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..70cd3cf93
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/schema.sql
@@ -0,0 +1,3 @@
+CREATE TABLE test_table (
+    id STRING
+);
diff --git a/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/stderr.txt b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/stderr.txt
new file mode 100644
index 000000000..2cfd3bad9
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_create_table_unknown_type/postgresql/pgx/stderr.txt
@@ -0,0 +1,5 @@
+# package querytest
+query.sql:1:1: rpc error: code = FailedPrecondition desc = type "string" does not exist (42704)
+CREATE TABLE test_table (
+    id STRING
+);
diff --git a/internal/endtoend/testdata/ddl_materialized_views_invalid/issue.md b/internal/endtoend/testdata/ddl_materialized_views_invalid/issue.md
new file mode 100644
index 000000000..21df2f08d
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_materialized_views_invalid/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1545
diff --git a/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/exec.json b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/query.sql b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/query.sql
new file mode 100644
index 000000000..b9fa4a4eb
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/query.sql
@@ -0,0 +1,4 @@
+-- name: GetTotalEarned :one
+SELECT COALESCE(SUM(earned), 0) as total_earned
+FROM grouped_kpis
+WHERE day = @day;
diff --git a/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/schema.sql b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..d95036a96
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE kpis (
+  ts TIMESTAMPTZ,
+  event_id TEXT NOT NULL
+);
+
+CREATE MATERIALIZED VIEW IF NOT EXISTS grouped_kpis AS
+SELECT date_trunc('1 day', ts) as day, COUNT(*)
+FROM kpis
+GROUP BY 1;
diff --git a/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/stderr.txt b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/stderr.txt
new file mode 100644
index 000000000..e79676465
--- /dev/null
+++ b/internal/endtoend/testdata/ddl_materialized_views_invalid/postgresql/pgx/stderr.txt
@@ -0,0 +1,2 @@
+# package querytest
+query.sql:2:21: column "earned" does not exist
diff --git a/internal/endtoend/testdata/delete_using/issue.md b/internal/endtoend/testdata/delete_using/issue.md
new file mode 100644
index 000000000..c3fc394ad
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1714
diff --git a/internal/endtoend/testdata/delete_using/postgresql/pgx/exec.json b/internal/endtoend/testdata/delete_using/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/delete_using/postgresql/pgx/go/db.go b/internal/endtoend/testdata/delete_using/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/delete_using/postgresql/pgx/go/models.go b/internal/endtoend/testdata/delete_using/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..2208b6fa0
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/postgresql/pgx/go/models.go
@@ -0,0 +1,18 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type A struct {
+	AID   pgtype.Text
+	BIDFk pgtype.Text
+}
+
+type B struct {
+	BID pgtype.Text
+}
diff --git a/internal/endtoend/testdata/delete_using/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/delete_using/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..7ebf0e694
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,39 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const getSomeDeletedNotOk = `-- name: GetSomeDeletedNotOk :many
+DELETE FROM a
+USING b
+WHERE a.b_id_fk = b.b_id
+RETURNING b.b_id
+`
+
+func (q *Queries) GetSomeDeletedNotOk(ctx context.Context) ([]pgtype.Text, error) {
+	rows, err := q.db.Query(ctx, getSomeDeletedNotOk)
+	if err != nil {
+		return nil, err
+	}
+	defer rows.Close()
+	var items []pgtype.Text
+	for rows.Next() {
+		var b_id pgtype.Text
+		if err := rows.Scan(&b_id); err != nil {
+			return nil, err
+		}
+		items = append(items, b_id)
+	}
+	if err := rows.Err(); err != nil {
+		return nil, err
+	}
+	return items, nil
+}
diff --git a/internal/endtoend/testdata/delete_using/postgresql/pgx/query.sql b/internal/endtoend/testdata/delete_using/postgresql/pgx/query.sql
new file mode 100644
index 000000000..f660aaf95
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/postgresql/pgx/query.sql
@@ -0,0 +1,5 @@
+-- name: GetSomeDeletedNotOk :many
+DELETE FROM a
+USING b
+WHERE a.b_id_fk = b.b_id
+RETURNING b.b_id; -- column "b_id" does not exist
diff --git a/internal/endtoend/testdata/delete_using/postgresql/pgx/schema.sql b/internal/endtoend/testdata/delete_using/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..d6380b7a5
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/postgresql/pgx/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE a
+(
+    a_id TEXT,
+    b_id_fk TEXT
+);
+CREATE TABLE b
+(
+    b_id TEXT
+);
diff --git a/internal/endtoend/testdata/delete_using/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/delete_using/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/delete_using/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/func_out_param/issue.md b/internal/endtoend/testdata/func_out_param/issue.md
new file mode 100644
index 000000000..1b8779f2f
--- /dev/null
+++ b/internal/endtoend/testdata/func_out_param/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1654
diff --git a/internal/endtoend/testdata/func_out_param/pgx/go/db.go b/internal/endtoend/testdata/func_out_param/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/func_out_param/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/func_out_param/pgx/go/models.go b/internal/endtoend/testdata/func_out_param/pgx/go/models.go
new file mode 100644
index 000000000..b320134bd
--- /dev/null
+++ b/internal/endtoend/testdata/func_out_param/pgx/go/models.go
@@ -0,0 +1,15 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type Author struct {
+	ID   int64
+	Name string
+	Bio  pgtype.Text
+}
diff --git a/internal/endtoend/testdata/func_out_param/pgx/go/query.sql.go b/internal/endtoend/testdata/func_out_param/pgx/go/query.sql.go
new file mode 100644
index 000000000..b19b4a070
--- /dev/null
+++ b/internal/endtoend/testdata/func_out_param/pgx/go/query.sql.go
@@ -0,0 +1,30 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const createAuthor = `-- name: CreateAuthor :one
+SELECT id FROM add_author (
+  $1, $2
+)
+`
+
+type CreateAuthorParams struct {
+	Name string
+	Bio  string
+}
+
+func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (pgtype.Int4, error) {
+	row := q.db.QueryRow(ctx, createAuthor, arg.Name, arg.Bio)
+	var id pgtype.Int4
+	err := row.Scan(&id)
+	return id, err
+}
diff --git a/internal/endtoend/testdata/func_out_param/pgx/query.sql b/internal/endtoend/testdata/func_out_param/pgx/query.sql
new file mode 100644
index 000000000..b23c7dca4
--- /dev/null
+++ b/internal/endtoend/testdata/func_out_param/pgx/query.sql
@@ -0,0 +1,4 @@
+-- name: CreateAuthor :one
+SELECT * FROM add_author (
+  sqlc.arg(name), sqlc.arg(bio)
+);
diff --git a/internal/endtoend/testdata/func_out_param/pgx/schema.sql b/internal/endtoend/testdata/func_out_param/pgx/schema.sql
new file mode 100644
index 000000000..97c1022d1
--- /dev/null
+++ b/internal/endtoend/testdata/func_out_param/pgx/schema.sql
@@ -0,0 +1,14 @@
+-- Example queries for sqlc
+CREATE TABLE authors (
+  id   BIGSERIAL PRIMARY KEY,
+  name text      NOT NULL,
+  bio  text
+);
+
+CREATE OR REPLACE FUNCTION add_author (name text, bio text, out id int)
+AS $$
+DECLARE
+BEGIN
+  id = 123;
+END;
+$$ LANGUAGE plpgsql;
diff --git a/internal/endtoend/testdata/func_out_param/pgx/sqlc.yaml b/internal/endtoend/testdata/func_out_param/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/func_out_param/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/func_return_record/issue.md b/internal/endtoend/testdata/func_return_record/issue.md
new file mode 100644
index 000000000..56e68299a
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1979
diff --git a/internal/endtoend/testdata/func_return_record/postgresql/pgx/exec.json b/internal/endtoend/testdata/func_return_record/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/db.go b/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/models.go b/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..077e70255
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/models.go
@@ -0,0 +1,11 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import ()
+
+type MyTable struct {
+	Data []byte
+}
diff --git a/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..0a9080f53
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,30 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const getData = `-- name: GetData :one
+SELECT key, value
+FROM my_table, jsonb_each(data)
+LIMIT 1
+`
+
+type GetDataRow struct {
+	Key   pgtype.Text
+	Value []byte
+}
+
+func (q *Queries) GetData(ctx context.Context) (GetDataRow, error) {
+	row := q.db.QueryRow(ctx, getData)
+	var i GetDataRow
+	err := row.Scan(&i.Key, &i.Value)
+	return i, err
+}
diff --git a/internal/endtoend/testdata/func_return_record/postgresql/pgx/query.sql b/internal/endtoend/testdata/func_return_record/postgresql/pgx/query.sql
new file mode 100644
index 000000000..c540b6ac5
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/postgresql/pgx/query.sql
@@ -0,0 +1,4 @@
+-- name: GetData :one
+SELECT key, value
+FROM my_table, jsonb_each(data)
+LIMIT 1;
diff --git a/internal/endtoend/testdata/func_return_record/postgresql/pgx/schema.sql b/internal/endtoend/testdata/func_return_record/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..4db45f972
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/postgresql/pgx/schema.sql
@@ -0,0 +1,3 @@
+CREATE TABLE my_table (
+  data JSONB NOT NULL
+);
diff --git a/internal/endtoend/testdata/func_return_record/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/func_return_record/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/func_return_record/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/insert_select_case/issue.md b/internal/endtoend/testdata/insert_select_case/issue.md
new file mode 100644
index 000000000..f4090f863
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1646
diff --git a/internal/endtoend/testdata/insert_select_case/postgresql/pgx/exec.json b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/db.go b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/models.go b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..100524a30
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/models.go
@@ -0,0 +1,14 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type Order struct {
+	ID   pgtype.Int8
+	Name pgtype.Text
+}
diff --git a/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..722933a95
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,28 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const insertOrders = `-- name: InsertOrders :exec
+insert into Orders (id,name)
+select id , CASE WHEN $1::BOOLEAN THEN $2 ELSE s.name END 
+from Orders s
+`
+
+type InsertOrdersParams struct {
+	NameDoUpdate pgtype.Bool
+	Name         pgtype.Text
+}
+
+func (q *Queries) InsertOrders(ctx context.Context, arg InsertOrdersParams) error {
+	_, err := q.db.Exec(ctx, insertOrders, arg.NameDoUpdate, arg.Name)
+	return err
+}
diff --git a/internal/endtoend/testdata/insert_select_case/postgresql/pgx/query.sql b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/query.sql
new file mode 100644
index 000000000..4396b7bf2
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/query.sql
@@ -0,0 +1,4 @@
+-- name: InsertOrders :exec
+insert into Orders (id,name)
+select id , CASE WHEN @name_do_update::BOOLEAN THEN @name ELSE s.name END 
+from Orders s ;
diff --git a/internal/endtoend/testdata/insert_select_case/postgresql/pgx/schema.sql b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..cbc21a5b7
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/schema.sql
@@ -0,0 +1,4 @@
+CREATE TABLE orders(
+  id bigserial,
+  name text
+);
diff --git a/internal/endtoend/testdata/insert_select_case/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..ee50c7b6e
--- /dev/null
+++ b/internal/endtoend/testdata/insert_select_case/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,12 @@
+version: "2"
+cloud:
+  project: "01HAQMMECEYQYKFJN8MP16QC41"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/invalid_queries_foo/pgx/v4/stderr.txt b/internal/endtoend/testdata/invalid_queries_foo/pgx/v4/stderr.txt
index 6b0840fc3..06ec54327 100644
--- a/internal/endtoend/testdata/invalid_queries_foo/pgx/v4/stderr.txt
+++ b/internal/endtoend/testdata/invalid_queries_foo/pgx/v4/stderr.txt
@@ -1,5 +1,5 @@
 # package querytest
-query.sql:1:1: invalid query comment: -- name: ListFoos
+query.sql:1:1: missing query type [':one', ':many', ':exec', ':execrows', ':execlastid', ':execresult', ':copyfrom', 'batchexec', 'batchmany', 'batchone']: -- name: ListFoos
 query.sql:5:1: invalid query comment: -- name: ListFoos :one :many
 query.sql:8:1: invalid query type: :two
 query.sql:11:1: query "DeleteFoo" specifies parameter ":one" without containing a RETURNING clause
diff --git a/internal/endtoend/testdata/invalid_queries_foo/pgx/v5/stderr.txt b/internal/endtoend/testdata/invalid_queries_foo/pgx/v5/stderr.txt
index 6b0840fc3..06ec54327 100644
--- a/internal/endtoend/testdata/invalid_queries_foo/pgx/v5/stderr.txt
+++ b/internal/endtoend/testdata/invalid_queries_foo/pgx/v5/stderr.txt
@@ -1,5 +1,5 @@
 # package querytest
-query.sql:1:1: invalid query comment: -- name: ListFoos
+query.sql:1:1: missing query type [':one', ':many', ':exec', ':execrows', ':execlastid', ':execresult', ':copyfrom', 'batchexec', 'batchmany', 'batchone']: -- name: ListFoos
 query.sql:5:1: invalid query comment: -- name: ListFoos :one :many
 query.sql:8:1: invalid query type: :two
 query.sql:11:1: query "DeleteFoo" specifies parameter ":one" without containing a RETURNING clause
diff --git a/internal/endtoend/testdata/invalid_queries_foo/stdlib/stderr.txt b/internal/endtoend/testdata/invalid_queries_foo/stdlib/stderr.txt
index 6b0840fc3..06ec54327 100644
--- a/internal/endtoend/testdata/invalid_queries_foo/stdlib/stderr.txt
+++ b/internal/endtoend/testdata/invalid_queries_foo/stdlib/stderr.txt
@@ -1,5 +1,5 @@
 # package querytest
-query.sql:1:1: invalid query comment: -- name: ListFoos
+query.sql:1:1: missing query type [':one', ':many', ':exec', ':execrows', ':execlastid', ':execresult', ':copyfrom', 'batchexec', 'batchmany', 'batchone']: -- name: ListFoos
 query.sql:5:1: invalid query comment: -- name: ListFoos :one :many
 query.sql:8:1: invalid query type: :two
 query.sql:11:1: query "DeleteFoo" specifies parameter ":one" without containing a RETURNING clause
diff --git a/internal/endtoend/testdata/join_left_table_alias/issue.md b/internal/endtoend/testdata/join_left_table_alias/issue.md
new file mode 100644
index 000000000..77e67d124
--- /dev/null
+++ b/internal/endtoend/testdata/join_left_table_alias/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1897
diff --git a/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/db.go b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/models.go b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..11461a006
--- /dev/null
+++ b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/models.go
@@ -0,0 +1,16 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import ()
+
+type Bar struct {
+	FooID int64
+	Info  string
+}
+
+type Foo struct {
+	ID int64
+}
diff --git a/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..2de45039a
--- /dev/null
+++ b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,48 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const joinBar = `-- name: JoinBar :one
+SELECT f.id, info
+FROM foo f
+LEFT JOIN bar b ON b.foo_id = f.id
+`
+
+type JoinBarRow struct {
+	ID   int64
+	Info pgtype.Text
+}
+
+func (q *Queries) JoinBar(ctx context.Context) (JoinBarRow, error) {
+	row := q.db.QueryRow(ctx, joinBar)
+	var i JoinBarRow
+	err := row.Scan(&i.ID, &i.Info)
+	return i, err
+}
+
+const joinBarAlias = `-- name: JoinBarAlias :one
+SELECT f.id, b.info
+FROM foo f
+LEFT JOIN bar b ON b.foo_id = f.id
+`
+
+type JoinBarAliasRow struct {
+	ID   int64
+	Info pgtype.Text
+}
+
+func (q *Queries) JoinBarAlias(ctx context.Context) (JoinBarAliasRow, error) {
+	row := q.db.QueryRow(ctx, joinBarAlias)
+	var i JoinBarAliasRow
+	err := row.Scan(&i.ID, &i.Info)
+	return i, err
+}
diff --git a/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/query.sql b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/query.sql
new file mode 100644
index 000000000..ad61f17b7
--- /dev/null
+++ b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/query.sql
@@ -0,0 +1,9 @@
+-- name: JoinBar :one
+SELECT f.id, info
+FROM foo f
+LEFT JOIN bar b ON b.foo_id = f.id;
+
+-- name: JoinBarAlias :one
+SELECT f.id, b.info
+FROM foo f
+LEFT JOIN bar b ON b.foo_id = f.id;
diff --git a/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/schema.sql b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..296159099
--- /dev/null
+++ b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE foo (
+	id BIGINT PRIMARY KEY
+);
+
+CREATE TABLE bar
+(
+    foo_id  BIGINT NOT NULL,
+    info    TEXT NOT NULL
+);
diff --git a/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/join_left_table_alias/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/min_max_date/issue.md b/internal/endtoend/testdata/min_max_date/issue.md
new file mode 100644
index 000000000..73083e965
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1574
diff --git a/internal/endtoend/testdata/min_max_date/postgresql/pgx/exec.json b/internal/endtoend/testdata/min_max_date/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/db.go b/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/models.go b/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..19ec509dd
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/models.go
@@ -0,0 +1,14 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type Activity struct {
+	AccountID int64
+	EventTime pgtype.Timestamptz
+}
diff --git a/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..df0bfad70
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,33 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const activityStats = `-- name: ActivityStats :one
+SELECT COUNT(*) as NumOfActivities,
+        MIN(event_time) as MinDate, 
+        MAX(event_time) as MaxDate 
+FROM activities 
+WHERE account_id = $1
+`
+
+type ActivityStatsRow struct {
+	Numofactivities int64
+	Mindate         pgtype.Timestamptz
+	Maxdate         pgtype.Timestamptz
+}
+
+func (q *Queries) ActivityStats(ctx context.Context, accountID int64) (ActivityStatsRow, error) {
+	row := q.db.QueryRow(ctx, activityStats, accountID)
+	var i ActivityStatsRow
+	err := row.Scan(&i.Numofactivities, &i.Mindate, &i.Maxdate)
+	return i, err
+}
diff --git a/internal/endtoend/testdata/min_max_date/postgresql/pgx/query.sql b/internal/endtoend/testdata/min_max_date/postgresql/pgx/query.sql
new file mode 100644
index 000000000..19909d0c8
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/postgresql/pgx/query.sql
@@ -0,0 +1,6 @@
+-- name: ActivityStats :one
+SELECT COUNT(*) as NumOfActivities,
+        MIN(event_time) as MinDate, 
+        MAX(event_time) as MaxDate 
+FROM activities 
+WHERE account_id = $1;
diff --git a/internal/endtoend/testdata/min_max_date/postgresql/pgx/schema.sql b/internal/endtoend/testdata/min_max_date/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..c75fe28fb
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/postgresql/pgx/schema.sql
@@ -0,0 +1,4 @@
+CREATE TABLE activities (
+    account_id BIGINT NOT NULL,
+    event_time TIMESTAMP WITH TIME ZONE NOT NULL
+);
diff --git a/internal/endtoend/testdata/min_max_date/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/min_max_date/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/min_max_date/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/models.go b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/models.go
index b1624997b..d918dc44c 100644
--- a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/models.go
+++ b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/models.go
@@ -219,6 +219,48 @@ func (ns NullQueryReturnStructEnumTableEnum) Value() (driver.Value, error) {
 	return string(ns.QueryReturnStructEnumTableEnum), nil
 }
 
+type QuerySqlcEmbedEnum string
+
+const (
+	QuerySqlcEmbedEnumM QuerySqlcEmbedEnum = "m"
+	QuerySqlcEmbedEnumN QuerySqlcEmbedEnum = "n"
+)
+
+func (e *QuerySqlcEmbedEnum) Scan(src interface{}) error {
+	switch s := src.(type) {
+	case []byte:
+		*e = QuerySqlcEmbedEnum(s)
+	case string:
+		*e = QuerySqlcEmbedEnum(s)
+	default:
+		return fmt.Errorf("unsupported scan type for QuerySqlcEmbedEnum: %T", src)
+	}
+	return nil
+}
+
+type NullQuerySqlcEmbedEnum struct {
+	QuerySqlcEmbedEnum QuerySqlcEmbedEnum
+	Valid              bool // Valid is true if QuerySqlcEmbedEnum is not NULL
+}
+
+// Scan implements the Scanner interface.
+func (ns *NullQuerySqlcEmbedEnum) Scan(value interface{}) error {
+	if value == nil {
+		ns.QuerySqlcEmbedEnum, ns.Valid = "", false
+		return nil
+	}
+	ns.Valid = true
+	return ns.QuerySqlcEmbedEnum.Scan(value)
+}
+
+// Value implements the driver Valuer interface.
+func (ns NullQuerySqlcEmbedEnum) Value() (driver.Value, error) {
+	if !ns.Valid {
+		return nil, nil
+	}
+	return string(ns.QuerySqlcEmbedEnum), nil
+}
+
 type QueryParamEnumTable struct {
 	ID    int32
 	Other QueryParamEnumTableEnum
@@ -229,3 +271,8 @@ type QueryReturnFullTable struct {
 	ID    int32
 	Value NullQueryReturnFullTableEnum
 }
+
+type QuerySqlcEmbedTable struct {
+	ID    int32
+	Value NullQuerySqlcEmbedEnum
+}
diff --git a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/query.sql.go b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/query.sql.go
index f65910269..91457e09a 100644
--- a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/query.sql.go
+++ b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/go/query.sql.go
@@ -90,3 +90,18 @@ func (q *Queries) query_return_struct_enum_table(ctx context.Context, id int32)
 	err := row.Scan(&i.Value, &i.Another)
 	return i, err
 }
+
+const query_sqlc_embed_table = `-- name: query_sqlc_embed_table :one
+SELECT query_sqlc_embed_table.id, query_sqlc_embed_table.value FROM query_sqlc_embed_table WHERE id = $1
+`
+
+type query_sqlc_embed_tableRow struct {
+	QuerySqlcEmbedTable QuerySqlcEmbedTable
+}
+
+func (q *Queries) query_sqlc_embed_table(ctx context.Context, id int32) (query_sqlc_embed_tableRow, error) {
+	row := q.db.QueryRowContext(ctx, query_sqlc_embed_table, id)
+	var i query_sqlc_embed_tableRow
+	err := row.Scan(&i.QuerySqlcEmbedTable.ID, &i.QuerySqlcEmbedTable.Value)
+	return i, err
+}
diff --git a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/query.sql b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/query.sql
index 1420d869d..599a22748 100644
--- a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/query.sql
+++ b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/query.sql
@@ -11,4 +11,7 @@ SELECT id FROM query_param_struct_enum_table WHERE id = $1 AND value = $2;
 SELECT value FROM query_return_enum_table WHERE id = $1;
 
 -- name: query_return_struct_enum_table :one
-SELECT value, another FROM query_return_struct_enum_table WHERE id = $1;
\ No newline at end of file
+SELECT value, another FROM query_return_struct_enum_table WHERE id = $1;
+
+-- name: query_sqlc_embed_table :one
+SELECT sqlc.embed(query_sqlc_embed_table) FROM query_sqlc_embed_table WHERE id = $1;
diff --git a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/schema.sql b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/schema.sql
index cc2ae14b2..486119c33 100644
--- a/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/schema.sql
+++ b/internal/endtoend/testdata/omit_unused_structs/postgresql/stdlib/schema.sql
@@ -50,4 +50,12 @@ CREATE TABLE query_return_struct_enum_table (
     id      INTEGER PRIMARY KEY,
     value   query_return_struct_enum_table_enum,
     another INTEGER
-);
\ No newline at end of file
+);
+
+CREATE TYPE query_sqlc_embed_enum AS ENUM (
+    'm', 'n'
+);
+CREATE TABLE query_sqlc_embed_table (
+    id      INTEGER PRIMARY KEY,
+    value   query_sqlc_embed_enum
+)
diff --git a/internal/endtoend/testdata/select_sequence/issue.md b/internal/endtoend/testdata/select_sequence/issue.md
new file mode 100644
index 000000000..38c550fe1
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1634
diff --git a/internal/endtoend/testdata/select_sequence/postgresql/pgx/exec.json b/internal/endtoend/testdata/select_sequence/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/db.go b/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/models.go b/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..172574ab2
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/models.go
@@ -0,0 +1,7 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import ()
diff --git a/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..430d6b49a
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,21 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+)
+
+const getLastValue = `-- name: GetLastValue :one
+SELECT last_value FROM my_sequence
+`
+
+func (q *Queries) GetLastValue(ctx context.Context) (int64, error) {
+	row := q.db.QueryRow(ctx, getLastValue)
+	var last_value int64
+	err := row.Scan(&last_value)
+	return last_value, err
+}
diff --git a/internal/endtoend/testdata/select_sequence/postgresql/pgx/query.sql b/internal/endtoend/testdata/select_sequence/postgresql/pgx/query.sql
new file mode 100644
index 000000000..82cc9b0a5
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/postgresql/pgx/query.sql
@@ -0,0 +1,2 @@
+-- name: GetLastValue :one
+SELECT last_value FROM my_sequence;
diff --git a/internal/endtoend/testdata/select_sequence/postgresql/pgx/schema.sql b/internal/endtoend/testdata/select_sequence/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..94a6932f8
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/postgresql/pgx/schema.sql
@@ -0,0 +1,6 @@
+CREATE SEQUENCE public.my_sequence
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
diff --git a/internal/endtoend/testdata/select_sequence/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/select_sequence/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/select_sequence/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/issue.md b/internal/endtoend/testdata/select_subquery/postgresql/issue.md
new file mode 100644
index 000000000..fa59b3a57
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/pull/2639
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/stdlib/exec.json b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/exec.json
new file mode 100644
index 000000000..e5dfda781
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/exec.json
@@ -0,0 +1,3 @@
+{
+    "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/db.go b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/db.go
new file mode 100644
index 000000000..a457fb76b
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/db.go
@@ -0,0 +1,31 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+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,
+	}
+}
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/models.go b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/models.go
new file mode 100644
index 000000000..56e82be76
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/models.go
@@ -0,0 +1,19 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"database/sql"
+)
+
+type Bar struct {
+	A     int32
+	Alias sql.NullString
+}
+
+type Foo struct {
+	A    int32
+	Name sql.NullString
+}
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/query.sql.go b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/query.sql.go
new file mode 100644
index 000000000..a8347ffe3
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/go/query.sql.go
@@ -0,0 +1,53 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+	"database/sql"
+)
+
+const subquery = `-- name: Subquery :many
+SELECT 
+	a,
+	name,
+	(SELECT alias FROM bar WHERE bar.a=foo.a AND alias = $1 ORDER BY bar.a DESC limit 1) as alias
+FROM FOO WHERE a = $2
+`
+
+type SubqueryParams struct {
+	Column1 sql.NullString
+	Column2 sql.NullInt32
+}
+
+type SubqueryRow struct {
+	A     int32
+	Name  sql.NullString
+	Alias sql.NullString
+}
+
+func (q *Queries) Subquery(ctx context.Context, arg SubqueryParams) ([]SubqueryRow, error) {
+	rows, err := q.db.QueryContext(ctx, subquery, arg.Column1, arg.Column2)
+	if err != nil {
+		return nil, err
+	}
+	defer rows.Close()
+	var items []SubqueryRow
+	for rows.Next() {
+		var i SubqueryRow
+		if err := rows.Scan(&i.A, &i.Name, &i.Alias); 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
+}
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/stdlib/query.sql b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/query.sql
new file mode 100644
index 000000000..3d9b058b0
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/query.sql
@@ -0,0 +1,6 @@
+-- name: Subquery :many
+SELECT 
+	a,
+	name,
+	(SELECT alias FROM bar WHERE bar.a=foo.a AND alias = $1 ORDER BY bar.a DESC limit 1) as alias
+FROM FOO WHERE a = $2;
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/stdlib/schema.sql b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/schema.sql
new file mode 100644
index 000000000..b256bf60a
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/schema.sql
@@ -0,0 +1,2 @@
+CREATE TABLE foo (a int not null, name text);
+CREATE TABLE bar (a int not null, alias text);
diff --git a/internal/endtoend/testdata/select_subquery/postgresql/stdlib/sqlc.yaml b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/sqlc.yaml
new file mode 100644
index 000000000..8c68222b4
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery/postgresql/stdlib/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "database/sql"
diff --git a/internal/endtoend/testdata/select_subquery_alias/issue.md b/internal/endtoend/testdata/select_subquery_alias/issue.md
new file mode 100644
index 000000000..1f15e6721
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1990
diff --git a/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/exec.json b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/db.go b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/models.go b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..14f6a8d25
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/models.go
@@ -0,0 +1,16 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type Wallet struct {
+	ID      int64
+	Address string
+	Type    string
+	Balance pgtype.Numeric
+}
diff --git a/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..975dbbb9e
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,61 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const findWallets = `-- name: FindWallets :many
+select id, address, balance, total_balance from 
+(
+	select id, address, balance,
+	  sum(balance) over (order by balance desc rows between unbounded preceding and current row) as total_balance,
+	  sum(balance) over (order by balance desc rows between unbounded preceding and current row) - balance as last_balance
+	from wallets
+	where type=$1
+) amounts
+where amounts.last_balance < $2
+`
+
+type FindWalletsParams struct {
+	Column1 pgtype.Text
+	Column2 pgtype.Numeric
+}
+
+type FindWalletsRow struct {
+	ID           int64
+	Address      string
+	Balance      pgtype.Numeric
+	TotalBalance pgtype.Numeric
+}
+
+func (q *Queries) FindWallets(ctx context.Context, arg FindWalletsParams) ([]FindWalletsRow, error) {
+	rows, err := q.db.Query(ctx, findWallets, arg.Column1, arg.Column2)
+	if err != nil {
+		return nil, err
+	}
+	defer rows.Close()
+	var items []FindWalletsRow
+	for rows.Next() {
+		var i FindWalletsRow
+		if err := rows.Scan(
+			&i.ID,
+			&i.Address,
+			&i.Balance,
+			&i.TotalBalance,
+		); err != nil {
+			return nil, err
+		}
+		items = append(items, i)
+	}
+	if err := rows.Err(); err != nil {
+		return nil, err
+	}
+	return items, nil
+}
diff --git a/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/query.sql b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/query.sql
new file mode 100644
index 000000000..b3412234c
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/query.sql
@@ -0,0 +1,10 @@
+-- name: FindWallets :many
+select id, address, balance, total_balance from 
+(
+	select id, address, balance,
+	  sum(balance) over (order by balance desc rows between unbounded preceding and current row) as total_balance,
+	  sum(balance) over (order by balance desc rows between unbounded preceding and current row) - balance as last_balance
+	from wallets
+	where type=$1
+) amounts
+where amounts.last_balance < $2;
diff --git a/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/schema.sql b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..275a65e10
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/schema.sql
@@ -0,0 +1,7 @@
+CREATE TABLE IF NOT EXISTS wallets
+(
+    id BIGSERIAL PRIMARY KEY,
+    address VARCHAR(44) NOT NULL,
+    type VARCHAR(44) NOT NULL,
+    balance DECIMAL(32, 18) NULL
+);
diff --git a/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/select_subquery_alias/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/select_system/issue.md b/internal/endtoend/testdata/select_system/issue.md
new file mode 100644
index 000000000..7e536076f
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1745
diff --git a/internal/endtoend/testdata/select_system/pgx/exec.json b/internal/endtoend/testdata/select_system/pgx/exec.json
new file mode 100644
index 000000000..e5dfda781
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+    "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/select_system/pgx/go/db.go b/internal/endtoend/testdata/select_system/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/select_system/pgx/go/models.go b/internal/endtoend/testdata/select_system/pgx/go/models.go
new file mode 100644
index 000000000..b52387cf1
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/pgx/go/models.go
@@ -0,0 +1,13 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type Test struct {
+	ID pgtype.Int4
+}
diff --git a/internal/endtoend/testdata/select_system/pgx/go/query.sql.go b/internal/endtoend/testdata/select_system/pgx/go/query.sql.go
new file mode 100644
index 000000000..fadb461a6
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/pgx/go/query.sql.go
@@ -0,0 +1,41 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const getSystemColumns = `-- name: GetSystemColumns :one
+SELECT
+  tableoid, xmin, cmin, xmax, cmax, ctid
+FROM test
+`
+
+type GetSystemColumnsRow struct {
+	Tableoid pgtype.Uint32
+	Xmin     pgtype.Uint32
+	Cmin     pgtype.Uint32
+	Xmax     pgtype.Uint32
+	Cmax     pgtype.Uint32
+	Ctid     pgtype.TID
+}
+
+func (q *Queries) GetSystemColumns(ctx context.Context) (GetSystemColumnsRow, error) {
+	row := q.db.QueryRow(ctx, getSystemColumns)
+	var i GetSystemColumnsRow
+	err := row.Scan(
+		&i.Tableoid,
+		&i.Xmin,
+		&i.Cmin,
+		&i.Xmax,
+		&i.Cmax,
+		&i.Ctid,
+	)
+	return i, err
+}
diff --git a/internal/endtoend/testdata/select_system/pgx/query.sql b/internal/endtoend/testdata/select_system/pgx/query.sql
new file mode 100644
index 000000000..11ddeb749
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/pgx/query.sql
@@ -0,0 +1,4 @@
+-- name: GetSystemColumns :one
+SELECT
+  tableoid, xmin, cmin, xmax, cmax, ctid
+FROM test;
diff --git a/internal/endtoend/testdata/select_system/pgx/schema.sql b/internal/endtoend/testdata/select_system/pgx/schema.sql
new file mode 100644
index 000000000..7518997c9
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/pgx/schema.sql
@@ -0,0 +1,3 @@
+CREATE TABLE test (
+  id INT
+);
diff --git a/internal/endtoend/testdata/select_system/pgx/sqlc.yaml b/internal/endtoend/testdata/select_system/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/select_system/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/endtoend/testdata/star_expansion_series/issue.md b/internal/endtoend/testdata/star_expansion_series/issue.md
new file mode 100644
index 000000000..72e3e3aa9
--- /dev/null
+++ b/internal/endtoend/testdata/star_expansion_series/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1995
diff --git a/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/db.go b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/models.go b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..31b21050a
--- /dev/null
+++ b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/models.go
@@ -0,0 +1,13 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+type Alertreport struct {
+	Eventdate pgtype.Date
+}
diff --git a/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..e82562c5e
--- /dev/null
+++ b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,56 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5/pgtype"
+)
+
+const countAlertReportBy = `-- name: CountAlertReportBy :many
+select DATE_TRUNC($1,ts)::text as datetime,coalesce(count,0) as count from 
+(
+    SELECT  DATE_TRUNC($1,eventdate) as hr ,count(*)
+    FROM    alertreport
+    where eventdate between $2 and $3
+    GROUP BY   1
+) AS cnt 
+right outer join ( SELECT ts FROM generate_series ( $2, $3, CONCAT('1 ',$1)::interval) AS ts ) as dte
+on DATE_TRUNC($1, ts ) = cnt.hr 
+order by 1 asc
+`
+
+type CountAlertReportByParams struct {
+	DateTrunc   string
+	Eventdate   pgtype.Date
+	Eventdate_2 pgtype.Date
+}
+
+type CountAlertReportByRow struct {
+	Datetime string
+	Count    int64
+}
+
+func (q *Queries) CountAlertReportBy(ctx context.Context, arg CountAlertReportByParams) ([]CountAlertReportByRow, error) {
+	rows, err := q.db.Query(ctx, countAlertReportBy, arg.DateTrunc, arg.Eventdate, arg.Eventdate_2)
+	if err != nil {
+		return nil, err
+	}
+	defer rows.Close()
+	var items []CountAlertReportByRow
+	for rows.Next() {
+		var i CountAlertReportByRow
+		if err := rows.Scan(&i.Datetime, &i.Count); err != nil {
+			return nil, err
+		}
+		items = append(items, i)
+	}
+	if err := rows.Err(); err != nil {
+		return nil, err
+	}
+	return items, nil
+}
diff --git a/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/query.sql b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/query.sql
new file mode 100644
index 000000000..df13ae9a9
--- /dev/null
+++ b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/query.sql
@@ -0,0 +1,11 @@
+-- name: CountAlertReportBy :many
+select DATE_TRUNC($1,ts)::text as datetime,coalesce(count,0) as count from 
+(
+    SELECT  DATE_TRUNC($1,eventdate) as hr ,count(*)
+    FROM    alertreport
+    where eventdate between $2 and $3
+    GROUP BY   1
+) AS cnt 
+right outer join ( SELECT * FROM generate_series ( $2, $3, CONCAT('1 ',$1)::interval) AS ts ) as dte
+on DATE_TRUNC($1, ts ) = cnt.hr 
+order by 1 asc;
diff --git a/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/schema.sql b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..533757a46
--- /dev/null
+++ b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/schema.sql
@@ -0,0 +1,3 @@
+CREATE TABLE alertreport (
+  eventdate date
+);
diff --git a/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..2f1271592
--- /dev/null
+++ b/internal/endtoend/testdata/star_expansion_series/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,14 @@
+version: "2"
+cloud:
+  project: "01HAQMMECEYQYKFJN8MP16QC41"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
+    database:
+      managed: true
diff --git a/internal/endtoend/testdata/update_array_index/issue.md b/internal/endtoend/testdata/update_array_index/issue.md
new file mode 100644
index 000000000..d86fb5d2a
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/issue.md
@@ -0,0 +1,1 @@
+https://github.com/sqlc-dev/sqlc/issues/1532
diff --git a/internal/endtoend/testdata/update_array_index/postgresql/pgx/exec.json b/internal/endtoend/testdata/update_array_index/postgresql/pgx/exec.json
new file mode 100644
index 000000000..ee1b7ecd9
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/postgresql/pgx/exec.json
@@ -0,0 +1,3 @@
+{
+  "contexts": ["managed-db"]
+}
diff --git a/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/db.go b/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/db.go
new file mode 100644
index 000000000..8a010ccc4
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/db.go
@@ -0,0 +1,32 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import (
+	"context"
+
+	"github.com/jackc/pgx/v5"
+	"github.com/jackc/pgx/v5/pgconn"
+)
+
+type DBTX interface {
+	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
+	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
+	QueryRow(context.Context, string, ...interface{}) pgx.Row
+}
+
+func New(db DBTX) *Queries {
+	return &Queries{db: db}
+}
+
+type Queries struct {
+	db DBTX
+}
+
+func (q *Queries) WithTx(tx pgx.Tx) *Queries {
+	return &Queries{
+		db: tx,
+	}
+}
diff --git a/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/models.go b/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/models.go
new file mode 100644
index 000000000..8ce25599b
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/models.go
@@ -0,0 +1,12 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+
+package querytest
+
+import ()
+
+type Author struct {
+	ID    int64
+	Names []string
+}
diff --git a/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/query.sql.go b/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/query.sql.go
new file mode 100644
index 000000000..f51cedfd0
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/postgresql/pgx/go/query.sql.go
@@ -0,0 +1,30 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+//   sqlc v1.22.0
+// source: query.sql
+
+package querytest
+
+import (
+	"context"
+)
+
+const updateAuthor = `-- name: UpdateAuthor :one
+update authors
+set names[$1] = $2
+where id=$3
+RETURNING id, names
+`
+
+type UpdateAuthorParams struct {
+	Names   int32
+	Names_2 string
+	ID      int64
+}
+
+func (q *Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) (Author, error) {
+	row := q.db.QueryRow(ctx, updateAuthor, arg.Names, arg.Names_2, arg.ID)
+	var i Author
+	err := row.Scan(&i.ID, &i.Names)
+	return i, err
+}
diff --git a/internal/endtoend/testdata/update_array_index/postgresql/pgx/query.sql b/internal/endtoend/testdata/update_array_index/postgresql/pgx/query.sql
new file mode 100644
index 000000000..32b4e9c14
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/postgresql/pgx/query.sql
@@ -0,0 +1,5 @@
+-- name: UpdateAuthor :one
+update authors
+set names[$1] = $2
+where id=$3
+RETURNING *;
diff --git a/internal/endtoend/testdata/update_array_index/postgresql/pgx/schema.sql b/internal/endtoend/testdata/update_array_index/postgresql/pgx/schema.sql
new file mode 100644
index 000000000..286ab791f
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/postgresql/pgx/schema.sql
@@ -0,0 +1,4 @@
+CREATE TABLE authors (
+  id    BIGSERIAL PRIMARY KEY,
+  names text[]    NOT NULL
+);
diff --git a/internal/endtoend/testdata/update_array_index/postgresql/pgx/sqlc.yaml b/internal/endtoend/testdata/update_array_index/postgresql/pgx/sqlc.yaml
new file mode 100644
index 000000000..5dc63e3f9
--- /dev/null
+++ b/internal/endtoend/testdata/update_array_index/postgresql/pgx/sqlc.yaml
@@ -0,0 +1,10 @@
+version: "2"
+sql:
+  - engine: "postgresql"
+    schema: "schema.sql"
+    queries: "query.sql"
+    gen:
+      go:
+        package: "querytest"
+        out: "go"
+        sql_package: "pgx/v5"
diff --git a/internal/metadata/meta_test.go b/internal/metadata/meta_test.go
index cbfcb6fba..3c2be6d6d 100644
--- a/internal/metadata/meta_test.go
+++ b/internal/metadata/meta_test.go
@@ -32,34 +32,108 @@ func TestParseQueryNameAndType(t *testing.T) {
 		}
 	}
 
-	query := `-- name: CreateFoo :one`
-	queryName, queryType, err := ParseQueryNameAndType(query, CommentSyntax{Dash: true})
-	if err != nil {
-		t.Errorf("expected valid metadata: %q", query)
-	}
-	if queryName != "CreateFoo" {
-		t.Errorf("incorrect queryName parsed: %q", query)
-	}
-	if queryType != CmdOne {
-		t.Errorf("incorrect queryType parsed: %q", query)
+	for query, cs := range map[string]CommentSyntax{
+		`-- name: CreateFoo :one`:    {Dash: true},
+		`# name: CreateFoo :one`:     {Hash: true},
+		`/* name: CreateFoo :one */`: {SlashStar: true},
+	} {
+		queryName, queryCmd, err := ParseQueryNameAndType(query, cs)
+		if err != nil {
+			t.Errorf("expected valid metadata: %q", query)
+		}
+		if queryName != "CreateFoo" {
+			t.Errorf("incorrect queryName parsed: (%q) %q", queryName, query)
+		}
+		if queryCmd != CmdOne {
+			t.Errorf("incorrect queryCmd parsed: (%q) %q", queryCmd, query)
+		}
 	}
 
 }
 
+func TestParseQueryParams(t *testing.T) {
+	for _, comments := range [][]string{
+		{
+			" name: CreateFoo :one",
+			" @param foo_id UUID",
+		},
+		{
+			" name: CreateFoo :one ",
+			" @param foo_id UUID ",
+		},
+		{
+			" name: CreateFoo :one",
+			"@param foo_id UUID",
+			" invalid",
+		},
+		{
+			" name: CreateFoo :one",
+			" @invalid",
+			" @param foo_id UUID",
+		},
+		{
+			" name: GetFoos :many ",
+			" @param foo_id UUID ",
+			" @param @invalid UUID ",
+		},
+	} {
+		params, _, err := ParseParamsAndFlags(comments)
+		if err != nil {
+			t.Errorf("expected comments to parse, got err: %s", err)
+		}
+
+		pt, ok := params["foo_id"]
+		if !ok {
+			t.Errorf("expected param not found")
+		}
+
+		if pt != "UUID" {
+			t.Error("unexpected param metadata:", pt)
+		}
+
+		_, ok = params["invalid"]
+		if ok {
+			t.Errorf("unexpected param found")
+		}
+	}
+}
+
 func TestParseQueryFlags(t *testing.T) {
 	for _, comments := range [][]string{
 		{
-			"-- name: CreateFoo :one",
-			"-- @flag-foo",
+			" name: CreateFoo :one",
+			" @flag-foo",
+		},
+		{
+			" name: CreateFoo :one ",
+			"@flag-foo ",
+		},
+		{
+			" name: CreateFoo :one",
+			" @flag-foo @flag-bar",
+		},
+		{
+			" name: GetFoos :many",
+			" @param @flag-bar UUID",
+			" @flag-foo",
+		},
+		{
+			" name: GetFoos :many",
+			" @flag-foo",
+			" @param @flag-bar UUID",
 		},
 	} {
-		flags, err := ParseQueryFlags(comments)
+		_, flags, err := ParseParamsAndFlags(comments)
 		if err != nil {
-			t.Errorf("expected query flags to parse, got error: %s", err)
+			t.Errorf("expected comments to parse, got err: %s", err)
 		}
 
 		if !flags["@flag-foo"] {
 			t.Errorf("expected flag not found")
 		}
+
+		if flags["@flag-bar"] {
+			t.Errorf("unexpected flag found")
+		}
 	}
-}
\ No newline at end of file
+}