Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert NULL value in db using Raw sql queries in rails

I am using raw sql queries in my rails application. I want to insert NULL value in one my rows, like how active record does using nil so that i will get that row when i do Table.find_by_column(nil). I tried '#{nil}' its entering as nothing db column is blank like this ' ' i want it to be NULL.

like image 986
Shilpi Agrawal Avatar asked Nov 20 '25 06:11

Shilpi Agrawal


1 Answers

You can also try this.

sql = "INSERT into table_name (r_id, r_name) VALUES (1, null)"

records_array = ActiveRecord::Base.connection.execute(sql)
like image 117
Amit Sharma Avatar answered Nov 21 '25 20:11

Amit Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!