Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return TEXT instead of VARCHAR columns #583

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JelteF
Copy link
Collaborator

@JelteF JelteF commented Feb 11, 2025

In DuckDB the canonical name for an unlimited size text column is
VARCHAR1, in Postgres this is TEXT2. In DuckDB TEXT is simply
an alias for VARCHAR type, and there's no way to know what was
provided by the user. In Postgres these types are actually distinct,
although behave exactly the same for unlimited length. Basically
everyone uses TEXT instead of VARCHAR.

Currently we convert the DuckDB type to a Postgres VARCHAR. In many
cases this doesn't really matter, because pretty much all clients handle
VARCHAR and TEXT the same too. There's one place where this leaks
through though: DDL coming from a query. For example if you do a CTAS
with a DuckDB query the resulting table columns will be of type
character varying instead of text3.

TODO:

  • Should contain tests
  • Fix CREATE MATERIALIZED VIEW issue
  • MotherDuck tables should probably be synced using TEXT too.

In DuckDB the canonical name for an unlimited size text column is
`VARCHAR`[1], in Postgres this is `TEXT`[2]. In DuckDB `TEXT` is simply
an alias for `VARCHAR` type, and there's no way to know what was
provided by the user. In Postgres these types are actually distinct,
although behave exactly the same for unlimited length. Basically
everyone uses `TEXT` instead of `VARCHAR`.

Currently we convert the DuckDB type to a Postgres `VARCHAR`. In many
cases this doesn't really matter, because pretty much all clients handle
VARCHAR and TEXT the same too. There's one place where this leaks
through though: DDL coming from a query. For example if you do a CTAS
with a DuckDB query the resulting table columns will be of type
`character varying` instead of `text`[3].

[1]: https://duckdb.org/docs/sql/data_types/text.html
[2]: https://www.postgresql.org/docs/current/datatype-character.html
[3]: #556 (comment)
@@ -1,4 +1,4 @@
CREATE TABLE t(a INT, b VARCHAR);
CREATE TABLE t(a INT, b TEXT);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be some bug when creating materialized views. Without changing this type we'd get an error like this:

+ERROR:  SELECT rule's target entry 2 has different type from column "b"
+DETAIL:  SELECT target entry has type character varying, but column has type text.

That shouldn't happen, the type should be detected as text everywhere.

@JelteF JelteF added this to the 0.4.0 milestone Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant