Skip to content

Commit

Permalink
vault backup: 2024-05-16 18:49:36
Browse files Browse the repository at this point in the history
Affected files:
content/.obsidian/plugins/recent-files-obsidian/data.json
content/.obsidian/workspace.json
content/postgresql/PostgreSQL Constraint and Key.md
content/postgresql/PostgreSQL Database.md
content/postgresql/PostgreSQL Delete.md
content/postgresql/PostgreSQL Join.md
content/postgresql/PostgreSQL Sequence and UUID.md
content/postgresql/PostgreSQL Table.md
content/postgresql/PostgreSQL Update.md
content/postgresql/PostgreSQL.md
  • Loading branch information
windsuzu committed May 16, 2024
1 parent aef6e90 commit 2c8a060
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 131 deletions.
52 changes: 26 additions & 26 deletions content/.obsidian/plugins/recent-files-obsidian/data.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
{
"recentFiles": [
{
"basename": "PostgreSQL Table",
"path": "postgresql/PostgreSQL Table.md"
},
{
"basename": "PostgreSQL Constraint and Key",
"path": "postgresql/PostgreSQL Constraint and Key.md"
},
{
"basename": "PostgreSQL",
"path": "postgresql/PostgreSQL.md"
},
{
"basename": "PostgreSQL Select",
"path": "postgresql/PostgreSQL Select.md"
"basename": "PostgreSQL Delete",
"path": "postgresql/PostgreSQL Delete.md"
},
{
"basename": "PostgreSQL Join",
"path": "postgresql/PostgreSQL Join.md"
},
{
"basename": "PostgreSQL Update",
"path": "postgresql/PostgreSQL Update.md"
},
{
"basename": "PostgreSQL Sequence and UUID",
"path": "postgresql/PostgreSQL Sequence and UUID.md"
},
{
"basename": "PostgreSQL Tables",
"path": "postgresql/PostgreSQL Tables.md"
"basename": "PostgreSQL Database",
"path": "postgresql/PostgreSQL Database.md"
},
{
"basename": "PostgreSQL Insert and Import",
"path": "postgresql/PostgreSQL Insert and Import.md"
},
{
"basename": "PostgreSQL Databases",
"path": "postgresql/PostgreSQL Databases.md"
"basename": "PostgreSQL Select",
"path": "postgresql/PostgreSQL Select.md"
},
{
"basename": "Connect PostgreSQL on WSL 2 (Ubuntu)",
Expand Down Expand Up @@ -179,26 +199,6 @@
{
"basename": "Anymore vs Any more",
"path": "english-grammar/Anymore vs Any more.md"
},
{
"basename": "Auxiliary verbs",
"path": "english-grammar/Auxiliary verbs.md"
},
{
"basename": "Auxiliary verbs Common Mistakes",
"path": "english-grammar/Auxiliary verbs Common Mistakes.md"
},
{
"basename": "Substitution",
"path": "english-grammar/Substitution.md"
},
{
"basename": "Ellipsis",
"path": "english-grammar/Ellipsis.md"
},
{
"basename": "There and it",
"path": "english-grammar/There and it.md"
}
],
"omittedPaths": [],
Expand Down
57 changes: 41 additions & 16 deletions content/.obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "tabs",
"children": [
{
"id": "09dd403f5501ccb2",
"id": "89b49aba37ae8848",
"type": "leaf",
"state": {
"type": "markdown",
Expand All @@ -18,8 +18,33 @@
"source": false
}
}
},
{
"id": "96a9372e3b208e7f",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "postgresql/PostgreSQL Constraint and Key.md",
"mode": "source",
"source": false
}
}
},
{
"id": "479dfa44c76beee2",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "postgresql/PostgreSQL Table.md",
"mode": "source",
"source": false
}
}
}
]
],
"currentTab": 2
}
],
"direction": "vertical"
Expand Down Expand Up @@ -102,7 +127,7 @@
"state": {
"type": "localgraph",
"state": {
"file": "postgresql/PostgreSQL.md",
"file": "postgresql/PostgreSQL Table.md",
"options": {
"collapse-filter": true,
"search": "",
Expand Down Expand Up @@ -152,7 +177,7 @@
"state": {
"type": "outline",
"state": {
"file": "postgresql/PostgreSQL.md"
"file": "postgresql/PostgreSQL Table.md"
}
}
},
Expand Down Expand Up @@ -193,7 +218,7 @@
"state": {
"type": "file-properties",
"state": {
"file": "postgresql/PostgreSQL.md"
"file": "postgresql/PostgreSQL Table.md"
}
}
},
Expand All @@ -203,7 +228,7 @@
"state": {
"type": "backlink",
"state": {
"file": "postgresql/PostgreSQL.md",
"file": "postgresql/PostgreSQL Table.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -220,7 +245,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "postgresql/PostgreSQL.md",
"file": "postgresql/PostgreSQL Table.md",
"linksCollapsed": false,
"unlinkedCollapsed": false
}
Expand All @@ -246,13 +271,18 @@
"cmdr:Obsidian Git: Create backup": false
}
},
"active": "09dd403f5501ccb2",
"active": "479dfa44c76beee2",
"lastOpenFiles": [
"postgresql/PostgreSQL Select.md",
"postgresql/PostgreSQL Constraint and Key.md",
"postgresql/PostgreSQL.md",
"postgresql/PostgreSQL Tables.md",
"postgresql/PostgreSQL Table.md",
"postgresql/PostgreSQL Delete.md",
"postgresql/PostgreSQL Join.md",
"postgresql/PostgreSQL Update.md",
"postgresql/PostgreSQL Sequence and UUID.md",
"postgresql/PostgreSQL Database.md",
"postgresql/PostgreSQL Insert and Import.md",
"postgresql/PostgreSQL Databases.md",
"postgresql/PostgreSQL Select.md",
"postgresql/Connect PostgreSQL on WSL 2 (Ubuntu).md",
"postgresql/Install PostgreSQL on WSL 2 (Ubuntu).md",
"index.md",
Expand All @@ -272,11 +302,6 @@
"mocs/Web-Dev MOC.md",
"mocs/JavaScript MOC.md",
"fish-shell",
"english-grammar/English Grammar.md",
"english-grammar/Relative clauses, relative pronouns and adverbs.md",
"english-grammar/Prepositions.md",
"english-grammar/Prepositions Common Mistakes.md",
"english-grammar/Since vs From.md",
"resume",
"attachments/avatar-jay.jpeg",
"attachments/prepositions-of-place.png",
Expand Down
54 changes: 54 additions & 0 deletions content/postgresql/PostgreSQL Constraint and Key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
draft: false
date: 2024-05-16 18:19
tags:
- postgres
---



```sql
ALTER TABLE person ADD UNIQUE (email);
ALTER TABLE person ADD CONSTRAINT unique_email UNIQUE (email);
```

```sql
ALTER TABLE person DROP CONSTRAINT person_pkey;
```

```sql
ALTER TABLE person ADD PRIMARY KEY (id);
```

```sql
ALTER TABLE person ADD CONSTRAINT gender_contraint CHECK (gender = 'Female' OR gender = 'Male');
```

```sql
CREATE TABLE car (
id BIGSERIAL NOT NULL PRIMARY KEY,
make VARCHAR(100) NOT NULL,
model VARCHAR(100) NOT NULL,
price NUMERIC(19,2) NOT NULL
);

CREATE TABLE person (
id BIGSERIAL NOT NULL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
gender VARCHAR(50) NOT NULL,
date_of_birth DATE NOT NULL,
email VARCHAR(150),
car_id BIGINT REFERENCE car(id),
UNIQUE(car_id)
);
```


```sql
UPDATE person SET car_id = 2 WHERE id = 1;
```


> [!info] References
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4)
File renamed without changes.
21 changes: 21 additions & 0 deletions content/postgresql/PostgreSQL Delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
draft: false
date: 2024-05-16 18:17
tags:
- postgres
---


