-
Notifications
You must be signed in to change notification settings - Fork 472
Completed Update statement documentation #1707
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad you resolved that formatting issue, @Amruta-Ranade! Overall, this is looking good. I have a few comments. But I think it'd be best for you to get this reviewed by an engineer first, whoever you worked with (David?).
v1.0/update.md
Outdated
`column_name` | The name of the column whose values you want to update. To update the values of multiple columns, use a comma-separated list of column names. | ||
`a_expr` | The new value you want to use, the [aggregate function](functions-and-operators.html#aggregate-functions) you want to perform, or the [value expression](sql-expressions.html) you want to use. | ||
`DEFAULT` | To fill columns with their [default values](default-value.html), use `DEFAULT VALUES` in place of `a_expr`. To fill a specific column with its default value, leave the value out of the `a_expr` or use `DEFAULT` at the appropriate position. | ||
`column_name_list` | A comma-separated list of column names, in parentheses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since column_name
is represented in the diagram as a loop, and you state that you can use a comma-separated list in the column_name
description, I think it's redundant to list column_name_list
here and in the diagram. What are you thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that's an error I made. In the first instance, it cannot be a comma-separated list of column names. It can be a comma-separated list of column name-value pairs. In the second instance, it can be a comma-separated list of column names. Fixed that in the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still confused about the difference between these. What is a comma-separated list of column name-value pairs vs. a comma-separate list of column names? Can you provide an example of each to help me understand?
v1.0/update.md
Outdated
`DEFAULT` | To fill columns with their [default values](default-value.html), use `DEFAULT VALUES` in place of `a_expr`. To fill a specific column with its default value, leave the value out of the `a_expr` or use `DEFAULT` at the appropriate position. | ||
`column_name_list` | A comma-separated list of column names, in parentheses. | ||
`select_with_parens` | A comma-separated list of values or [value expressions](sql-expressions.html), in parentheses. To update values of multiple rows, use a comma-separated list of parentheses. <br><br>Each value must match the [data type](data-types.html) of its column. Also, if column names are listed (`qualified_name_list`), values must be in corresponding order; otherwise, they must follow the declared order of the columns in the table. | ||
`WHERE a_expr`| `a_expr` must be an expression that returns Boolean values using columns (e.g. `<column> = <value>`). Update rows that return `TRUE`.<br><br>__Without a `WHERE` clause in your statement, `UPDATE` updates all rows from the table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you want to format the final paragraph? I think something's incomplete there...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's an error that creeped in when I was debugging the formatting issue. Fixed in the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the last paragraph still starts with two underscores. What formatting are you intending here?
v1.0/update.md
Outdated
| id | balance | customer | | ||
+----+----------+----------+ | ||
| 1 | 10000.50 | michael | | ||
| 2 | 9000.0 | kelly | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need one more space before the final pipe of row 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looks the same. Did you push your change?
v1.0/update.md
Outdated
(4 rows) | ||
~~~ | ||
|
||
### Update with default values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use title case, like for the other examples: Update with Default Values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looks the same...
v1.0/update.md
Outdated
|
||
### Update All Rows | ||
|
||
{{site.data.alerts.callout_danger}}If you don't use the WHERE clause to specify the rows to be updated, the values for all rows will be updated.{{site.data.alerts.end}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to apply code formatting to WHERE
. Note that within a callout like this, you need to use html to format things:
<code>WHERE</code>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looks the same...
v1.0/update.md
Outdated
|
||
### Update and Return Values | ||
|
||
In this example, the `RETURNING` clause returns the `id` values of the rows updated, which are generated server-side by the `unique_rowid()` function. The language-specific versions assume that you have installed the relevant [client drivers](install-client-drivers.html). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the text taken from the insert
example is not correct here. You need to remove the clause:
which are generated server-side by the
unique_rowsid()
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the first sentence needs to be revised to match the fact that the example updates a single row:
In this example, the
RETURNING
clause returns theid
value of the row updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looks the same...
v1.0/update.md
Outdated
|
||
In this example, the `RETURNING` clause returns the `id` values of the rows updated, which are generated server-side by the `unique_rowid()` function. The language-specific versions assume that you have installed the relevant [client drivers](install-client-drivers.html). | ||
|
||
{{site.data.alerts.callout_success}}This use of <code>RETURNING</code> mirrors the behavior of MySQL's <code>last_insert_id()</code> function.{{site.data.alerts.end}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove this as well. It applies more to the insert
example from which this was taken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked online, and it seems the last_insert_id() function works with update as well. Will confirm with eng though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks, Amruta.
v1.0/update.md
Outdated
'UPDATE accounts SET balance = DEFAULT WHERE id = 1 RETURNING id' | ||
) | ||
|
||
# Print out the returned values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it singular to match the example: returned value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looks the same. Seems like you haven't pushed your changes yet, for this and all other changes below?
v1.0/update.md
Outdated
|
||
# Print out the returned values. | ||
rows = cur.fetchall() | ||
print('IDs:') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, make it singular to match the example: print('ID:')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
v1.0/update.md
Outdated
conn.close() | ||
~~~ | ||
|
||
The printed values would look like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it singular: The printed value would look like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
v1.0/update.md
Outdated
The printed values would look like: | ||
|
||
~~~ | ||
IDs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it singular: ID:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
</section> | ||
|
||
<section class="filter-content" markdown="1" data-scope="ruby"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same tweaks need to be made to this and all the other code samples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Review status: 0 of 3 files reviewed at latest revision, 12 unresolved discussions, some commit checks failed. v1.0/update.md, line 44 at r1 (raw file):
Looks like Jesse has gotten a lot of feedback on this, but I'd be really stoked if we could use non-WASP names! I recommend using a random name generator like this one: https://www.behindthename.com/random/ Comments from Reviewable |
@sploiselle This is cool! Thanks for sharing! |
…s, Added non-WASP names, regrouped examples
60435aa
to
5c8fc5d
Compare
Review status: 0 of 3 files reviewed at latest revision, 14 unresolved discussions, all commit checks successful. v1.0/update.md, line 106 at r2 (raw file):
Thanks for adding this, Amruta! nit: Use title case like the others, and code-format
v1.0/update.md, line 223 at r2 (raw file):
I meant to mention this earlier, but it looks like my comment got lost: We need to change this comment to:
Also need to update the other code samples. Comments from Reviewable |
Thanks, @Amruta-Ranade. LGTM (after you apply these updates to the v1.1 page as well). |
Closes #499
Need to self-review the content, but fixed formatting issues.