Função JSON_EXTRACT_ARRAY_ELEMENT_TEXT - AWS Clean Rooms

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Função JSON_EXTRACT_ARRAY_ELEMENT_TEXT

A função JSON_EXTRACT_ARRAY_ELEMENT_TEXT retorna um elemento de array JSON no array mais externa de uma string JSON, usando um índice baseado em zero. O primeiro elemento em uma matriz fica na posição 0. Se o índice for negativo ou estiver fora do limite, JSON_EXTRACT_ARRAY_ELEMENT_TEXT retornará uma string vazia. Se o argumento null_if_invalid for definido como true e a string JSON for inválida, a função retornará NULL, em vez de retornar um erro.

Para obter mais informações, consulte Funções JSON.

Sintaxe

json_extract_array_element_text('json string', pos [, null_if_invalid ] )

Argumentos

json_string

Uma string JSON adequadamente formatada.

pos

Um número inteiro que representa o índice do elemento da matriz a ser retornado, usando um índice de matriz baseado em zero.

null_if_invalid

Um valor booliano que especifica se NULL será ou não retornado caso a string de entrada JSON seja inválida, em vez de retornar um erro. Para retornar NULL se JSON for inválido, especifique true (t). Para retornar um erro se JSON for inválido, especifique false (f). O padrão é false.

Tipo de retorno

Uma string VARCHAR que representa o elemento de matriz JSON referenciado por pos.

Exemplo

O exemplo a seguir retorna o elemento da posição 2 da matriz, que é o terceiro elemento de um índice de matriz baseado em zero:

select json_extract_array_element_text('[111,112,113]', 2); json_extract_array_element_text ------------------------------- 113

O exemplo a seguir retornará um erro porque JSON é inválido.

select json_extract_array_element_text('["a",["b",1,["c",2,3,null,]]]',1); An error occurred when executing the SQL command: select json_extract_array_element_text('["a",["b",1,["c",2,3,null,]]]',1)

O exemplo a seguir define null_if_invalid como true; portanto, a instrução retornará NULL, em vez de retornar um erro para o JSON inválido.

select json_extract_array_element_text('["a",["b",1,["c",2,3,null,]]]',1,true); json_extract_array_element_text -------------------------------