[racket] How to insert array into Postgresql using DB module

From: J G Cho (gcho at fundingmatters.com)
Date: Fri Jan 4 12:08:13 EST 2013

Thank you.

If I may ask another question, what is the best way to handle
inserting a new record and fetching that ID?

Is there a better way than what I am about to do below?

;; [String] -> ID
(define (create! ... )

  (define batch!
    (lambda ()
      (define prev-id
        (query-value conn
                     "SELECT id FROM tableORDER BY id DESC LIMIT 1"))
      (query (my-conn)
             "INSERT INTO table (cols ...) VALUES ($1, $2, $3, $4, $5)"
             ...)
      ;; return assuming the ID is one greater that prev-id
      (+ 1 prev-id)))

  (call-with-transaction conn
                         batch!))

Posted on the users mailing list.