When using the sqlx package in Go with a Postgres database, you may come across the following error: lastinsertid is not supported by this driver postgres This error will happen when you want to access the LastInsertId() of a newly inserted entity. In this post, I will show you how to fix this error without making any changes to your database. Let’s investigate a specific scenario where this error will occur: func CreateAppointment(appointment Appointment) int { result, err := database.Db.NamedExec("INSERT ...

Many applications are automatically tested on each commit inside a GitLab pipeline. If your application relies on a database such as PostgreSQL, it can be tempting to use an in-memory database such as H2 for tests because it is easier to set up and destroy for each execution of your test suite. While this works for simple applications, it is no longer possible once you rely on vendor-specific SQL features (e.g., usage of column types not available in H2). In ...

Bernhard Knasmüller on Software Development