Skip to content
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

Completed concept entry for Postgresql operators #4764 #4785

Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c9f7959
added shell for concept
nbarnhouse Jun 3, 2024
53c085b
completed first draft of operator-invocations
nbarnhouse Jun 12, 2024
a884d8b
Merge branch 'Codecademy:main' into main
nbarnhouse Jun 12, 2024
5de5292
added shell for file structure
nbarnhouse Jun 13, 2024
5e4b65e
completed description and syntax, working through examples now
nbarnhouse Jun 15, 2024
7783c09
completed initial write up of numpy.degrees
nbarnhouse Jun 17, 2024
88ef147
corrected missing description
nbarnhouse Jun 17, 2024
2c9017f
corrected md file with missing description
nbarnhouse Jun 17, 2024
8ae7e64
removing file added in error
nbarnhouse Jun 17, 2024
a48af58
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
3ea051a
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
61e08be
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
2ea31a5
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
dff8c89
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
23b2acd
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
ff28c5f
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
d714e37
Update content/postgresql/concepts/operator-invocations/operator-invo…
nbarnhouse Jun 27, 2024
f7f8632
Merge branch 'main' into postgresql-operator_invocations
Sriparno08 Jul 3, 2024
5bbe7b3
Minor changes
Sriparno08 Jul 3, 2024
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
100 changes: 100 additions & 0 deletions content/postgresql/concepts/operators/operators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
Title: 'Operators'
Description: 'Enable users to perform different operations on the data.'
Subjects:
- 'Computer Science'
- 'Data Science'
Tags:
- 'Data'
- 'Database'
- 'Operators'
- 'PostgreSQL'
CatalogContent:
- 'learn-sql'
- 'paths/analyze-data-with-sql'
---

In PostgreSQL, **operators** enable users to perform different operations on the data in one or multiple tables in a [database](https://www.codecademy.com/resources/docs/general/database). They can be used for calculations, comparisons, joining, filtering, etc.

## Syntax

There are many operators that can be used in PostgreSQL. Here are some common ones:

### Comparison Operators

The following operators can be categorized as comparison operators:

```pseudo
// Equal to
SELECT * FROM table_name
WHERE column1 = 'North';

// Not Equal to
SELECT * FROM table_name
WHERE column1 != column2;

// Greater than
SELECT * FROM table_name
WHERE column1 > 10;

// Less than
SELECT * FROM table_name
WHERE column1 < 1000;
```

### Logical Operators

The following operators can be categorized as logical operators:

```pseudo
// AND
SELECT * FROM table_name
WHERE column1 >= 10 AND column1 <= 1000;

// OR
SELECT * FROM table_name
WHERE column1 = 'NORTH' OR 'WEST';

// NOT
SELECT * FROM table_name
WHERE NOT column1 = 'SOUTH';
```

## Examples

The following examples demonstrate the usage of operators in PostgreSQL.

Here's a table named `animals` to be used for the examples:

| `id` | `name` | `species` | `gender` | `age` |
| ---- | ------ | --------- | -------- | ----- |
| 01 | Niko | monkey | female | 3 |
| 02 | Frank | giraffe | male | 4 |
| 03 | Lyn | lion | female | 6 |
| 04 | Tom | elephant | male | 7 |

Here's a query that invokes some of the operators mentioned above:

```sql
SELECT * FROM animals WHERE gender = 'female' AND age >= 4;
```

The above query results in the following output:

| `id` | `name` | `species` | `gender` | `age` |
| ---- | ------ | --------- | -------- | ----- |
| 03 | Lyn | lion | female | 6 |

Here's another query that invokes some operators:

```sql
SELECT * FROM animals WHERE NOT species = 'lion';
```

The above query produces the following output:

| `id` | `name` | `species` | `gender` | `age` |
| ---- | ------ | --------- | -------- | ----- |
| 01 | Niko | monkey | female | 3 |
| 02 | Frank | giraffe | male | 4 |
| 04 | Tom | elephant | male | 7 |
Loading