SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Splitting a Column into New Columns

    What would be the best way to split a column (say, cityState) into two new columns (city and state) about a certain delimiter (namely, a tab)?

    Edit: I might mention that this is going to be done in PostgreSQL... That may help *slaps forehead*
    Ryan

  2. #2
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by a tab? Splitting one value into two columns is as simple as creating two extra columns (city and state) and modifying the db to work like this.
    Ryan Butler

    Midwest Web Design

  3. #3
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have this:

    Seattle\tWashington

    And I want to run an SQL query or some kind of PostgreSQL command to split that field (cityState) into (city = Seattle, state = Washington).

    All of my data is already there, I just want to split it. Does that make sense?
    Ryan

  4. #4
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Initially thinking look up the REPLACE function. Never dealt with PostGre db, so not sure if that's an option. Either that, or you're going to have to split the data using a server side language. Did it before with .NET. What language are you using PHP?

    If you need additional help, I should be around tomorrow.
    Ryan Butler

    Midwest Web Design

  5. #5
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, I'm finally just doing it (well, at this point, have done it) with PHP. I was just trying to find a more elegant solution, since it's a somewhat hefty database.

    Thanks
    Ryan


Bookmarks

Posting Permissions

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