activerecord-import icon indicating copy to clipboard operation
activerecord-import copied to clipboard

Output SQL as string

Open lancecarlson opened this issue 12 years ago • 6 comments

It would be nice if there was a method like import_to_sql or something that would return the SQL string and not run the command against the database.

I'm not sure if this is the case, but I have a hunch that it would be less overhead for Ruby to output the SQL string to a file so that I can use mysql < the_outputted.sql to import the file.

Thoughts?

lancecarlson avatar May 16 '12 03:05 lancecarlson

@lancecarlson, thanks for the suggestion. This sounds like a reasonable feature of activerecord-import. If you'd like to take a stab and submit a pull request I'd be happy to review and merge in; otherwise, you'll have to wait for me to get some free time.

zdennis avatar May 18 '12 03:05 zdennis

:+1: I like this for debugging. Nice suggestion.

findchris avatar Dec 18 '12 20:12 findchris

I like this idea a lot. I think I'd need to refactor before introducing this as there's not a great way to do this now.

zdennis avatar Feb 16 '13 18:02 zdennis

I hit a strange bug after switching from mysql to postgresql. null is sent as a primary key value. and I'd like to find out where the SQL is being generated. now I am getting this error.

ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, ...

any help would be much appreciated.

this feature request could help, that's why I decided to post here, not knowing where else I can get help.

mathieujobin avatar Apr 19 '17 13:04 mathieujobin

Love this idea -- has this been implemented?

breathe avatar Oct 09 '20 20:10 breathe

@breathe nope it is still open. Like Zach mentioned above, I don't think the current implementation will make this an easy update, but if you're interested in working on it that would be awesome. I'm thinking an option like :preview_sql would be my preference vs a new method.

jkowens avatar Oct 09 '20 21:10 jkowens