#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Insert records to Postgres from CSV string


    I prepare a CSV string from desktop application and post it to a PHP script and it works fine.
    Now I have to INSERT all records from a posted csv to the POSTGRES table, so ther would be some work with parsing csv variable to some array and then making a INSERTs to do the job.
    Is there a better and more simple way to do it since I don't have a lot of experience in PHP?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    does the PHP script do anything with the data? If it's just for importing, you don't need it. Simply use PostgreSQL's own import functionalities:
    http://www.postgresql.org/docs/9.2/static/sql-copy.html
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    does the PHP script do anything with the data? If it's just for importing, you don't need it. Simply use PostgreSQL's own import functionalities:
    Thank's, Jacques, I know it can be done directly within Postgres, but I post data via web, so PHP script is used to get the csv string from the web server.
    Or did you mean I should save CSV string somewhere as a temp file and do the rest of the job from Postgres?
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Um, so you have a desktop application, which sends a CSV string to a remote web server? Well, in this case keep your PHP script and use str_getcsv() to parse the CSV data.
    Last edited by Jacques1; January 1st, 2013 at 12:57 AM.

IMN logo majestic logo threadwatch logo seochat tools logo