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

Pading strings with spaces to longest string in queries with union [CORE5916] #6174

Closed
firebird-automations opened this issue Sep 19, 2018 · 4 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Wojtek (dlpl)

I have query using union all to add many records to database at one time. But in each varchar field spaces are added at the end.
There is a sample demonstrating problem:

SELECT
COL,
REPLACE(COL, ' ', '.'),
CHAR_LENGTH(COL),
CHAR_LENGTH(TRIM(COL))

FROM
(
SELECT 'a' AS COL FROM RDB$DATABASE
UNION ALL
SELECT 'bbbbbbb' FROM RDB$DATABASE
UNION ALL
SELECT 'cc' FROM RDB$DATABASE
)

And result:

COL REPLACE CHAR_LENGTH CHAR_LENGTH1
a a...... 7 1
bbbbbbb bbbbbbb 7 7
cc cc..... 7 2

@firebird-automations
Copy link
Collaborator Author

Commented by: @aafemt

You have no VARCHARs in your example, only CHARs. And yes, CHAR fields are padded with spaces by definition.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

String literals are type CHAR, not VARCHAR, and as a result they are padded with spaces.

@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

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