Robotframework-Database-Library icon indicating copy to clipboard operation
Robotframework-Database-Library copied to clipboard

Write query result to CSV

Open lucielavickova opened this issue 6 years ago • 2 comments

I would like to export my SQL Query result into a CSV file, would it be possible to implement such keyword? Or is there any elegant way how to do it? I find it quite hard to format the query result into a csv format.

Thank you very much Cheers, Lucie

lucielavickova avatar Feb 10 '19 18:02 lucielavickova

It can be easily added, hovewer I wonder about the approach.

We can for example:

  1. Add parameter to query keyword to save results (ie Query ${query} output_path=my_file.csv)
  2. Add new keyword that can save list of dicts results from query:
${results}    Query    SELECT * FROM users    returnAsDict=${True}
Save Results To CSV    ${results}    my_file.csv
  1. Don't add it at all since it's not strictly related to "databases" but more to data handling :) (it could be added in some extra, optional module as often useful keyword).

@amochin What do you think?

bhirsz avatar Nov 09 '23 18:11 bhirsz

I think that including this feature in the library would be too much. Increasing the complexity without a real need. With the database library you can already return query results as a dictionary - which can be written in a csv file using the CSV library or a keyword in Python.

amochin avatar Nov 11 '23 18:11 amochin