Skip to content

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

Merged
merged 3 commits into from
Jul 18, 2017
Merged

Completed Update statement documentation #1707

merged 3 commits into from
Jul 18, 2017

Conversation

Amruta-Ranade
Copy link
Contributor

Closes #499
Need to self-review the content, but fixed formatting issues.

@Amruta-Ranade Amruta-Ranade requested a review from jseldess July 13, 2017 03:04
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@cockroach-teamcity
Copy link
Member

Copy link
Contributor

@jseldess jseldess left a 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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...

Copy link
Contributor Author

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.

Copy link
Contributor

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 |
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

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}}
Copy link
Contributor

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>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

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).
Copy link
Contributor

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.

Copy link
Contributor

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 the id value of the row updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

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}}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

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:')
Copy link
Contributor

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:')

Copy link
Contributor Author

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:
Copy link
Contributor

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:

Copy link
Contributor Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it singular: ID:

Copy link
Contributor Author

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">
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@cockroach-teamcity
Copy link
Member

@cockroach-teamcity
Copy link
Member

@sploiselle
Copy link
Contributor

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):

| id | balance  | customer |
+----+----------+----------+
|  1 | 10000.50 | michael  |

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

@Amruta-Ranade
Copy link
Contributor Author

Amruta-Ranade commented Jul 14, 2017

@sploiselle This is cool! Thanks for sharing!

@cockroach-teamcity
Copy link
Member

@cockroach-teamcity
Copy link
Member

@cockroach-teamcity
Copy link
Member

@Amruta-Ranade Amruta-Ranade requested a review from dt July 17, 2017 17:28
@Amruta-Ranade Amruta-Ranade changed the title [WIP]: Completed Update statement documentation Completed Update statement documentation Jul 17, 2017
@jseldess
Copy link
Contributor

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):

~~~

### Update using SELECT statement

Thanks for adding this, Amruta!

nit: Use title case like the others, and code-format SELECT:

Update Using `SELECT` Statement

v1.0/update.md, line 223 at r2 (raw file):

# Insert two rows into the "accounts" table
# and return the "id" value.

I meant to mention this earlier, but it looks like my comment got lost: We need to change this comment to:

# Update a row in the "accounts" table
# and return the "id" value.

Also need to update the other code samples.


Comments from Reviewable

@cockroach-teamcity
Copy link
Member

@jseldess
Copy link
Contributor

Thanks, @Amruta-Ranade. LGTM (after you apply these updates to the v1.1 page as well).

@cockroach-teamcity
Copy link
Member

1 similar comment
@cockroach-teamcity
Copy link
Member

@Amruta-Ranade Amruta-Ranade merged commit 5f9abe8 into master Jul 18, 2017
@Amruta-Ranade Amruta-Ranade deleted the update_stmt branch July 18, 2017 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: UPDATE statement
5 participants