Assuming these two tables:

CREATE TABLE reports (csv BYTEA);

Is it possible to (pseudocode):

INSERT INTO reports (csv) (SELECT to_csv(SELECT day, kpi FROM data));

with the result being a CSV stored as BYTEA in table reports, column csv?

I specifically do not want to go through the filesystem (COPY, etc.).

  • Please do not crosspost. Also asked here: stackoverflow.com/questions/55738331 – a_horse_with_no_name Apr 18 '19 at 5:28
  • Thanks! Is it best to migrate the original question or delete it? I think this community is a better fit. – crdb Apr 18 '19 at 5:48
  • Why do you want to do that? Is it just storing your CSVs? If so, wouldn't it be better to store them on the filesystem? – dezso Apr 18 '19 at 8:48
  • The CSV data has to be stored back to the database where it will be picked up by a web application, and the web application cannot be modified to produce the CSV itself. The database user does not have access to the filesystem, but it can define functions and triggers. – crdb Apr 18 '19 at 9:17
  • 1
    Yes, it's possible but you need to write the to_csv function, and first, decide what are going to be its argument(s). – Daniel Vérité Apr 18 '19 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.