-
Notifications
You must be signed in to change notification settings - Fork 540
Add postgreSql character length functions #4121
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 postgreSql character length functions #4121
Conversation
Test for length function can be executed standalone. Test for Nullable type support is generated
Returns number of characters in the string or will return NULL if expression is NULL. In PostgreSql the following are synonymous and are Ansi Sql supported. length ( In MySql the length function is in bytes ) char_length character_length char_length is ANSI SQL Standard and the explicitly named character_length, as multibyte character counts as a single character not as bytes. Examples char_length ( text ) -> integer char_length('jose') -> 4 char_length('海豚') -> 2 char_length(NULL) -> NULL
Support for all character length functions can be used in check constraint.
lowercase to compile - not sure if this should matter
54494fd
to
8ad37f7
Compare
AFAIK there is no sql type checker. While the compiler is able to get the expected Kotlin type, eg for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Let's add MySql (and other dialects) in another PR.
Ok. To try and understand further - using a bind variable - would it be expected for the Would this work if the bind parameter is not related to a SqlColumn? Given
results in Maybe this is not supported |
Yes, this should work! Could you add it as a test? I I will take a look later. |
Shows the error Type mismatch: inferred type is String but Int? was expected
@hfhbd Thanks - Added failing test here 04ad12f This problem already existed with calling functions
Maybe it's related to this https://github.com/cashapp/sqldelight/pull/3431/files |
Thanks. |
This reverts commit 04ad12f.
I was just about to ask to revert the test. Rewriting the function implementation is another issue and properly won't make it into 2.0. |
Add postgreSql character length functions
Add fixture test for use with constraint checks
Add integration test for use with client
Returns number of characters in the string or will return NULL if expression is NULL.
PostgreSQL supports Ansi CHAR_LENGTH, CHARACTER_LENGTH.
It also supports LENGTH, which is a PostgreSQL alias for CHAR_LENGTH.
Multibyte characters count as a single character, not as bytes.
Examples
char_length ( text ) -> integer
char_length( 'jose' ) -> 4
char_length( '海豚' ) -> 2
char_length( NULL ) -> NULL
TODO
Add to MySql
❓ One question for the reviewer -- how to make the PostgreSqlTypeResolver.kt so that the char functions will type check string expressions and fail if passed a numeric?
e.g error function character_length(integer) does not exist