You can use EXPLAIN in PostgreSQL: # explain with t as (select * from mantis_user_table) update mantis_user_table b set id=id where exists (select 1 from t where t.id = b.id);
Update on mantis_user_table b (cost=23.19..41.92 rows=453 width=186) -> Hash Join (cost=23.19..41.92 rows=453 width=186) Hash Cond: (b.id = mantis_user_table.id) ... # explain with t as (select * from mantis_user_table) select id from t; Seq Scan on mantis_user_table (cost=0.00..15.44 rows=244 width=4) (1 row) And the documentation says that MySQL has something alike. If it is not a SELECT, then use ExecContext. Rich a következőt írta (2020. szeptember 15., kedd, 16:19:51 UTC+2): > I am writing a program in Go that allows users to put a query to a > database. This program uses multiple different drivers such as Postgres, > MySQL, and I want to be able to add other drivers as needed. This is > supposed to be something a user can use and depending on how the > configuration file is setup, connect to the server using the driver for > that server, as well as the configured username / password. I've integrated > it in to use my company's authentication system so that it can checks the > user's rights on the server to make sure that user has the authority to run > the commands specified. So a user can type ANY query they want -- select > update insert etc.... > > sqlrun -h mysqlsrv -e "select..." > > sqlrun -h postgressrv -e "update ..." > > -h Specifies the host and in a config file the host is configured with the > driver, default database, username, and an encrypted password, I've > integrated it in to my company's authentication system to know if the user > can execute queries at all, or read only, or can write to the database. > > So right now I pass all user given queries to sql.Query(). This works but > when the user is doing an update or insert -- I can't output the number of > rows impacted, for that I would need to use sql.Exec() > > What I want to know is if there is a way to get Rows impacted with a > query, or if there is a more comprehensive way to evaluate the query to > know if I should query or exec? I've looked into doing simple things like > look at the first word, if it's select, run query, if it's update or insert > run exec. The problem with that is the complexity of sql, you can have a > select statement that doesn't start with the word select... For example: > "WITH temporary_name AS (SELECT * FROM table_name)..." I am sure there > could be others where Insert or Update are not always the first word of the > query... > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0c5fffd0-1fe7-4b76-934e-3c57527cdc2cn%40googlegroups.com.