Array of characters in LIKE predicate

Moderator: NorbertKrupa

rajasekhart
Intermediate
Intermediate
Posts: 87
Joined: Wed Apr 25, 2012 8:10 am

Array of characters in LIKE predicate

Post by rajasekhart » Thu Nov 01, 2012 7:27 am

Hi,

Do we have the facility of searching a string as follows.

Eg: i want to retrieve the names of the members whose name begins with 'A' or 'B' or 'C'

For this i write the query as follows in sql.

select * from MEMBERS where NAME LIKE '[A-C]%'

Do we have the above facility in vertica too???

Thanks,
Raj!
Rajasekhar.T|HP ATP Vertica Big Data Solutions V1

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Array of characters in LIKE predicate

Post by id10t » Thu Nov 01, 2012 8:16 am

Hi!

As option:

Code: Select all

select * from  members where left(name,1) in ('a','b','c');
or

Code: Select all

select * from  members where REGEXP_LIKE(name, '^[a-c]');

rajasekhart
Intermediate
Intermediate
Posts: 87
Joined: Wed Apr 25, 2012 8:10 am

Re: Array of characters in LIKE predicate

Post by rajasekhart » Thu Nov 01, 2012 8:32 am

Hi Daniel,

Thats perfectly meeting my requirement.

Thanks a lot,
Raj!
Rajasekhar.T|HP ATP Vertica Big Data Solutions V1

User avatar
nnani
Master
Master
Posts: 302
Joined: Fri Apr 13, 2012 6:28 am
Contact:

Re: Array of characters in LIKE predicate

Post by nnani » Thu May 23, 2013 7:06 am

Hello Skwa,

I had a look at the specified topic and it looks good to me, but I was curious to know whether the example shown below can be modified for some different patter matching

Code: Select all

select * from  members where REGEXP_LIKE(name, '^[a-c]');
The patter matching for strings here is done where the strings start from letters ranging from a-c, In my scenario, we have different strings look for
Lets say abc%, def%, fgh%, %mno.

Can we modify the above sql for this
nnani........
Long way to go

You can check out my blogs at vertica-howto

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Array of characters in LIKE predicate

Post by id10t » Thu May 23, 2013 11:12 am

Hi!

Code: Select all

sampler=> select * from nnani ;
 id |  name  
----+--------
  1 | abc
  2 | abcxxx
  3 | xxxabc
  4 | def
  5 | defyyy
  6 | zzzdef
  7 | fgh
  8 | fgh---
  9 | ooofgh
 10 | mno
 11 | mnogo
 12 | gomno
(12 rows)

Code: Select all

sampler=> select * from nnani where regexp_like(name, '^((abc)|(def)|(fgh))|(mno)$');
 id |  name  
----+--------
  1 | abc
  2 | abcxxx
  4 | def
  5 | defyyy
  7 | fgh
  8 | fgh---
 10 | mno
 12 | gomno
(8 rows)

User avatar
nnani
Master
Master
Posts: 302
Joined: Fri Apr 13, 2012 6:28 am
Contact:

Re: Array of characters in LIKE predicate

Post by nnani » Fri May 24, 2013 9:14 am

Can we use this in a case statement.

If yes. Can you give me an example.

I tried it at my end, but it says

ERROR 4286: Operator does not exist: varchar = boolean
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts
nnani........
Long way to go

You can check out my blogs at vertica-howto

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Array of characters in LIKE predicate

Post by id10t » Fri May 24, 2013 6:43 pm

Hi!

Can you give me your "wrong" query?

Post Reply

Return to “Vertica Database Development”