# Newbie issue with read/write and SQL-NULL

**URL:** https://racket.discourse.group/t/newbie-issue-with-read-write-and-sql-null/1162
**Category:** Questions & Answers
**Tags:** racket
**Created:** [July 20, 2022, 12:49pm UTC](https://racket.discourse.group/t/newbie-issue-with-read-write-and-sql-null/1162 "2022-07-20T12:49:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![KenMax](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kenmax/32/614_2.png) [@KenMax](https://racket.discourse.group/u/KenMax)
#### Post date: [July 20, 2022, 12:49pm UTC](https://racket.discourse.group/t/newbie-issue-with-read-write-and-sql-null/1162/1 "2022-07-20T12:49:41Z")

</div>

My objective is to backup and restore a MYSQL table.  
I am selecting all of the rows with (define sql-rows (query-rows...  
I am dumping them to a file with (with-output-to-file "backup.dat" (lambda () (write sql-rows)...  
This appears to work.  
I am reading the data back with (define b-up (with-input-from-file "backup.dat" (lambda () (read)...  
This fails with "read: bad syntax '#\<' when it tries to read a SQL NULL, and I am puzzled as to how to get around this. On a simple test, read and write seem to handle the SQL-NULL if I don't go via a file port, but fail if I do. Probably something basic, as I am new to Racket, but I have not been able to find an answer in hunting through the documentation, so some help would be appreciated. Thanks.

---

<div class="post-metadata">

### Author: ![ryanc](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/ryanc/32/71_2.png) [@ryanc](https://racket.discourse.group/u/ryanc)
#### Post date: [July 20, 2022, 1:16pm UTC](https://racket.discourse.group/t/newbie-issue-with-read-write-and-sql-null/1162/2 "2022-07-20T13:16:40Z")

</div>

Many of the Racket values that represent SQL scalar values are not readable (or at least do not survive write-read roundtripping). That includes the representation of `NULL`, dates and times, bit strings, geometric values, etc. But I believe all of them are serializable (see the [`racket/serialize`](https://docs.racket-lang.org/reference/serialization.html) library), so if you `write` the result of calling `serialize` on the rows and then call `deserialize` on the result of `read`, you should get back equivalent values.

---

<div class="post-metadata">

### Author: ![KenMax](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kenmax/32/614_2.png) [@KenMax](https://racket.discourse.group/u/KenMax)
#### Post date: [July 21, 2022, 1:42pm UTC](https://racket.discourse.group/t/newbie-issue-with-read-write-and-sql-null/1162/3 "2022-07-21T13:42:20Z")

</div>

Perfect! Much appreciated, that saved me a lot of head scratching.
