FAQ
Indeed. However, from the documentation:

// Exec executes a query that doesn't return rows, such
// as an INSERT or UPDATE.
Exec(args []Value) (Result, error)

// Exec executes a query that may return rows, such as a
// SELECT.
Query(args []Value) (Rows, error)

see:
http://golang.org/pkg/database/sql/driver/

You can see how this might encourage people to make bad assumptions
(eg. Query will never perform an INSERT).

The documentation *should* state: Both query() and exec() MUST accept and execute any valid sql statement.


~
Doug.
On Monday, April 8, 2013 9:52:56 AM UTC+8, Maxim Khitrov wrote:

On Sun, Apr 7, 2013 at 9:04 PM, Dougx <douglas...@gmail.com <javascript:>>
wrote:
How are you even supposed to run the query:

INSERT INTO PERSON (NAME) VALUES ('JACK') RETURNING ID_PERSON,
CREATION_TIME
Using the sql library? Do we use sql.Query() for this?
No~ because you can't use sql.Query() for insert statements for some
database drivers (eg. https://github.com/go-sql-driver/mysql).
I'm not familiar with this driver, but that doesn't sound like a
correct implementation. You should be able to run the same statements
with Query() and Exec(). The only difference is the return value. The
driver can also do some optimizations, such as releasing resources
early if it knows that the returned rows (if any) aren't needed. I
would expect your INSERT statement to work just fine with 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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 20 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 7, '13 at 2:29p
activeApr 12, '13 at 7:19p
posts20
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase