From 8229e38b9ef436c9a7d5d3fea76166a9b8559c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Thomaz?= Date: Tue, 5 Mar 2024 20:00:27 -0300 Subject: [PATCH 1/3] feat(datatypes): improve details on TEXT --- docs/reference/datatypes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/reference/datatypes.md b/docs/reference/datatypes.md index bca076eaae..d367bc549b 100644 --- a/docs/reference/datatypes.md +++ b/docs/reference/datatypes.md @@ -204,6 +204,10 @@ type Book struct { } ``` +## TEXT + +For PostgreSQL, when you have a column with the `TEXT` type, sqlc will map it to `pgtype.Text` by default. If you want to use it as a string in your Golang application, you will need to override it. The `TEXT` datatype is an unlimited size VARCHAR, so, for this reason, if you want to map the `TEXT` SQL datatype to a Golang `string`, you must set the option `pointer: true` in your overrides config. The same applies to MySQL and other supported SQL databases. + ## Geometry ### PostGIS From 7f2eab6f00491501024cf7ade8b32b479017637d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Thomaz?= Date: Wed, 6 Mar 2024 18:03:41 -0300 Subject: [PATCH 2/3] docs(datatypes): correct nullable TEXT description --- docs/reference/datatypes.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/reference/datatypes.md b/docs/reference/datatypes.md index d367bc549b..d154749ed0 100644 --- a/docs/reference/datatypes.md +++ b/docs/reference/datatypes.md @@ -206,7 +206,11 @@ type Book struct { ## TEXT -For PostgreSQL, when you have a column with the `TEXT` type, sqlc will map it to `pgtype.Text` by default. If you want to use it as a string in your Golang application, you will need to override it. The `TEXT` datatype is an unlimited size VARCHAR, so, for this reason, if you want to map the `TEXT` SQL datatype to a Golang `string`, you must set the option `pointer: true` in your overrides config. The same applies to MySQL and other supported SQL databases. +In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a Go string by default. This default mapping applies to `TEXT` columns that are not nullable. However, for nullable `TEXT` columns, sqlc maps them to `pgtype.Text` when using the pgx/v5 driver. This distinction is crucial for developers looking to handle null values appropriately in their Go applications. + +To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in you sqlc config file. + +This behavior is consistent across other supported SQL databases by sqlc, not just PostgreSQL. ## Geometry From db115689738954f9d824659dc0609f8d15b4bb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Thomaz?= Date: Wed, 6 Mar 2024 18:10:25 -0300 Subject: [PATCH 3/3] docs(datatypes): remove incorrect assumption --- docs/reference/datatypes.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/reference/datatypes.md b/docs/reference/datatypes.md index d154749ed0..42eb4cff9b 100644 --- a/docs/reference/datatypes.md +++ b/docs/reference/datatypes.md @@ -210,8 +210,6 @@ In PostgreSQL, when you have a column with the TEXT type, sqlc will map it to a To accommodate nullable strings and map them to `*string` in Go, you can use the `emit_pointers_for_null_types` option in your sqlc configuration. This option ensures that nullable SQL columns are represented as pointer types in Go, allowing for a clear distinction between null and non-null values. Another way to do this is by passing the option `pointer: true` when you are overriding the `TEXT` datatype in you sqlc config file. -This behavior is consistent across other supported SQL databases by sqlc, not just PostgreSQL. - ## Geometry ### PostGIS