I've tried to do a native query with Spring Boot using all(array[])
function, however, I couldn't make it correctly. I don't know the quantity of Strings that I'll pass, it's a dynamic quantity. Can you guys help me on this, please?
I've tried using List<String>
, String[]
and just String
as below:
passing
String
and in the queryall(array[:texto])
: no errors, however, no results.passing
List<String>
and in the queryall(array[:texto])
:
org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying ~~* record
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
- passing
String[]
and in the queryall(array[:texto])
:
org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying ~~* bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
- passing
String[]
and in the queryall(array[CAST(:texto AS TEXT)])
: no errors, however, no results.
@Query(value="SELECT * FROM Tag WHERE nome ILIKE all(array[:texto])", nativeQuery=true)
public List<Tag> findPacotesByTexto(@Param("texto") List<String> texto);
EDITED:
@Entity
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)
private String nome;
@ManyToOne
@JsonIgnore
@JoinColumn(name="pacote_id")
private Pacote pacote;
Tag() {
}
public Tag (String nome, Pacote pacote) {
this.nome = nome;
this.pacote = pacote;
}
public long getId() {
return id;
}
public String getNome() {
return nome;
}
public Pacote getPacote() {
return pacote;
}
}
How can I make this work?
Thanks in advance.