An sql query that return values of a feld alternatively

Hello,
I have a table in postgresql database named Object with 3 fields ID, TYPE and DATE.
Infact, i need an sql query wich bring back values of the field of the field ‘TYPE’ which has the type list of strings , and at the same time I would like taht the query execute an alternative search on the list of strings wich is explained in an example as below :
An altrenative serach means that if I want the query to display the strings : ‘a’ and ‘b’ i have to fix it from the begining . after that while looping the list if I found the string ‘a’ , the last one would be displayed , and if I cotinue and I found it again it won’t be dispalyed or recovered if I didn’t yet find the string ‘b’ , and the query continue to recover the ‘a’ and ‘b’ so on until not finding the next ‘a’ or ‘b’ :

Example : if the field ‘TYPE’ has the value : [‘a’,‘a’,‘b’,‘c’,‘a’,‘b’,‘b’] then the query return :
[‘a’,‘b’,‘a’,‘b’]
May be the functions ‘regexp_replace’ and ‘intsr’ would help ain’t ?
Thank you for your answers ?
Best regards ?

I’m not really sure I understand what you are doing, but

Dim s() As String = Split(rs.Field(“TYPE”).getString, “,”)
Now you have them in an array, use every other 1

Dim myString As String
For counter As Integer = 0 to Ubound(s) STEP 2
myString = myString + s(counter)
Next counter

thank your for your suggestion :slight_smile:
In fact I am looking for an sql query with postgresql to solve the problem not for a function . thank you for any other suggestion :slight_smile:

I would personally do this in Xojo to make things simpler but if you want to do it in the db I think you’ll need a cursor: http://www.postgresql.org/docs/9.2/static/plpgsql-cursors.html