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

Improve SPACE(n) emulation where possible #10135

Closed
lukaseder opened this issue Apr 28, 2020 · 0 comments
Closed

Improve SPACE(n) emulation where possible #10135

lukaseder opened this issue Apr 28, 2020 · 0 comments

Comments

@lukaseder
Copy link
Member

As can be visualised with our new manual sections for different functions, and their emulations:
https://www.jooq.org/doc/3.14/manual/sql-building/column-expressions/string-functions/space-function/

The SPACE(n) emulation is more complicated than it needs to be in many dialects:

-- FIREBIRD
cast(rpad(' ', (char_length(' ') * 3), ' ') as varchar(4000))

-- CUBRID, H2, MARIADB, MYSQL, ASE, AURORA_MYSQL, DB2, SQLSERVER, SQLDATAWAREHOUSE, SYBASE, VERTICA
space(3)

-- INFORMIX, MEMSQL
rpad(' ', (char_length(' ') * 3), ' ')

-- HANA, INGRES, ORACLE, TERADATA
rpad(' ', (length(' ') * 3), ' ')

-- SQLITE
"replace"(hex(zeroblob(3)), '00', ' ')

-- HSQLDB, POSTGRES, AURORA_POSTGRES, COCKROACHDB, REDSHIFT
repeat(' ', 3)

It uses repeat() internally, but with a literal(' '), whose length is known by jOOQ, so the length doesn't need to be calculated dynamically.


See also: https://twitter.com/Avalanche1979/status/1255089041005056001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant