Add en/0.5.x.md syntax highlighting
This commit is contained in:
16
en/05.4.md
16
en/05.4.md
@@ -15,7 +15,7 @@ I will use the first one in the examples that follow.
|
||||
## Samples
|
||||
|
||||
We create the following SQL:
|
||||
|
||||
```sql
|
||||
CREATE TABLE userinfo
|
||||
(
|
||||
uid serial NOT NULL,
|
||||
@@ -25,9 +25,9 @@ We create the following SQL:
|
||||
CONSTRAINT userinfo_pkey PRIMARY KEY (uid)
|
||||
)
|
||||
WITH (OIDS=FALSE);
|
||||
|
||||
```
|
||||
An example:
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -102,20 +102,20 @@ An example:
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
Note that PostgreSQL uses the `$1, $2` format instead of the `?` that MySQL uses, and it has a different DSN format in `sql.Open`.
|
||||
Another thing is that the PostgreSQL driver does not support `sql.Result.LastInsertId()`.
|
||||
So instead of this,
|
||||
|
||||
```Go
|
||||
stmt, err := db.Prepare("INSERT INTO userinfo(username,departname,created) VALUES($1,$2,$3);")
|
||||
res, err := stmt.Exec("astaxie", "研发部门", "2012-12-09")
|
||||
fmt.Println(res.LastInsertId())
|
||||
|
||||
```
|
||||
use `db.QueryRow()` and `.Scan()` to get the value for the last inserted id.
|
||||
|
||||
```Go
|
||||
err = db.QueryRow("INSERT INTO TABLE_NAME values($1) returning uid;", VALUE1").Scan(&lastInsertId)
|
||||
fmt.Println(lastInsertId)
|
||||
|
||||
```
|
||||
## Links
|
||||
|
||||
- [Directory](preface.md)
|
||||
|
||||
Reference in New Issue
Block a user