Em 21 de julho de 2011 16:35, Marcelo Silva (IG) <[email protected]> escreveu: > Pessoal, tenho o seguinte select > > SELECT * FROM TABELA > WHERE (CAMPO1 LIKE ‘STRING_A%’) > OR(CAMPO1 LIKE ‘STRING_B%’) > OR(CAMPO1 LIKE ‘STRING_C%’) > > Observe que tenho que fazer varios ORs com Like porque as strings são o > inicio de palavras > > Sei que o IN(‘STR_A’,’STR_B’,’STR_C’) > seria mais eficiente e elegante, porem ele só me dá a opcao de string fixa > Existe outra forma de fazer o Select acima ? > Seria algo do tipo > > SELECT * FROM TABELA > WHERE (CAMPO1 IN(‘STR_A%’,’STR_B%’,’STR_C%’)) >
SELECT * FROM TABELA WHERE (CAMPO1 ~* ‘^(STR_A|STR_B|STR_C).*’); ou, para este caso particular: SELECT * FROM TABELA WHERE (CAMPO1 ~* ‘^STR_(A|B|C).*’); Osvaldo http://www.postgresql.org/docs/current/interactive/functions-matching.html#FUNCTIONS-POSIX-REGEXP _______________________________________________ pgbr-geral mailing list [email protected] https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
