<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Parsing/splitting query text parameter - Usage Support - Redash Discourse</title> <meta name="description" content="Hi, I am not too familiar with SQL queries but I am trying to setup a SQL redash query where I would like to parse an input query parameter. For example: I have one query parameter called model_one. This is basically a &hellip;"> <meta name="generator" content="Discourse 3.2.0.beta2-dev - https://github.com/discourse/discourse version 83621ccbe797223b48b624b00ef04f24672e1f03"> <link rel="icon" type="image/png" href="https://global.discourse-cdn.com/standard17/uploads/redash1/optimized/1X/01e20869afc0877e3e5aee0f94419b9e9bffa961_2_32x32.ico"> <link rel="apple-touch-icon" type="image/png" href="https://global.discourse-cdn.com/standard17/uploads/redash1/optimized/1X/e1838a8a0c506503a22e0c60e2334374b2895c87_2_180x180.png"> <meta name="theme-color" media="all" content="#ffffff"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover"> <link rel="canonical" href="https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606" /> <link rel="search" type="application/opensearchdescription+xml" href="https://discuss.redash.io/opensearch.xml" title="Redash Discourse Search"> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/color_definitions_base__2_8fd59ae1f286f43b3ff17996df07ea951685249d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" class="light-scheme"/> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/desktop_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="desktop" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/checklist_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="checklist" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-adplugin_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-adplugin" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-akismet_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-akismet" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-cakeday_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-cakeday" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-chat-integration_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-chat-integration" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-details_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-details" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-footnote_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-footnote" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-lazy-videos_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-lazy-videos" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-local-dates_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-local-dates" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-narrative-bot_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-narrative-bot" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-presence_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-presence" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-solved_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-solved" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/discourse-spoiler-alert_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="discourse-spoiler-alert" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/hosted-site_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="hosted-site" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/poll_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="poll" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/poll_desktop_d86c892d7cd5311243d31a8f11787f4b0342874d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="poll_desktop" /> <link href="https://sjc6.discourse-cdn.com/standard17/stylesheets/desktop_theme_2_be4cb2b86ec06123c5e974acd20fd933d14b129d.css?__ws=discuss.redash.io" media="all" rel="stylesheet" data-target="desktop_theme" data-theme-id="2" data-theme-name="default"/> <meta id="data-ga-universal-analytics" data-tracking-code="UA-47088186-6" data-json="{"cookieDomain":"auto"}" data-auto-link-domains=""> <link rel="preload" href="https://global.discourse-cdn.com/standard17/assets/google-universal-analytics-v3-08add7ec997ab472fcd9f821d32ff7caf4b8b9a5de2ec18ca723a040be07a098.gz.js" as="script"> <script defer src="https://global.discourse-cdn.com/standard17/assets/google-universal-analytics-v3-08add7ec997ab472fcd9f821d32ff7caf4b8b9a5de2ec18ca723a040be07a098.gz.js"></script> <link rel="alternate nofollow" type="application/rss+xml" title="RSS feed of 'Parsing/splitting query text parameter'" href="https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606.rss" /> <meta property="og:site_name" content="Redash Discourse" /> <meta property="og:type" content="website" /> <meta name="twitter:card" content="summary" /> <meta name="twitter:image" content="https://global.discourse-cdn.com/standard17/uploads/redash1/original/1X/e1838a8a0c506503a22e0c60e2334374b2895c87.png" /> <meta property="og:image" content="https://global.discourse-cdn.com/standard17/uploads/redash1/original/1X/e1838a8a0c506503a22e0c60e2334374b2895c87.png" /> <meta property="og:url" content="https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606" /> <meta name="twitter:url" content="https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606" /> <meta property="og:title" content="Parsing/splitting query text parameter" /> <meta name="twitter:title" content="Parsing/splitting query text parameter" /> <meta property="og:description" content="Hi, I am not too familiar with SQL queries but I am trying to setup a SQL redash query where I would like to parse an input query parameter. For example: I have one query parameter called model_one. This is basically a comma separated input model_name,run_id. Example: abcd,1234 I am trying to run a query as: SELECT run_id, model_name, username, FROM test.table WHERE (model_name LIKE SUBSTRING_INDEX('{{model_one}}', '/', 1) AND (run_id LIKE '%SUBSTRING_INDEX('{{model_one}}', ..." /> <meta name="twitter:description" content="Hi, I am not too familiar with SQL queries but I am trying to setup a SQL redash query where I would like to parse an input query parameter. For example: I have one query parameter called model_one. This is basically a comma separated input model_name,run_id. Example: abcd,1234 I am trying to run a query as: SELECT run_id, model_name, username, FROM test.table WHERE (model_name LIKE SUBSTRING_INDEX('{{model_one}}', '/', 1) AND (run_id LIKE '%SUBSTRING_INDEX('{{model_one}}', ..." /> <meta property="og:article:section" content="Support" /> <meta property="og:article:section:color" content="BF1E2E" /> <meta property="og:article:section" content="Usage Support" /> <meta property="og:article:section:color" content="AB9364" /> <meta property="og:article:tag" content="parameters" /> <meta property="article:published_time" content="2022-06-10T07:16:33+00:00" /> <meta property="og:ignore_canonical" content="true" /> <script type="application/ld+json">{"@context":"http://schema.org","@type":"QAPage","name":"Parsing/splitting query text parameter","mainEntity":{"@type":"Question","name":"Parsing/splitting query text parameter","text":"Hi, I am not too familiar with SQL queries but I am trying to setup a SQL redash query where I would like to parse an input query parameter.\n\nFor example: I have one query parameter called model_one. This is basically a comma separated input model_name,run_id. Example: abcd,1234\n\nI am trying to run …","upvoteCount":0,"answerCount":1,"dateCreated":"2022-06-10T07:16:33.243Z","author":{"@type":"Person","name":"Anjandeep Sahni"},"acceptedAnswer":{"@type":"Answer","text":"Thanks for explaining. Data source is presto db. So I was able to resolve it by using split_part.\n\n<a href=\"https://prestodb.io/docs/current/functions/string.html\" class=\"onebox\" target=\"_blank\" rel=\"noopener nofollow ugc\">https://prestodb.io/docs/current/functions/string.html<\/a>","upvoteCount":0,"dateCreated":"2022-06-15T18:11:53.627Z","url":"https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606/3","author":{"@type":"Person","name":"anjandeepsahni"}}}}</script> </head> <body class="crawler "> <header> <a href="/"> Redash Discourse </a> </header> <div id="main-outlet" class="wrap" role="main"> <div id="topic-title"> <h1> <a href="/t/parsing-splitting-query-text-parameter/10606">Parsing/splitting query text parameter</a> </h1> <div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList"> <span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> <a href="https://discuss.redash.io/c/support/6" class="badge-wrapper bullet" itemprop="item"> <span class='badge-category-bg' style='background-color: #BF1E2E'></span> <span class='badge-category clear-badge'> <span class='category-name' itemprop='name'>Support</span> </span> </a> <meta itemprop="position" content="1" /> </span> <span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> <a href="https://discuss.redash.io/c/support/support-usage/10" class="badge-wrapper bullet" itemprop="item"> <span class='badge-category-bg' style='background-color: #AB9364'></span> <span class='badge-category clear-badge'> <span class='category-name' itemprop='name'>Usage Support</span> </span> </a> <meta itemprop="position" content="2" /> </span> </div> <div class="topic-category"> <div class='discourse-tags list-tags'> <a href='https://discuss.redash.io/tag/parameters' class='discourse-tag' rel="tag">parameters</a> </div> </div> </div> <div itemscope itemtype='http://schema.org/DiscussionForumPosting'> <meta itemprop='headline' content='Parsing/splitting query text parameter'> <meta itemprop='articleSection' content='Usage Support'> <meta itemprop='keywords' content='parameters'> <div itemprop='publisher' itemscope itemtype="http://schema.org/Organization"> <meta itemprop='name' content='Redash Discourse'> <div itemprop='logo' itemscope itemtype="http://schema.org/ImageObject"> <meta itemprop='url' content='https://global.discourse-cdn.com/standard17/uploads/redash1/original/1X/c07bc573841e1e4a0013ea3b6fe088a1534228a3.png'> </div> </div> <div id='post_1' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discuss.redash.io/u/anjandeepsahni'><span itemprop='name'>anjandeepsahni</span></a> </span> <link itemprop="mainEntityOfPage" href="https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606"> <span class="crawler-post-infos"> <time itemprop='datePublished' datetime='2022-06-10T07:16:33Z' class='post-time'> June 10, 2022, 7:16am </time> <meta itemprop='dateModified' content='2022-06-10T07:16:33Z'> <span itemprop='position'>1</span> </span> </div> <div class='post' itemprop='articleBody'> <p>Hi, I am not too familiar with SQL queries but I am trying to setup a SQL redash query where I would like to parse an input query parameter.</p> <p>For example: I have one query parameter called model_one. This is basically a comma separated input model_name,run_id. Example: abcd,1234</p> <p>I am trying to run a query as:</p> <pre><code class="lang-auto">SELECT run_id, model_name, username, FROM test.table WHERE (model_name LIKE SUBSTRING_INDEX('{{model_one}}', '/', 1) AND (run_id LIKE '%SUBSTRING_INDEX('{{model_one}}', '/', 1)%')) </code></pre> <p>But this is giving me an error:</p> <pre><code class="lang-auto">Function substring_index not registered </code></pre> <p>Is it possible to split the text parameter input in query code?</p> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="0" /> <span class='post-likes'></span> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/CommentAction"/> <meta itemprop="userInteractionCount" content="1" /> </div> </div> <div id='post_2' itemprop='comment' itemscope itemtype='http://schema.org/Comment' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discuss.redash.io/u/jesse'><span itemprop='name'>jesse</span></a> </span> <link itemprop="mainEntityOfPage" href="https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606"> <span class="crawler-post-infos"> <time itemprop='datePublished' datetime='2022-06-14T17:34:05Z' class='post-time'> June 14, 2022, 5:34pm </time> <meta itemprop='dateModified' content='2022-06-14T17:34:05Z'> <span itemprop='position'>2</span> </span> </div> <div class='post' itemprop='text'> <p>There’s no reason Redash won’t support this. It just depends which database you’re querying. For example, the error you see:</p> <aside class="quote no-group" data-username="anjandeepsahni" data-post="1" data-topic="10606"> <div class="title"> <div class="quote-controls"></div> <img loading="lazy" alt="" width="20" height="20" src="https://sjc6.discourse-cdn.com/standard17/user_avatar/discuss.redash.io/anjandeepsahni/40/4109_2.png" class="avatar"> anjandeepsahni:</div> <blockquote> <p><code>Function substring_index not registered</code></p> </blockquote> </aside> <p>comes from the data source you are querying. It doesn’t have a <code>substring_index</code> function. What data source is this?</p> <aside class="quote no-group" data-username="anjandeepsahni" data-post="1" data-topic="10606"> <div class="title"> <div class="quote-controls"></div> <img loading="lazy" alt="" width="20" height="20" src="https://sjc6.discourse-cdn.com/standard17/user_avatar/discuss.redash.io/anjandeepsahni/40/4109_2.png" class="avatar"> anjandeepsahni:</div> <blockquote> <p>Is it possible to split the text parameter input in query code?</p> </blockquote> </aside> <p>That depends on whether your data source supports any kind of substring indexing.</p> <hr> <p>Side note: there appears to be a typo in the final line of your query. I believe it should be:</p> <pre><code class="lang-sql">SELECT run_id, model_name, username, FROM test.table WHERE (model_name LIKE SUBSTRING_INDEX('{{model_one}}', '/', 1) AND (run_id LIKE '%' + SUBSTRING_INDEX('{{model_one}}', '/', 1) + '%')) </code></pre> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="0" /> <span class='post-likes'></span> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/CommentAction"/> <meta itemprop="userInteractionCount" content="1" /> </div> </div> <div id='post_3' itemprop='comment' itemscope itemtype='http://schema.org/Comment' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discuss.redash.io/u/anjandeepsahni'><span itemprop='name'>anjandeepsahni</span></a> </span> <link itemprop="mainEntityOfPage" href="https://discuss.redash.io/t/parsing-splitting-query-text-parameter/10606"> <span class="crawler-post-infos"> <time itemprop='datePublished' datetime='2022-06-15T18:11:53Z' class='post-time'> June 15, 2022, 6:11pm </time> <meta itemprop='dateModified' content='2022-06-15T18:11:53Z'> <span itemprop='position'>3</span> </span> </div> <div class='post' itemprop='text'> <p>Thanks for explaining. Data source is presto db. So I was able to resolve it by using split_part.<br> <a href="https://prestodb.io/docs/current/functions/string.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://prestodb.io/docs/current/functions/string.html</a></p> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="0" /> <span class='post-likes'></span> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/CommentAction"/> <meta itemprop="userInteractionCount" content="0" /> </div> </div> </div> </div> <footer class="container wrap"> <nav class='crawler-nav'> <ul> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/' itemprop="url">Home </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/categories' itemprop="url">Categories </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/guidelines' itemprop="url">FAQ/Guidelines </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='http://redash.io/terms.html' itemprop="url">Terms of Service </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='http://redash.io/privacy.html' itemprop="url">Privacy Policy </a> </span> </li> </ul> </nav> <p class='powered-by-link'>Powered by <a href="https://www.discourse.org">Discourse</a>, best viewed with JavaScript enabled</p> </footer> </body> </html>