HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Why is my database name truncated?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
databasewhynametruncated

Problem

I'm using MariaDB v5.x and want to return a long database's name with the query. I can successfully do this with a simple query, but with a more involved query the database name comes back truncated [34 characters]. Why does this happen and is there a way to retrieve the full, un-truncated name?

This example query works:

SELECT DATABASE() as 'database', hour as 'hour'
FROM time
WHERE hour = 1;


However, this type of query returns the truncated database name:

SELECT DATABASE() as 'database',
       t.hour as 'hour',
       d.day as 'day'
FROM   time t,
       day d
WHERE  t.day_pk = day.pk AND
       t.hour   = 1      AND
       d.day    = 22
UNION ALL
SELECT DATABASE() as 'database',
       t.hour as 'hour',
       d.day as 'day'
FROM   time t,
       day d
WHERE  t.day_pk = day.pk AND
       t.hour   = 1      AND
       d.day    = 24;


Thanks for any /all help.

D.

Solution

I can confirm that the same behaviour is present even in MariaDB 10.7.1.

The truncation appears to happen when UNION is used.

Here is a workaround - use the substring function to indicate you want the full length:

SELECT substring(database() FROM 1 FOR length(database())) AS "database"
UNION ALL
SELECT substring(database() FROM 1 FOR length(database()));

Code Snippets

SELECT substring(database() FROM 1 FOR length(database())) AS "database"
UNION ALL
SELECT substring(database() FROM 1 FOR length(database()));

Context

StackExchange Database Administrators Q#306183, answer score: 2

Revisions (0)

No revisions yet.