Check for a NULL/nil YAML value stored in a database column

By | March 4, 2014

I was trying to google for searching a database for a nil yaml value and it took me a bit so I thought I would post my findings.  Basically if you do this in the rails console:

nil.to_yaml

you’ll receive:

--- \n...\n

Kind of irritating when you’re trying to write a SQL query. So to check for a null column in the traditional sense as well as YAML, you can do so with the following query:

SELECT * FROM my_table
WHERE my_column IS NULL OR my_column = '--- 
...
'

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *