SQL to CSV

Post Reply
Dave23
Member
Posts: 41
Joined: Thu Oct 12, 2017 4:42 pm

SQL to CSV

Post by Dave23 »

Hi all,
Pretty new to this forum and switch and i was wondering if I could pick your brains.

Currently I have a flow that writes to a csv file from my sql database. I use execute command with an argument that contains select sql statements which then writes one row to my csv file. This then continues to loop until all rows have been created.

My question is, is there a way to write all the rows in one go without having to loop through row by row?

Now i'm not really clued up when it comes to creating scripts, I do however have the scripting module, but i was hoping there was a way to do this without creating a script?

Cheers
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: SQL to CSV

Post by Padawan »

Do you have the database module in Switch? If so, then you can create a CSV file from an SQL query using the "Database connect" tool.
Dave23
Member
Posts: 41
Joined: Thu Oct 12, 2017 4:42 pm

Re: SQL to CSV

Post by Dave23 »

Alright Padawan,

Yeh i do have the database module. I am currently using this to update my database once a row has been added. I was just wondering if there is a way to write multiple rows in one go rather than one row at a time? I also have the scripting module too.

Cheers
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: SQL to CSV

Post by Padawan »

Do you want to write from your database to a CSV or from a CSV to your database?

If you want to write from your database to a CSV, then you can use the "Database Connect" element. If you use an SQL statement which will return multiple rows and set the log type to CSV, then you will get a multirow CSV file in the output.

If you want to write from a CSV to a database, multiple rows at the same time, then I think you'll need a script.
Dave23
Member
Posts: 41
Joined: Thu Oct 12, 2017 4:42 pm

Re: SQL to CSV

Post by Dave23 »

alright padawan,

yeh i want to be able to write from my sql database to csv. i've tried creating a csv log but all i seem to be getting is a red cog on my database connect element which says warning job was started. you seen this before?

cheers
Dave23
Member
Posts: 41
Joined: Thu Oct 12, 2017 4:42 pm

Re: SQL to CSV

Post by Dave23 »

Me being a plonker, it was my odbc connection not configured properly. Got it working cheers mate.
Dave23
Member
Posts: 41
Joined: Thu Oct 12, 2017 4:42 pm

Re: SQL to CSV

Post by Dave23 »

Hi,
Is there a way to delete the first two rows of the log file that comes out? or disable it somehow?

Cheers
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: SQL to CSV

Post by Padawan »

It's not possible to disable it to my knowledge.

I also don't know an easy way to remove them. Scripting will work of course.

On mac you could build something using one of the tools mentioned on the following page and execute command:
https://stackoverflow.com/questions/245 ... rom-output

There is a big chance you'll need to run your command via an extra bash script in the execute command.

If you are on mac, then maybe I can build a sample when I have some time next week.
Post Reply