{"id":249,"date":"2020-01-14T01:38:37","date_gmt":"2020-01-14T01:38:37","guid":{"rendered":"https:\/\/snowflake.pavlik.us\/?p=249"},"modified":"2020-01-16T00:53:44","modified_gmt":"2020-01-16T00:53:44","slug":"snowflake-udf-to-get-payment-card-type","status":"publish","type":"post","link":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/","title":{"rendered":"Snowflake UDF to Get Payment Card Type"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg\" alt=\"Payment Cards\" class=\"wp-image-251\" width=\"420\" height=\"263\" srcset=\"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg 640w, https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards-300x188.jpg 300w\" sizes=\"auto, (max-width: 420px) 100vw, 420px\" \/><\/figure><\/div>\n\n\n\n<p>This User Defined Function (UDF) doesn&#8217;t require much explanation. Payment card number goes in; payment card type comes out. Since it is designed for speed, it does not validate the check digit. A subsequent post will provide a UDF to validate the check digit using the Luhn algorithm.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n\/********************************************************************************************************************\n\nFunction:    PaymentCardType\nDescription: Decodes the type of payment card from Visa, Mastercard, AMEX, etc.\nParameters:  A string indicating the type of payment card, or a blank string if not identified. \n\n*********************************************************************************************************************\/\ncreate or replace function PaymentCardType(cardNumber string)\n  returns string \n  language javascript\n  strict\n  as &#039;\n     \n    \/\/Remove all spaces and dashes. Simply ignore them.\n    NUMBER = CARDNUMBER.replace(\/ \/g, &quot;&quot;);\n    NUMBER = NUMBER.replace(\/-\/g, &quot;&quot;);\n     \n     \n    \/\/ Visa\n    var re = new RegExp(&quot;(4&#x5B;0-9]{15})&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;Visa&quot;;\n\n    \/\/ Mastercard\n    re = new RegExp(&quot;(5&#x5B;1-5]&#x5B;0-9]{14})&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;Mastercard&quot;;\n\n    \/\/ AMEX\n    re = new RegExp(&quot;^3&#x5B;47]&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;AMEX&quot;;\n\n    \/\/ Discover\n    re = new RegExp(&quot;^(6011|622(12&#x5B;6-9]|1&#x5B;3-9]&#x5B;0-9]|&#x5B;2-8]&#x5B;0-9]{2}|9&#x5B;0-1]&#x5B;0-9]|92&#x5B;0-5]|64&#x5B;4-9])|65)&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;Discover&quot;;\n\n    \/\/ Diners\n    re = new RegExp(&quot;^36&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;Diners&quot;;\n\n    \/\/ Diners - Carte Blanche\n    re = new RegExp(&quot;^30&#x5B;0-5]&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;Diners - Carte Blanche&quot;;\n\n    \/\/ JCB\n    re = new RegExp(&quot;^35(2&#x5B;89]|&#x5B;3-8]&#x5B;0-9])&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;JCB&quot;;\n\n    \/\/ Visa Electron\n    re = new RegExp(&quot;^(4026|417500|4508|4844|491(3|7))&quot;);\n    if (NUMBER.match(re) != null)\n        return &quot;Visa Electron&quot;;\n\n    return &quot;&quot;;\n \n  &#039;;\n\n-- Test the UDF:\nselect PaymentCardType(&#039;4470653497431234&#039;);\n<\/pre><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This User Defined Function (UDF) doesn&#8217;t require much explanation. Payment card number goes in; payment card type comes out. Since it is designed for speed, it does not validate the check digit. A subsequent post will provide a UDF to validate the check digit using the Luhn algorithm.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2,1],"tags":[27,28,29],"class_list":["post-249","post","type-post","status-publish","format-standard","hentry","category-functions","category-sql","category-uncategorized","tag-credit-card","tag-payment-card","tag-pci"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\r\n<title>Snowflake UDF to Get Payment Card Type - Snowflake in the Carolinas<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Snowflake UDF to Get Payment Card Type - Snowflake in the Carolinas\" \/>\r\n<meta property=\"og:description\" content=\"This User Defined Function (UDF) doesn&#8217;t require much explanation. Payment card number goes in; payment card type comes out. Since it is designed for speed, it does not validate the check digit. A subsequent post will provide a UDF to validate the check digit using the Luhn algorithm.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/\" \/>\r\n<meta property=\"og:site_name\" content=\"Snowflake in the Carolinas\" \/>\r\n<meta property=\"article:published_time\" content=\"2020-01-14T01:38:37+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2020-01-16T00:53:44+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg\" \/>\r\n\t<meta property=\"og:image:width\" content=\"640\" \/>\r\n\t<meta property=\"og:image:height\" content=\"401\" \/>\r\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\r\n<meta name=\"author\" content=\"Greg Pavlik\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Greg Pavlik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/\"},\"author\":{\"name\":\"Greg Pavlik\",\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/#\\\/schema\\\/person\\\/019455f4675665b6cf5edea31ec44d7b\"},\"headline\":\"Snowflake UDF to Get Payment Card Type\",\"datePublished\":\"2020-01-14T01:38:37+00:00\",\"dateModified\":\"2020-01-16T00:53:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/\"},\"wordCount\":56,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/snowflake.pavlik.us\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/credit_cards.jpg\",\"keywords\":[\"Credit Card\",\"Payment Card\",\"PCI\"],\"articleSection\":[\"Functions\",\"SnowSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/\",\"url\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/\",\"name\":\"Snowflake UDF to Get Payment Card Type - Snowflake in the Carolinas\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/snowflake.pavlik.us\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/credit_cards.jpg\",\"datePublished\":\"2020-01-14T01:38:37+00:00\",\"dateModified\":\"2020-01-16T00:53:44+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/#\\\/schema\\\/person\\\/019455f4675665b6cf5edea31ec44d7b\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#primaryimage\",\"url\":\"https:\\\/\\\/snowflake.pavlik.us\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/credit_cards.jpg\",\"contentUrl\":\"https:\\\/\\\/snowflake.pavlik.us\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/credit_cards.jpg\",\"width\":640,\"height\":401,\"caption\":\"Payment Cards\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/index.php\\\/2020\\\/01\\\/14\\\/snowflake-udf-to-get-payment-card-type\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/snowflake.pavlik.us\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Snowflake UDF to Get Payment Card Type\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/#website\",\"url\":\"https:\\\/\\\/snowflake.pavlik.us\\\/\",\"name\":\"Snowflake in the Carolinas\",\"description\":\"Random thoughts on all things Snowflake in the Carolinas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/snowflake.pavlik.us\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/snowflake.pavlik.us\\\/#\\\/schema\\\/person\\\/019455f4675665b6cf5edea31ec44d7b\",\"name\":\"Greg Pavlik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d81df729eebf37a042922b17d4a4c834b1e0ccfa9fea1c2c78cb8e95c7e91701?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d81df729eebf37a042922b17d4a4c834b1e0ccfa9fea1c2c78cb8e95c7e91701?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d81df729eebf37a042922b17d4a4c834b1e0ccfa9fea1c2c78cb8e95c7e91701?s=96&d=mm&r=g\",\"caption\":\"Greg Pavlik\"},\"description\":\"Greg is a Senior Sales Engineer at Snowflake Computing, in the Raleigh-Durham area. He's been in data management and security for the twenty years.\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Snowflake UDF to Get Payment Card Type - Snowflake in the Carolinas","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/","og_locale":"en_US","og_type":"article","og_title":"Snowflake UDF to Get Payment Card Type - Snowflake in the Carolinas","og_description":"This User Defined Function (UDF) doesn&#8217;t require much explanation. Payment card number goes in; payment card type comes out. Since it is designed for speed, it does not validate the check digit. A subsequent post will provide a UDF to validate the check digit using the Luhn algorithm.","og_url":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/","og_site_name":"Snowflake in the Carolinas","article_published_time":"2020-01-14T01:38:37+00:00","article_modified_time":"2020-01-16T00:53:44+00:00","og_image":[{"width":640,"height":401,"url":"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg","type":"image\/jpeg"}],"author":"Greg Pavlik","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Greg Pavlik","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#article","isPartOf":{"@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/"},"author":{"name":"Greg Pavlik","@id":"https:\/\/snowflake.pavlik.us\/#\/schema\/person\/019455f4675665b6cf5edea31ec44d7b"},"headline":"Snowflake UDF to Get Payment Card Type","datePublished":"2020-01-14T01:38:37+00:00","dateModified":"2020-01-16T00:53:44+00:00","mainEntityOfPage":{"@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/"},"wordCount":56,"commentCount":0,"image":{"@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#primaryimage"},"thumbnailUrl":"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg","keywords":["Credit Card","Payment Card","PCI"],"articleSection":["Functions","SnowSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/","url":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/","name":"Snowflake UDF to Get Payment Card Type - Snowflake in the Carolinas","isPartOf":{"@id":"https:\/\/snowflake.pavlik.us\/#website"},"primaryImageOfPage":{"@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#primaryimage"},"image":{"@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#primaryimage"},"thumbnailUrl":"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg","datePublished":"2020-01-14T01:38:37+00:00","dateModified":"2020-01-16T00:53:44+00:00","author":{"@id":"https:\/\/snowflake.pavlik.us\/#\/schema\/person\/019455f4675665b6cf5edea31ec44d7b"},"breadcrumb":{"@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#primaryimage","url":"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg","contentUrl":"https:\/\/snowflake.pavlik.us\/wp-content\/uploads\/2020\/01\/credit_cards.jpg","width":640,"height":401,"caption":"Payment Cards"},{"@type":"BreadcrumbList","@id":"https:\/\/snowflake.pavlik.us\/index.php\/2020\/01\/14\/snowflake-udf-to-get-payment-card-type\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/snowflake.pavlik.us\/"},{"@type":"ListItem","position":2,"name":"Snowflake UDF to Get Payment Card Type"}]},{"@type":"WebSite","@id":"https:\/\/snowflake.pavlik.us\/#website","url":"https:\/\/snowflake.pavlik.us\/","name":"Snowflake in the Carolinas","description":"Random thoughts on all things Snowflake in the Carolinas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/snowflake.pavlik.us\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/snowflake.pavlik.us\/#\/schema\/person\/019455f4675665b6cf5edea31ec44d7b","name":"Greg Pavlik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d81df729eebf37a042922b17d4a4c834b1e0ccfa9fea1c2c78cb8e95c7e91701?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d81df729eebf37a042922b17d4a4c834b1e0ccfa9fea1c2c78cb8e95c7e91701?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d81df729eebf37a042922b17d4a4c834b1e0ccfa9fea1c2c78cb8e95c7e91701?s=96&d=mm&r=g","caption":"Greg Pavlik"},"description":"Greg is a Senior Sales Engineer at Snowflake Computing, in the Raleigh-Durham area. He's been in data management and security for the twenty years."}]}},"_links":{"self":[{"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/posts\/249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/comments?post=249"}],"version-history":[{"count":3,"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/posts\/249\/revisions"}],"predecessor-version":[{"id":253,"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/posts\/249\/revisions\/253"}],"wp:attachment":[{"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/media?parent=249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/categories?post=249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/snowflake.pavlik.us\/index.php\/wp-json\/wp\/v2\/tags?post=249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}