Search code examples
sqlitegogo-gormtransaction-isolation

near "SET": syntax error , while trying to set isolation level


I want to create a transaction in go and while doing that I get error : near "SET": syntax error. The code:

db.Exec("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;")
if err := db.Exec("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED").Error; err != nil {
    return err
}

tx:=db.Begin()

Even when omitting ";" I get the same error. I'm using sqlite3 database and gorm ORM.


Solution

  • To achieve this in SQLite you have to use pragmas.

    Does this work?

    if err := db.Exec("PRAGMA read_uncommitted = true").Error; err != nil {
        return err
    }
    
    tx:=db.Begin()