Your Question

I tried to execute a simple Raw SQL using Gorm 2.0.

Looking into the documentation there are 2 ways to pass parameters.

(1) As positional parameters:

query = "SELECT * FROM subscriptions WHERE deleted_source = ?"
db.Exec(query, "SYSTEM")

This will result in error:

syntax error at end of input (SQLSTATE 42601)

(2) As named parameters:

query = "SELECT * FROM subscriptions WHERE deleted_source = @source"
db.Exec(query, sql.Named("source", "SYSTEM"))

This will result in error:

ERROR: column "source" does not exist (SQLSTATE 42703) 

(3) But if I try PostgreSQL specific format:

query = "SELECT * FROM subscriptions WHERE deleted_source = $1"
db.Exec(query, "SYSTEM")

Then it works, but this is not what the documentation describes.

I use (latest) versions:

gorm.io/driver/postgres v1.2.3
gorm.io/gorm v1.22.5

Edit: The actual SQL that I try to execute is more complicated and it's an UPDATE statement, but I used this simple SELECT example here because the behaviour is exactly the same.

The document you expected this should be explained

https://gorm.io/docs/sql_builder.html

Expected answer

What I'm doing wrong?