Closed sasakiyori closed 2 years ago
Maybe we no need to use QueryRow for this?
Correct. In this particular example Exec
would be better.
I don't know if there are more scenarios for using the void type.
Since void
is a type that only has one value (or no values depending on how you look at it), there is no point scanning a void
type. However, if you somehow had a query that returned a real value and a void (e.g. select now(), pg_sleep(1)
) you handle the void
by passing nil
to Scan()
for the void
.
e.g.
var t time.Time
row := conn.QueryRow(context.Background(), "select now(), pg_sleep(1)")
err := row.Scan(&t, nil)
Thanks! This way to process void
is good enough.
When executing
select pg_sleep(1)
, one result row was returned. The oid type value of the result is2278
, which is avoid
type.When using pgx to exec the sql above, there is not a suited pgtype for scanning.
Maybe we no need to use
QueryRow
for this?I don't know if there are more scenarios for using the
void
type. But ifvoid
can be added into pgtype enum list, that will be better.