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

sql: match Postgres type conversion behavior #75101

Open
11 tasks
mgartner opened this issue Jan 18, 2022 · 1 comment
Open
11 tasks

sql: match Postgres type conversion behavior #75101

mgartner opened this issue Jan 18, 2022 · 1 comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs P-3 Issues/test failures with no fix SLA T-sql-queries SQL Queries Team

Comments

@mgartner
Copy link
Collaborator

mgartner commented Jan 18, 2022

The behavior of type conversions in CockroachDB behaves differently than Postgres in a handful of cases. The Postgres docs on type conversion are an excellent starting place for understanding how Postgres makes type conversion decisions.

Implicit Casts

Implicit casts are casts that are automatically added so that expressions can be strongly typed. For example, implicit casts allow expressions like 1::INT4 = 1::INT2 to be typed.

From the Postgres docs on type conversion:

All type conversion rules are designed with several principles in mind:

  • Implicit conversions should never have surprising or unpredictable outcomes.

  • There should be no extra overhead in the parser or executor if a query does not need implicit type conversion. That is, if a query is well-formed and the types already match, then the query should execute without spending extra time in the parser and without introducing unnecessary implicit conversion calls in the query.

  • Additionally, if a query usually requires an implicit conversion for a function, and if then the user defines a new function with the correct argument types, the parser should use this new function and no longer do implicit conversion to use the old function.

We currently have logic scattered throughout the code base that loosely mimics implicit casts, but has some rough edges. This is a meta issue to track all the work required in order to fully implement implicit casts to behave as they do in Postgres.

Another Example with Collated Strings

We also need to support implicit casts for collated strings. For example, the SQL below executes successfully in PG, but not in CRDB v22.1.

CREATE TABLE t (t TEXT COLLATE "de_DE");

SELECT * FROM t WHERE t = 'x';

Function overload resolution

The logic for determining the overload of a function is documented here. We currently differ from this behavior in several ways.

TODO

Epic CRDB-2474
Jira issue: CRDB-12461

@mgartner mgartner added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Jan 18, 2022
@mgartner mgartner added this to Triage in SQL Sessions - Deprecated via automation Jan 18, 2022
@mgartner mgartner added this to Triage in SQL Queries via automation Jan 18, 2022
@mgartner mgartner moved this from Triage to Backlog in SQL Queries Jan 18, 2022
@rafiss rafiss moved this from Triage to Longer term backlog in SQL Sessions - Deprecated Feb 14, 2022
@mgartner mgartner changed the title sql: implement implicit casts sql: match Postgres type conversion behavior Mar 21, 2022
@rafiss rafiss added the T-sql-queries SQL Queries Team label Oct 3, 2022
@mgartner mgartner moved this from Backlog to New Backlog in SQL Queries Mar 7, 2023
@rafiss rafiss added the O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs label Jun 4, 2024
@rafiss
Copy link
Collaborator

rafiss commented Jun 4, 2024

Adding the O-support label since this issue periodically comes through support channels. For example: #78083, #125025.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs P-3 Issues/test failures with no fix SLA T-sql-queries SQL Queries Team
Projects
Status: Backlog
SQL Queries
New Backlog
SQL Sessions - Deprecated
Longer term backlog
Development

No branches or pull requests

3 participants