Skip to content

Added update query to postgresql docs #1535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/tutorials/getting-started-postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ DELETE FROM authors
WHERE id = $1;
```

For SQL UPDATE if you do not want to return the updated record to the user, add this to the `query.sql` file:
```sql
-- name: UpdateAuthor :exec
UPDATE authors
set name = $2,
bio = $3
WHERE id = $1;
```
Otherwise, to return the updated record back to the user, add this to the `query.sql` file:
```sql
-- name: UpdateAuthor :one
UPDATE authors
set name = $2,
bio = $3
WHERE id = $1
RETURNING *;
```

You are now ready to generate code. Run the `generate` command. You shouldn't see any errors or output.

```shell
Expand Down