Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
Writing Data from R to Redshift issue

I have been trying to push data created in a work space on R server back to Redshift. Using dbWriteTable(), I can successfully create the table, but the data are not being written to this newly created table and the following error is produced:

> dbWriteTable(con, c("schema", "table"), value = df,append=TRUE, 
row.names=FALSE)

Error in postgresqlpqExec(new.con, sql4) : 

  RS-DBI driver: (could not Retrieve the result : ERROR:  syntax error at or 
near "STDIN"
LINE 1: COPY "schema"."table" FROM STDIN
                                      ^
)

Notes on the code:

  • 'con' refers to the Redshift connection, the code for that in generic form is as follows:

    con <- dbConnect(drv, host="host_name",
                     port="port_id",
                     dbname="db_name",
                     user="username",
                     password="password")
    
  • I cannot give full examples with data due to restrictions on the data.

Originally, I thought it could be a permissions issue within the work space. But, I have found an extremely slow solution by creating the table using dbSendQuery() and then looping through each row of the dataframe I wish to insert into Redshift via another call to dbSendQuery(). This tells me the issue must be related to something other then permissions since I can complete the task inefficiently.

Any comments or proposals related to this error are greatly appreciated, thank you.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It looks like your client "R" application is trying to use Postgres COPY ... FROM STDIN syntax. "FROM STDIN" is not supported syntax for the Redshift COPY command, see Redshift COPY.

Options you might consider are inserting row by row (as you were doing with dbSendQuery()), but this will be slow, or outputting your data to a CSV file that can be uploaded to Amazon S3 and from there loaded using COPY with S3 as a data source (fast).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!