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/sem/tree: fix tuple pretty print when tuple has 1 element #135938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tigrato
Copy link

@tigrato tigrato commented Nov 21, 2024

When using sql/sem/tree.Tuple to generate SQL statements for IN operators, the produced output is incorrect if the tuple only has one element. The output includes an extra ,.

As an example, the following

&tree.Tuple{
        Exprs: []tree.Expr{
                tree.NewStrVal("val1"),
        },
}

Is incorrectly mapped to ('val1',) instead of ('val1').

Because of the extra ,, sql parsers fail to parse the input.

This commit aims to fix these conditions and remove the trailing ,.

@tigrato tigrato requested a review from a team as a code owner November 21, 2024 19:59
Copy link

blathers-crl bot commented Nov 21, 2024

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added the O-community Originated from the community label Nov 21, 2024
@cockroach-teamcity
Copy link
Member

cockroach-teamcity commented Nov 21, 2024

CLA assistant check
All committers have signed the CLA.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@tigrato tigrato changed the title sql/sem/tree: fix tupple pretty print when tupple has 1 element sql/sem/tree: fix tupple pretty print when tuple has 1 element Nov 21, 2024
@tigrato tigrato changed the title sql/sem/tree: fix tupple pretty print when tuple has 1 element sql/sem/tree: fix tuple pretty print when tuple has 1 element Nov 21, 2024
When using `sql/sem/tree.Tuple` to generate SQL statements for IN
operators, the produced output is incorrect if the tupple only has one
element. The output includes an extra `,`.

As an example, the following

```go
&tree.Tuple{
        Exprs: []tree.Expr{
                tree.NewStrVal("val1"),
        },
}

```

Is incorrectly mapped to `('val1',)` instead of `('val1')`.

Because of the extra `,`, sql parsers fail to parse the input.

This commit aims to fix these conditions and remove the trailing `,`.

Fixes cockroachdb#135939

release note (bug fix): Fixed a bug that caused `pkg/sql/sem/tree.Tuple`
to generate invalid SQL statements when the tuple only has one element.
Copy link

blathers-crl bot commented Nov 21, 2024

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants