<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: dbquery command with map command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/dbquery-command-with-map-command/m-p/174126#M186592</link>
    <description>&lt;P&gt;I figured out that using a subsearch ie [ ] is not ideal in most situations. Its better to use the map search="" notation and escape the quotes inside the quoted search=. &lt;/P&gt;

&lt;P&gt;Thus, this search works:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
index=log sourcetype=app_log "keyword" | rex "(?i)primary key: (?P&lt;PRIMARY_KEY&gt;[^ ]+)" | join type=outer host [ | inputlookup db_info.csv ] | dedup host, primary_key | fields SID, primary_key | map search="| dbquery $SID$ \"select column1, column2 from $SID$.table where _id = '$primary_key$'\"" | table column1, column2&lt;BR /&gt;
&lt;/PRIMARY_KEY&gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I also noticed that if you remove the last "table" command, and run it straight out, you wont see the result but Splunk displays results count. &lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 17:22:02 GMT</pubDate>
    <dc:creator>BP9906</dc:creator>
    <dc:date>2020-09-28T17:22:02Z</dc:date>
    <item>
      <title>dbquery command with map command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/dbquery-command-with-map-command/m-p/174125#M186591</link>
      <description>&lt;P&gt;Has anyone been able to use inputlookup with the map command to run multiple DB queries? &lt;/P&gt;

&lt;P&gt;When I run it, I get an error that dbquery doesnt understand database named $DATABASE$.&lt;BR /&gt;
Definitely the inputlookup returns 1 column named "DATABASE" with the database names equal to the naming I put for the database name when I run the command manually. &lt;BR /&gt;
Any ideas?&lt;BR /&gt;&lt;BR /&gt;
I found that "|append [ |dbquery ..." works too, but more than a few with a complex query makes it look like a scary splunk search. &lt;/P&gt;

&lt;P&gt;Thank you for your help.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
|inputlookup db.csv | map [ | dbquery "$DATABASE$" "select column1 from $DATABASE$.table1 where table1.last_updated_date &amp;gt;= TRUNC(SYSDATE)" ]&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:27:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/dbquery-command-with-map-command/m-p/174125#M186591</guid>
      <dc:creator>BP9906</dc:creator>
      <dc:date>2020-09-28T15:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: dbquery command with map command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/dbquery-command-with-map-command/m-p/174126#M186592</link>
      <description>&lt;P&gt;I figured out that using a subsearch ie [ ] is not ideal in most situations. Its better to use the map search="" notation and escape the quotes inside the quoted search=. &lt;/P&gt;

&lt;P&gt;Thus, this search works:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
index=log sourcetype=app_log "keyword" | rex "(?i)primary key: (?P&lt;PRIMARY_KEY&gt;[^ ]+)" | join type=outer host [ | inputlookup db_info.csv ] | dedup host, primary_key | fields SID, primary_key | map search="| dbquery $SID$ \"select column1, column2 from $SID$.table where _id = '$primary_key$'\"" | table column1, column2&lt;BR /&gt;
&lt;/PRIMARY_KEY&gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I also noticed that if you remove the last "table" command, and run it straight out, you wont see the result but Splunk displays results count. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:22:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/dbquery-command-with-map-command/m-p/174126#M186592</guid>
      <dc:creator>BP9906</dc:creator>
      <dc:date>2020-09-28T17:22:02Z</dc:date>
    </item>
  </channel>
</rss>

