Search code examples
postgresqlcsvapache-nifibulkinsert

How to do BULK INSERT into PostgreSQL without specifying physical csv file in Apache NiFi


I need to do BULK INSERT into PostgreSQL table in Apache NiFi without specifying the physical csv file in COPY command. I just cannot store the CSV files on the disk and would like to do BULK INSERT using a flow file that is coming from previous processors and is already in CSV format (or I can change it to json, that's not an issue).

Please advise, what is the best way to do this in Apache NiFi?


Solution

  • PostgreSQL's COPY operation requires a path to a file. I'd recommend looking at PutDatabaseRecord which generates a PreparedStatement based on your CSV data and executes the statement in a single batch (unless Maximum Batch Size is set)