Finding the position of a value in PostgreSQL arrays

后端 未结 3 420
萌比男神i
萌比男神i 2021-01-01 11:42

How can I get the position of a value in PostgreSQL arrays? There\'s .index() method for Python and array_search() function for PHP, but I cannot find any such function for

3条回答
  •  离开以前
    2021-01-01 12:24

    For integer arrays only you can use the greatly faster idx function from the intarray bundled extension.

    This function hasn't been generalized to support all array types yet, unfortunately, so you're stuck with a very slow SQL approach for other arrays.

提交回复
热议问题