Skip to content

Commit 4e37925

Browse files
authored
Added update query to postgresql docs (#1535)
* Added updated query to postgresql docs * Updated the UPDATE query to postgresql docs for exec or returning record
1 parent 6e45a9f commit 4e37925

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/tutorials/getting-started-postgresql.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ DELETE FROM authors
6060
WHERE id = $1;
6161
```
6262

63+
For SQL UPDATE if you do not want to return the updated record to the user, add this to the `query.sql` file:
64+
```sql
65+
-- name: UpdateAuthor :exec
66+
UPDATE authors
67+
set name = $2,
68+
bio = $3
69+
WHERE id = $1;
70+
```
71+
Otherwise, to return the updated record back to the user, add this to the `query.sql` file:
72+
```sql
73+
-- name: UpdateAuthor :one
74+
UPDATE authors
75+
set name = $2,
76+
bio = $3
77+
WHERE id = $1
78+
RETURNING *;
79+
```
80+
6381
You are now ready to generate code. Run the `generate` command. You shouldn't see any errors or output.
6482

6583
```shell

0 commit comments

Comments
 (0)