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

Why mix the style of functions and phrases? #66

Open
0-issue opened this issue Jul 4, 2023 · 1 comment
Open

Why mix the style of functions and phrases? #66

0-issue opened this issue Jul 4, 2023 · 1 comment

Comments

@0-issue
Copy link

0-issue commented Jul 4, 2023

Input:

select
  foo,
  bar
from
  baz
where
  foo like 'abd%'
  or foo like 'ada%' escape '!'
  or foo not like 'abd%'
  or foo not like 'ada%' escape '!'
  or foo ilike 'efg%'
  or foo ilike 'ada%' escape '!'
  or foo not ilike 'efg%'
  or foo not ilike 'ada%' escape '!'

output (cat file.sql | ./main --align --casemode lower):

select foo, bar
  from baz
 where foo like 'abd%'
    or like_escape(foo, 'ada%', '!')
    or foo not like 'abd%'
    or not_like_escape(foo, 'ada%', '!')
    or foo ilike 'efg%'
    or ilike_escape(foo, 'ada%', '!')
    or foo not ilike 'efg%'
    or not_ilike_escape(foo, 'ada%', '!');

In the following excerpt, every other line has been converted to a function. Why, does it make more sense? If not, is there a way to disable that?

    or like_escape(foo, 'ada%', '!')
    or foo not like 'abd%'
    or not_like_escape(foo, 'ada%', '!')
    or foo ilike 'efg%'
    or ilike_escape(foo, 'ada%', '!')
    or foo not ilike 'efg%'
    or not_ilike_escape(foo, 'ada%', '!')
@maddyblue
Copy link
Owner

maddyblue commented Jul 4, 2023

This is because cockroach's parser converts these to a function call node instead of leaving them in their native form with an exact representation. Ideally it would do what you describe. Cockroach could be changed so that the parser can fully roundtrip these, and its planner is the thing that converts them some lower level function call or whatever. I no longer work on the cockroach code (where the actual AST -> pretty printing logic occurs), so I'm not able to make this change.

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

No branches or pull requests

2 participants