Deployment Architecture

DB Connect Column Aliases

arrowsmith3
Path Finder

Is anyone having an issues with assigning column aliases in a mysql db?

SELECT DISTINCT
issuestatus.pname AS "Status"
FROM issuestatus

pname
1 Open
2 Assigned

AvianFLU
Explorer

If this is in the Database Input or Database Query feature - I found a workaround for this. Simply cast all the fields and it should work.

SELECT DISTINCT CAST(issuestatus.pname AS Char(32)) AS Status FROM issuestatus

monkey
Explorer

This workaround, well, works! I've been looking for a way to get aliases working for ages now and this finally does it. Thanks!

0 Karma

FloydATC
Explorer

I think I found the root cause of this problem in the README notes for MySQL J connector 5.1.x which states that .getColumnName() now always returns the original column name and the caller must use .getColumnLabel() to get the alias.

Downgrading from 5.1.4 to 3.14 solved the problem for me, although I'm sure it will cause other problems down the road. I have reported the issue to Splunk via our dealer.

0 Karma

aelliott
Motivator

Did you attempt to exclude the quotes around the Status?

0 Karma

rdevine
Path Finder

Anyone ever find a solution for this?

0 Karma

HiroshiSatoh
Champion

Do not be resolved in a way and a separate column by editing the column?

ex.
| dbquery mysql01 limit=1000 "select users.id+0 as user_id from users"

(result)
user_id
1
2
3

How about now?
SELECT DISTINCT issuestatus.pname+"" AS "Status" FROM issuestatus

yuwtennis
Communicator

I am having a same problem as well with using the 'AS' in select statement.

You cannot join multiple tables that has same column names if you cant
use the AS.

I hope there is a solution for this.

0 Karma

vrmerlin
New Member

I tried escaping the quotes as suggested, but it didn't fix the problem for me. Any other suggestions?

0 Karma

Sammich
New Member

You need to escape the quotes that are used in the column alias.
| dbquery "database" "SELECT DISTINCT issuestatus.pname AS \"Status\" FROM issuestatus"

0 Karma

wagnerbianchi
Splunk Employee
Splunk Employee

Yes, I got the same problem! Perhaps the parser is not considering convert the alias from SQL to SPL, I think...

SELECT user as username FROM mysql.user WHERE user='root';

Database Results
User
1 root
2 root

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...