<?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: Can not create savedsearch from a search containing sql query inside with dbxquery in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305994#M140600</link>
    <description>&lt;P&gt;I know how to run query with db connect. This query is working fine :&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;| inputlookup my_lookup.csv&lt;BR /&gt;
| eval searchquery="SELECT field1, field2  FROM mongo_collection WHERE field1 &amp;gt; ".field_constant_from_my_lookup." "&lt;BR /&gt;
| map search="|dbxquery connection=mongo_database_connection query="$searchquery$""&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;when it is run directly. &lt;BR /&gt;
But when it is run from outside with:&lt;BR /&gt;
 &lt;STRONG&gt;| savedsearch above_query_name&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;it does not work and says:&lt;BR /&gt;
&lt;STRONG&gt;Error in 'savedsearch' command: Encountered the following error while building a search for saved search 'above_query_name': Error while replacing variable name='searchquery'. Could not find variable in the argument map.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:14:57 GMT</pubDate>
    <dc:creator>harry2007gsp</dc:creator>
    <dc:date>2020-09-29T16:14:57Z</dc:date>
    <item>
      <title>Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305991#M140597</link>
      <description>&lt;P&gt;how can i use a search(ex:abc) as savedsearch when search abc contains sql query inside it?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 03:27:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305991#M140597</guid>
      <dc:creator>harry2007gsp</dc:creator>
      <dc:date>2017-10-13T03:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305992#M140598</link>
      <description>&lt;P&gt;Splunk &lt;A href="https://www.splunk.com/en_us/resources/search-processing-language.html"&gt;search processing language&lt;/A&gt; is a different language and you cannot use SQL syntax, there are documentation links from the link mentioned there which may help.&lt;/P&gt;

&lt;P&gt;Also there is a documentation page on &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SQLtoSplunk"&gt;SPL for SQL users&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 12:53:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305992#M140598</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2017-10-13T12:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305993#M140599</link>
      <description>&lt;P&gt;Alternatively if you are trying to write SPL that runs a SQL query via the DB Connect application the documentation is &lt;A href="http://docs.splunk.com/Documentation/DBX/latest/DeployDBX/Commands"&gt;here&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;An example from the documentation is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;dbxquery query="select * from actor where actor_id &amp;gt; ? and actor_name = ?" connection="mysql" params="3,BOB"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Oct 2017 13:01:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305993#M140599</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2017-10-13T13:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305994#M140600</link>
      <description>&lt;P&gt;I know how to run query with db connect. This query is working fine :&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;| inputlookup my_lookup.csv&lt;BR /&gt;
| eval searchquery="SELECT field1, field2  FROM mongo_collection WHERE field1 &amp;gt; ".field_constant_from_my_lookup." "&lt;BR /&gt;
| map search="|dbxquery connection=mongo_database_connection query="$searchquery$""&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;when it is run directly. &lt;BR /&gt;
But when it is run from outside with:&lt;BR /&gt;
 &lt;STRONG&gt;| savedsearch above_query_name&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;it does not work and says:&lt;BR /&gt;
&lt;STRONG&gt;Error in 'savedsearch' command: Encountered the following error while building a search for saved search 'above_query_name': Error while replacing variable name='searchquery'. Could not find variable in the argument map.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:14:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305994#M140600</guid>
      <dc:creator>harry2007gsp</dc:creator>
      <dc:date>2020-09-29T16:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305995#M140601</link>
      <description>&lt;P&gt;Did you try passing a dummy argument to see if that works?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| savedsearch above_query_name searchquery="dummy"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 14:27:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305995#M140601</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2017-10-13T14:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305996#M140602</link>
      <description>&lt;P&gt;With that dummy argument I get this:&lt;BR /&gt;
&lt;STRONG&gt;[map]: java.sql.SQLException: Invalid SQL statement entered.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 14:43:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305996#M140602</guid>
      <dc:creator>harry2007gsp</dc:creator>
      <dc:date>2017-10-13T14:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305997#M140603</link>
      <description>&lt;P&gt;With dbxquery , we can use sql inside spl. My problem is that the search i made is working fine with run directly but does not run when run with :&lt;BR /&gt;
&lt;STRONG&gt;|savedsearch query_name&lt;/STRONG&gt; &lt;BR /&gt;
from outside in a new search.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 14:50:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305997#M140603</guid>
      <dc:creator>harry2007gsp</dc:creator>
      <dc:date>2017-10-13T14:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create savedsearch from a search containing sql query inside with dbxquery</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305998#M140604</link>
      <description>&lt;P&gt;Hello fellows, &lt;/P&gt;

&lt;P&gt;We also had a very similar issue like described by @harry2007gsp, if we put the &lt;STRONG&gt;dbxquery&lt;/STRONG&gt; into a &lt;STRONG&gt;saved search&lt;/STRONG&gt;, we get the following error.&lt;BR /&gt;
Even though the same search worked perfectly when we run it directly.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3660i65D1DC27E00A165D/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Splunk version 7.2.7 says "Unrecognized option". After a long job inspection we figured out, Splunk automatically adds by calling saved searches "&lt;STRONG&gt;| search&lt;/STRONG&gt;" at the beginning of the line! resulting in "| search | &lt;STRONG&gt;dbxconnect&lt;/STRONG&gt; [..."&lt;BR /&gt;
And because the dbxquery has to be the first line operator, everything crashes.&lt;/P&gt;

&lt;P&gt;Original state:&lt;/P&gt;

&lt;P&gt;The call: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| savedsearch "DBXQUERY"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The saved search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbxquery [| makeresults \`getSplunkAppName\` | eval query="SELECT COUNT(*) FROM TABLE WHERE SPLUNK_APP = '".SplunkApp."'" | return query] connection="SomeDB"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The Macro (just gives the name of hte current splunk application): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval [rest /services/search/jobs splunk_server=local | addinfo | where sid = info_sid | rename eai:acl.app as SplunkApp | return SplunkApp]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And after removing the &lt;STRONG&gt;leading pipeline&lt;/STRONG&gt; in the saved search, splunk stopped to add "&lt;STRONG&gt;| search&lt;/STRONG&gt;".&lt;BR /&gt;
Also the new working saved search has bekome: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;dbxquery [| makeresults \`getSplunkAppName\` | eval query="SELECT COUNT(*) FROM TABLE WHERE SPLUNK_APP = '".SplunkApp."'" | return query] connection="SomeDB"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Mar 2020 13:50:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-not-create-savedsearch-from-a-search-containing-sql-query/m-p/305998#M140604</guid>
      <dc:creator>olex_k7</dc:creator>
      <dc:date>2020-03-02T13:50:56Z</dc:date>
    </item>
  </channel>
</rss>

