|
1749 | 1749 | "cell_type": "markdown", |
1750 | 1750 | "metadata": {}, |
1751 | 1751 | "source": [ |
1752 | | - "# Querying data" |
| 1752 | + "# Querying data from a single table" |
1753 | 1753 | ] |
1754 | 1754 | }, |
1755 | 1755 | { |
|
1767 | 1767 | "cell_type": "markdown", |
1768 | 1768 | "metadata": {}, |
1769 | 1769 | "source": [ |
1770 | | - "## Restricting by attribute value" |
| 1770 | + "## Restrictions (`&`) - filter data with certain conditions" |
1771 | 1771 | ] |
1772 | 1772 | }, |
1773 | 1773 | { |
|
3117 | 3117 | "cell_type": "markdown", |
3118 | 3118 | "metadata": {}, |
3119 | 3119 | "source": [ |
3120 | | - "## Negative restriction - with the `-` operator" |
| 3120 | + "## Negative restriction (`-`) - filter out data" |
3121 | 3121 | ] |
3122 | 3122 | }, |
3123 | 3123 | { |
|
3464 | 3464 | "cell_type": "markdown", |
3465 | 3465 | "metadata": {}, |
3466 | 3466 | "source": [ |
3467 | | - "## Deleting entries" |
3468 | | - ] |
3469 | | - }, |
3470 | | - { |
3471 | | - "cell_type": "markdown", |
3472 | | - "metadata": {}, |
3473 | | - "source": [ |
3474 | | - "Now we have a good idea on how to restrict table entries, this is a good time to introduce how to **delete** entries from a table." |
3475 | | - ] |
3476 | | - }, |
3477 | | - { |
3478 | | - "cell_type": "markdown", |
3479 | | - "metadata": {}, |
3480 | | - "source": [ |
3481 | | - "To delete a specific entry, you restrict the table down to the target entry, and call `delete` method." |
3482 | | - ] |
3483 | | - }, |
3484 | | - { |
3485 | | - "cell_type": "code", |
3486 | | - "execution_count": 45, |
3487 | | - "metadata": {}, |
3488 | | - "outputs": [ |
3489 | | - { |
3490 | | - "name": "stdout", |
3491 | | - "output_type": "stream", |
3492 | | - "text": [ |
3493 | | - "About to delete:\n", |
3494 | | - "`test_`.`mouse`: 1 items\n", |
3495 | | - "Proceed? [yes, No]: yes\n", |
3496 | | - "Committed.\n" |
3497 | | - ] |
3498 | | - } |
3499 | | - ], |
3500 | | - "source": [ |
3501 | | - "(Mouse & 'mouse_id = 100').delete()" |
3502 | | - ] |
3503 | | - }, |
3504 | | - { |
3505 | | - "cell_type": "markdown", |
3506 | | - "metadata": {}, |
3507 | | - "source": [ |
3508 | | - "Calling `delete` method on an *unrestricted* table will attempt to delete the whole table!" |
3509 | | - ] |
3510 | | - }, |
3511 | | - { |
3512 | | - "cell_type": "code", |
3513 | | - "execution_count": 46, |
3514 | | - "metadata": {}, |
3515 | | - "outputs": [ |
3516 | | - { |
3517 | | - "name": "stdout", |
3518 | | - "output_type": "stream", |
3519 | | - "text": [ |
3520 | | - "About to delete:\n", |
3521 | | - "`test_`.`session`: 3 items\n", |
3522 | | - "`test_`.`mouse`: 11 items\n", |
3523 | | - "Proceed? [yes, No]: No\n", |
3524 | | - "Cancelled deletes.\n" |
3525 | | - ] |
3526 | | - } |
3527 | | - ], |
3528 | | - "source": [ |
3529 | | - "Mouse.delete()" |
3530 | | - ] |
3531 | | - }, |
3532 | | - { |
3533 | | - "cell_type": "markdown", |
3534 | | - "metadata": {}, |
3535 | | - "source": [ |
3536 | | - "Notice that when you try to delete all `Mouse`, `delete` also warned that `Session` entries will get deleted! \n", |
3537 | | - "\n", |
3538 | | - "DataJoint understands and keeps track of dependencies such that **no dependent entries will be left orphaned**. The `delete` operations automatically **cascades down** the dependency to ensure data integrity. We will revisit this point in the next session." |
3539 | | - ] |
3540 | | - }, |
3541 | | - { |
3542 | | - "cell_type": "markdown", |
3543 | | - "metadata": {}, |
3544 | | - "source": [ |
3545 | | - "## Joining tables" |
| 3467 | + "## Join (`*`) - gather information from different tables" |
3546 | 3468 | ] |
3547 | 3469 | }, |
3548 | 3470 | { |
|
3950 | 3872 | "cell_type": "markdown", |
3951 | 3873 | "metadata": {}, |
3952 | 3874 | "source": [ |
3953 | | - "## Projection .proj(): focus on attributes of interest\n", |
| 3875 | + "## Projection (`.proj()`) - focus on attributes of interest" |
| 3876 | + ] |
| 3877 | + }, |
| 3878 | + { |
| 3879 | + "cell_type": "markdown", |
| 3880 | + "metadata": {}, |
| 3881 | + "source": [ |
3954 | 3882 | "Beside restriction (`&`) and join (`*`) operations, DataJoint offers another type of operation: projection (`.proj()`). Projection is used to select attributes (columns) from a table, to rename them, or to create new calculated attributes. " |
3955 | 3883 | ] |
3956 | 3884 | }, |
|
4453 | 4381 | "cell_type": "markdown", |
4454 | 4382 | "metadata": {}, |
4455 | 4383 | "source": [ |
4456 | | - "## Fetch query results" |
| 4384 | + "# Fetch query results" |
4457 | 4385 | ] |
4458 | 4386 | }, |
4459 | 4387 | { |
|
4755 | 4683 | "(Mouse * Session & {'session_date': '2017-05-15'}).fetch1('KEY') # \"fetch1()\" because we know there's only one" |
4756 | 4684 | ] |
4757 | 4685 | }, |
| 4686 | + { |
| 4687 | + "cell_type": "markdown", |
| 4688 | + "metadata": {}, |
| 4689 | + "source": [ |
| 4690 | + "# Deletion (`.delete()`) - deleting entries and their dependencies" |
| 4691 | + ] |
| 4692 | + }, |
| 4693 | + { |
| 4694 | + "cell_type": "markdown", |
| 4695 | + "metadata": {}, |
| 4696 | + "source": [ |
| 4697 | + "Now we have a good idea on how to restrict table entries, this is a good time to introduce how to **delete** entries from a table." |
| 4698 | + ] |
| 4699 | + }, |
| 4700 | + { |
| 4701 | + "cell_type": "markdown", |
| 4702 | + "metadata": {}, |
| 4703 | + "source": [ |
| 4704 | + "To delete a specific entry, you restrict the table down to the target entry, and call `delete` method." |
| 4705 | + ] |
| 4706 | + }, |
| 4707 | + { |
| 4708 | + "cell_type": "code", |
| 4709 | + "execution_count": 45, |
| 4710 | + "metadata": {}, |
| 4711 | + "outputs": [ |
| 4712 | + { |
| 4713 | + "name": "stdout", |
| 4714 | + "output_type": "stream", |
| 4715 | + "text": [ |
| 4716 | + "About to delete:\n", |
| 4717 | + "`test_`.`mouse`: 1 items\n", |
| 4718 | + "Proceed? [yes, No]: yes\n", |
| 4719 | + "Committed.\n" |
| 4720 | + ] |
| 4721 | + } |
| 4722 | + ], |
| 4723 | + "source": [ |
| 4724 | + "(Mouse & 'mouse_id = 100').delete()" |
| 4725 | + ] |
| 4726 | + }, |
| 4727 | + { |
| 4728 | + "cell_type": "markdown", |
| 4729 | + "metadata": {}, |
| 4730 | + "source": [ |
| 4731 | + "Calling `delete` method on an *unrestricted* table will attempt to delete the whole table!" |
| 4732 | + ] |
| 4733 | + }, |
| 4734 | + { |
| 4735 | + "cell_type": "code", |
| 4736 | + "execution_count": 46, |
| 4737 | + "metadata": {}, |
| 4738 | + "outputs": [ |
| 4739 | + { |
| 4740 | + "name": "stdout", |
| 4741 | + "output_type": "stream", |
| 4742 | + "text": [ |
| 4743 | + "About to delete:\n", |
| 4744 | + "`test_`.`session`: 3 items\n", |
| 4745 | + "`test_`.`mouse`: 11 items\n", |
| 4746 | + "Proceed? [yes, No]: No\n", |
| 4747 | + "Cancelled deletes.\n" |
| 4748 | + ] |
| 4749 | + } |
| 4750 | + ], |
| 4751 | + "source": [ |
| 4752 | + "Mouse.delete()" |
| 4753 | + ] |
| 4754 | + }, |
| 4755 | + { |
| 4756 | + "cell_type": "markdown", |
| 4757 | + "metadata": {}, |
| 4758 | + "source": [ |
| 4759 | + "Notice that when you try to delete all `Mouse`, `delete` also warned that `Session` entries will get deleted! \n", |
| 4760 | + "\n", |
| 4761 | + "DataJoint understands and keeps track of dependencies such that **no dependent entries will be left orphaned**. The `delete` operations automatically **cascades down** the dependency to ensure data integrity. We will revisit this point in the next session." |
| 4762 | + ] |
| 4763 | + }, |
4758 | 4764 | { |
4759 | 4765 | "cell_type": "markdown", |
4760 | 4766 | "metadata": {}, |
|
0 commit comments