[Haskell-cafe] How to select last inserted record from Table Using Database.HSQL.MySQL

Steffen Schuldenzucker sschuldenzucker at uni-bonn.de
Mon Jul 25 21:02:38 CEST 2011


Hello Sergiy,

On 07/25/2011 04:54 PM, Sergiy Nazarenko wrote:
> Hi, everyone!
>
> trycon <- connect "mysql" "bigtables" "vasya" "*******"
> stmt' <- query trycon "INSERT INTO mytable (user,time,host,) VALUES
> ("Vasya","2011.07.30 11.59","foo")"
>
> I am beginner to use HSQL and I have a problem.
> I need to know row ID after INSERT into table.
>
> fetch stmt'  returned False
>
> What should I do?

This does not seem to be HSQL specific. For mysql, Google gave me 
LAST_INSERT_ID():

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id

There probably exist similar functions for other sql databases.

-- Steffen



More information about the Haskell-Cafe mailing list