Yep, thanks.  I've been using RETURNING pretty extensively to get not just
the ID but other fields as well.  It's ridiculously convenient.
Unfortunately, I'm migrating to SQLite now and they don't support RETURNING
so I was trying to use the simple-result struct.  I'm not sure why I used a
Pg connection in the initial email -- senior moment, I guess.

On Wed, Apr 24, 2019 at 11:24 AM Simon Schlee <[email protected]> wrote:

>
> > (require db)
>> > (define db (postgresql-connect  ...args...))
>> > (simple-result-info (query db "insert into collaborations (name) values
>> ('foojalskdsfls')"))
>> '((insert-id . #f) (affected-rows . 1))
>>
>
> With postgresql instead of doing a plain insert you can use returning to
> return your id:
> (assuming your collaborations table has a id field that is automatically
> initialized)
>
> > (query-row db "insert into collaborations (name) values
> ('foojalskdsfls') returning id")
>
> '#(3)    ;; the id of your inserted row
>
>
> see returning in the postgres-documentation:
> https://www.postgresql.org/docs/9.5/sql-insert.html
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to