Created
          September 10, 2017 01:15 
        
      - 
      
 - 
        
Save mgiacomini/a81a5f86b6c072dde848ca67c9a8f798 to your computer and use it in GitHub Desktop.  
    use copy command to fast imports
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | db_conn = ActiveRecord::Base.connection.raw_connection | |
| copy_statement = 'COPY forecasts FROM STDIN' | |
| file_path = '/tmp/forecast.csv' | |
| db_conn.copy_data(copy_statement) do | |
| CSV.foreach(file_path, headers: true) do |row| | |
| db_conn.put_copy_data(row.fields + [Time.zone.now]) | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment