Results 1 to 4 of 4

Thread: String split

  1. #1
    Join Date
    Oct 2003
    Posts
    18

    Unanswered: String split

    Does postgresql support string split and return the result as an array?

    something like this.
    String idsText= "5-10-20"
    String[] ids = split(idsText, '-')

    SELECT * FROM tablename WHERE id = ids

    Thx in advance

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    No, but you could write a function in PL/pgSQL to do it.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    string_to_array seems to be what you want:

    See:
    http://www.postgresql.org/docs/8.1/s...ons-array.html
    http://www.postgresql.org/docs/8.1/static/arrays.html

    Your example would be:

    Code:
    SELECT * 
    FROM tablename
    WHERE id = any(string_to_array('5-10-20', '-'))
    Last edited by shammat; 12-18-06 at 19:25.

  4. #4
    Join Date
    Oct 2003
    Posts
    18
    Thx shammat.

    It just what i need

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •