{"id":35473,"date":"2024-06-19T10:56:00","date_gmt":"2024-06-19T00:56:00","guid":{"rendered":"https:\/\/database.guide\/?p=35473"},"modified":"2024-06-19T10:56:02","modified_gmt":"2024-06-19T00:56:02","slug":"fix-function-array_shuffleinteger-integer-does-not-exist-in-postgresql","status":"publish","type":"post","link":"https:\/\/database.guide\/fix-function-array_shuffleinteger-integer-does-not-exist-in-postgresql\/","title":{"rendered":"Fix &#8220;function array_shuffle(integer, integer) does not exist&#8221; in PostgreSQL"},"content":{"rendered":"\n<p class=\"\">If you&#8217;re getting an error that reads &#8220;<em>function array_shuffle(integer, integer) does not exist<\/em>&#8221; when using the <code><a href=\"https:\/\/database.guide\/a-quick-overview-of-the-array_shuffle-function-in-postgresql\/\" data-type=\"post\" data-id=\"35446\">array_shuffle()<\/a><\/code> function in PostgreSQL, it&#8217;s probably because the argument you&#8217;re passing to the function is not an array.<\/p>\n\n\n\n<p class=\"\">Actually, the error message implies that you&#8217;re passing multiple <em>integer<\/em> values (two in this case, but it could be more), separated by a comma. Perhaps you&#8217;re trying to pass an array of integers, but you haven&#8217;t provided them in an array. Or perhaps you&#8217;re passing the wrong column or variable. Either way, the argument for this function must be an array.<\/p>\n\n\n\n<p class=\"\">To fix this error, replace the <em>integer<\/em> values with a single array value when calling the <code>array_shuffle()<\/code> function.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Example of Error<\/h2>\n\n\n\n<p class=\"\">Here&#8217;s an example of code that produces the error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT array_shuffle( 1,5 );<\/code><\/pre>\n\n\n\n<p class=\"\">Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR:  function array_shuffle(integer, integer) does not exist<br>LINE 1: SELECT array_shuffle( 1,5 );<br>               ^<br>HINT:  No function matches the given name and argument types. You might need to add explicit type casts.<\/pre>\n\n\n\n<p class=\"\">Here I passed two integers to the <code>array_shuffle()<\/code> function but it doesn&#8217;t accept such arguments. It only accepts a single array of any type.<\/p>\n\n\n\n<p class=\"\">We&#8217;d get a similar error if we passed more integers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT array_shuffle( 1,2,3,4,5 );<\/code><\/pre>\n\n\n\n<p class=\"\">Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR:  function array_shuffle(integer, integer, integer, integer, integer) does not exist<br>LINE 1: SELECT array_shuffle( 1,2,3,4,5 );<br>               ^<br>HINT:  No function matches the given name and argument types. You might need to add explicit type casts.<\/pre>\n\n\n\n<p class=\"\">The only difference is the number of times the word <code>integer<\/code> is repeated in the error message (i.e. it reflects how many integers we passed to the function).<\/p>\n\n\n\n<p class=\"\">The same error can occur even if not all arguments are integers. For example, the following example includes a <em>numeric<\/em> type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT array_shuffle( 1,2.5 );<\/code><\/pre>\n\n\n\n<p class=\"\">Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR:  function array_shuffle(integer, numeric) does not exist<br>LINE 1: SELECT array_shuffle( 1,2.5 );<br>               ^<br>HINT:  No function matches the given name and argument types. You might need to add explicit type casts.<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Solution<\/h2>\n\n\n\n<p class=\"\">To fix the problem, simply pass an array instead of an integer\/numeric value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT array_shuffle( ARRAY&#91; 1,2,3,4,5 ] );<\/code><\/pre>\n\n\n\n<p class=\"\">Sample result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> array_shuffle <br>---------------<br> {2,4,1,3,5}<\/pre>\n\n\n\n<p class=\"\">This time the function worked without error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re getting an error that reads &#8220;function array_shuffle(integer, integer) does not exist&#8221; when using the array_shuffle() function in PostgreSQL, it&#8217;s probably because the argument you&#8217;re passing to the function is not an array. Actually, the error message implies that you&#8217;re passing multiple integer values (two in this case, but it could be more), separated &#8230; <a title=\"Fix &#8220;function array_shuffle(integer, integer) does not exist&#8221; in PostgreSQL\" class=\"read-more\" href=\"https:\/\/database.guide\/fix-function-array_shuffleinteger-integer-does-not-exist-in-postgresql\/\" aria-label=\"Read more about Fix &#8220;function array_shuffle(integer, integer) does not exist&#8221; in PostgreSQL\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[169,76,10],"class_list":["post-35473","post","type-post","status-publish","format-standard","hentry","category-postgresql","tag-arrays","tag-errors","tag-how-to"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/35473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=35473"}],"version-history":[{"count":5,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/35473\/revisions"}],"predecessor-version":[{"id":35550,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/35473\/revisions\/35550"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=35473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=35473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=35473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}