```sql
DELETE FROM person;
```

```sql
DELETE FROM person WHERE id = 1;
```




> [!info] References
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4)
39 changes: 39 additions & 0 deletions content/postgresql/PostgreSQL Join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
draft: false
date: 2024-05-16 18:17
tags:
- postgres
---


### JOIN

```sql
JOIN car ON person.car_id = car.id;
```

```sql
SELECT person.first_name, car.make, car.price
FROM person
JOIN car ON person.car_id = car.id
```

```sql
SELECT person.first_name, car.make, car.price
FROM person
LEFT JOIN car ON person.car_id = car.id
```

```sql
SELECT person.first_name, car.make, car.price
FROM person
JOIN car USING (car_uid)
```






> [!info] References
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4)
24 changes: 24 additions & 0 deletions content/postgresql/PostgreSQL Sequence and UUID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
draft: false
date: 2024-05-16 18:15
tags:
- postgres
---

### BIGSERIAL

```sql
ALTER SEQUENCE person_id_seq RESTART WITH 0;
```

### UUID







> [!info] References
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4)
> - [Universally unique identifier - Wikipedia](https://en.wikipedia.org/wiki/Universally_unique_identifier)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
draft: false
date: 2024-05-16 11:49
date: 2024-05-16 17:20
tags:
- postgres
---
Expand Down Expand Up @@ -83,9 +83,32 @@ And use `\d table_name` to see the details of the specified table.
# "person_pkey" PRIMARY KEY, btree (id)
```

### Update a table

To update a table, use `ALTER`. For example, you can update the column name by using `ALTER TABLE` with `RENAME TO`:

```sql
ALTER TABLE table_name RENAME column_name TO column_new_name;

ALTER TABLE person RENAME id TO person_uid;
ALTER TABLE person RENAME gender TO sex;
```

Additionally, you can update the column type by using `ALTER TABLE` with `ALTER COLUMN` and `TYPE`:

```sql
ALTER TABLE table_name ALTER COLUMN column_name TYPE type_name;

ALTER TABLE person ALTER COLUMN email TYPE varchar(300);
ALTER TABLE person ALTER COLUMN age TYPE int;
```
### Remove a table

To remove a table, simply use `DROP TABLE table_name`.
To remove a table, use `DROP` to do so.

```sql
DROP TABLE table_name;
```

> [!info] References
> - [Learn PostgreSQL Tutorial - Full Course for Beginners - YouTube](https://www.youtube.com/watch?v=qw--VYLpxG4)
Loading

0 comments on commit 2c8a060

Please sign in to comment.