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

Add --wrap_after option for wrapping identifier lists. #248

Merged
merged 1 commit into from Jun 3, 2016

Conversation

fimmtiu
Copy link
Contributor

@fimmtiu fimmtiu commented Jun 2, 2016

This pull request adds a new option, --wrap_after, which defines a column limit which it'll try not to exceed when printing identifier lists. Instead of printing each identifier in the query on its own line (very annoying for IN clauses or SELECTs for many columns!), it keeps printing them on the same line until it goes past the wrap_after amount, at which point it inserts a newline.

Before:

SELECT DISTINCT `foos`.`bar_id`
FROM `foos`
INNER JOIN `bars` ON `bars`.`id` = `foos`.`bar_id`
LEFT JOIN `honks` ON `honks`.foo_id = foos.id
LEFT JOIN `bonks` ON `bonks`.id = `honks`.bonk_id
WHERE `foos`.user_id IN (912034523,
                         912611173,
                         912611177,
                         912611179,
                         912611191,
                         912611201,
                         912611211,
                         912611397,
                         912059323,
                         912096413,
                         912101453,
                         912103173,
                         912106635,
                         912116235,
                         912481421,
                         912482243,
                         912560941,
                         912636990,
                         912637838)
  AND `honks`.type = 99
  AND bonks.state IN (1,
                      2,
                      3,
                      4)
  AND (`bars`.group_id IN (31331,
                           31333))
  AND (monkey_id IS NOT NULL
       AND bars.group_id IS NOT NULL
       and LENGTH(bars.description) > 0)
  AND `bars`.`enabled` = 1;

After (using --wrap-after=80):

SELECT DISTINCT `foos`.`bar_id`
FROM `foos`
INNER JOIN `bars` ON `bars`.`id` = `foos`.`bar_id`
LEFT JOIN `honks` ON `honks`.foo_id = foos.id
LEFT JOIN `bonks` ON `bonks`.id = `honks`.bonk_id
WHERE `foos`.user_id IN (912034523,912611173,912611177,912611179,912611191,912611201,
                         912611211,912611397,912059323,912096413,912101453,912103173,
                         912106635,912116235,912481421,912482243,912560941,912636990,
                         912637838)
  AND `honks`.type = 99
  AND bonks.state IN (1,2,3,4)
  AND (`bars`.group_id IN (31331,31333))
  AND (monkey_id IS NOT NULL
       AND bars.group_id IS NOT NULL
       and LENGTH(bars.description) > 0)
  AND `bars`.`enabled` = 1;

@fimmtiu
Copy link
Contributor Author

fimmtiu commented Jun 2, 2016

Addendum: Just wanted to say how useful this tool is, and how easy it was to read and modify your code. Thanks very much!

@andialbrecht andialbrecht added this to the 0.2.0 milestone Jun 3, 2016
@andialbrecht andialbrecht merged commit 12d9aee into andialbrecht:master Jun 3, 2016
@andialbrecht
Copy link
Owner

woot! Thanks! That was an often requested feature!

ovr pushed a commit to cube-js/sqlparse that referenced this pull request Dec 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants