Splunk Search

dbconnect returning data from 2 db's with same field names

Cuyose
Builder

Splunk doesn't seem to work with the AS operator in SQl, but rather expects you to RENAME after the query. But what do you do if the query returns the same field name in 2 dbs like this? When I try to rename off the "m.first_name" it doesnt work.

| dbquery DATABASE " SELECT m.first_name AS mFirstName,
mb.first_name AS mb_firstname
FROM DATABASE.TABLE1 m,

DATABASE.TABLE2 mb

WHERE m.id = mb.entity_id"

0 Karma
1 Solution

HiroshiSatoh
Champion

As some other threads, "AS alias" does not work properly status quo.
I have escaped that you do the following.

ex.
m.first_name+"" AS mFirstName, mb.first_name+"" AS mb_firstname

View solution in original post

rdownie
Communicator

You can use the Advanced setting when you create your lookup and rename it in the SQL query there. Then it will return as any name you want it to. I had to do this with spaces in column names which Splunk did not know how to handle and it worked great.

0 Karma

HiroshiSatoh
Champion

As some other threads, "AS alias" does not work properly status quo.
I have escaped that you do the following.

ex.
m.first_name+"" AS mFirstName, mb.first_name+"" AS mb_firstname

Cuyose
Builder

Bam this worked! Thank you!

0 Karma

HiroshiSatoh
Champion

If I could use TRIM, I want you to try and TRIM

trim(m.first_name) AS mFirstName, trim(mb.first_name) AS mb_firstname

Cuyose
Builder

The first and last names from both tables have values when just running the query against the SQL db. When adding the suggested (AS) syntax fix to the splunk dbquery the new field names are now displayed in the results from the new search but all the first and last name fields for the renamed table return 0's and not the data from the db.

0 Karma

HiroshiSatoh
Champion

What data do you missing? Regularity or is likely something?
My environment is MySQL Server 5.5.

0 Karma

Cuyose
Builder

This returns the columns now, but doesn't return any data for those renamed columns. running in sql works fine though.

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...