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

Create column-reference for PostgreSQL. #4582

Merged
merged 19 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2959e5a
Create column-reference for PostgreSQL.
ogumbaiyke Apr 28, 2024
1d8c124
Merge branch 'main' into New_Concept_Entry
ogumbaiyke May 7, 2024
1cdf5f8
Merge branch 'main' into New_Concept_Entry
Sriparno08 May 13, 2024
ea76634
Update term-entry-template.md
Sriparno08 May 13, 2024
d214674
Update content/postgresql/concepts/column-references/column-reference…
ogumbaiyke May 16, 2024
c109c31
Update content/postgresql/concepts/column-references/column-reference…
ogumbaiyke May 16, 2024
481f62b
Update content/postgresql/concepts/column-references/column-reference…
ogumbaiyke May 16, 2024
55807ef
Update content/postgresql/concepts/column-references/column-reference…
ogumbaiyke May 16, 2024
79412e1
Update content/postgresql/concepts/column-references/column-reference…
ogumbaiyke May 16, 2024
c422627
Update content/postgresql/concepts/column-references/column-reference…
ogumbaiyke May 16, 2024
6be7134
Merge branch 'main' into New_Concept_Entry
ogumbaiyke May 16, 2024
275d9fa
Merge branch 'main' into New_Concept_Entry
ogumbaiyke May 19, 2024
ca4620f
Update column-references.md
ogumbaiyke May 19, 2024
90fd0e7
Update column-references.md
Sriparno08 May 19, 2024
50b88ad
Merge branch 'main' into New_Concept_Entry
Sriparno08 May 19, 2024
afbe783
Merge branch 'main' into New_Concept_Entry
dakshdeepHERE May 22, 2024
efa76bb
Merge branch 'main' into New_Concept_Entry
ishg-153 May 22, 2024
bd84cb3
Format Fix
avdhoottt May 23, 2024
e036df0
Merge branch 'main' into New_Concept_Entry
avdhoottt May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
139 changes: 139 additions & 0 deletions content/postgresql/concepts/column-references/column-references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
Title: 'Column References'
Description: 'Allow developers to retrieve column names and relevant data from a table.'
Subjects:
- 'Computer Science'
- 'Data Science'
Tags:
- 'PostgreSQL'
- 'Database'
- 'Data'
CatalogContent:
- 'getting-started-off-platform-for-data-science'
- 'paths/design-databases-with-postgresql'
---

In PostgreSQL, **column references** is an important concept that allows developers to retrieve column names and relevant data from a table. Understanding this concept can be useful for data scientists, analysts and administrators as it helps them to query and analyze data efficiently.

## Syntax

The process for referencing columns in PostgreSQL matches a lot with that of SQL (Structured Query Language) as they share some attributes and patterns. Specifically, there are some statements that can be used to reference columns in PostgreSQL.

### SELECT

The `SELECT` statement is used to get data from specific columns in a table:

```pseudo
SELECT column3, column2, ...
FROM table_name;
```

### INSERT

The `INSERT` statement is used to specify the columns to which data is to be inserted:

```pseudo
INSERT INTO table_name (column3, column7, ...)
VALUES (value3, value7, ...);
```

### UPDATE

The `UPDATE` statement is used to specify the columns to be updated with new data:

```pseudo
UPDATE table_name
SET column4 = value4, column9 = value9, ...
WHERE condition;
```

### DELETE

The `DELETE` statement is used to specify the columns to be deleted:

```pseudo
DELETE FROM table_name
WHERE condition;
```

### ALTER TABLE

The `ALTER TABLE` statement is used to add, modify or remove columns from a table.

Here is the syntax for adding a column to a table:

```pseudo
ALTER TABLE table_name
ADD column_name data_type;
```

The following syntax shows how to modify a column in a table:

```pseudo
ALTER TABLE table_name
ALTER COLUMN column_name TYPE new_data_type;
```

The syntax for removing a column from a table is following:

```pseudo
ALTER TABLE table_name
DROP COLUMN column_name;
```

### CREATE TABLE

The `CREATE TABLE` statement is used to define columns while creating a table:

```pseudo
CREATE TABLE table_name (
column1 data_type,
column2 data_type,
);
```

## Example

The following example demonstrates the usage of column references in PostgreSQL:

```sql
-- Creating a table

CREATE TABLE bus (
first_name VARCHAR(80),
last_name VARCHAR(80),
occupation VARCHAR(80),
starting_point VARCHAR(80),
destination_point VARCHAR(80),
ticket_price INTEGER,
duration_in_minutes BIGINT,
type_of_payment VARCHAR(90),
age INTEGER,
next_of_kin VARCHAR(100),
date_of_payment DATE
);

-- Inserting data

INSERT INTO bus (first_name, last_name, occupation, starting_point, destination_point, ticket_price, duration_in_minutes, type_of_payment, age, next_of_kin, date_of_payment)

VALUES
('Ikechukwu', 'Ogumba', 'Student', 'Dei-Dei', 'Kubwa', 200, 15, 'Card Payment', 22, 'William Ogumba', '2024-04-20'),
('John', 'Snow', 'Plumber', 'Dei-Dei', 'Wuse Junction', 500, 40, 'Card Payment', 30, 'Micheal Bolton', '2024-04-20'),
('Barry', 'Hickler', 'Banker', 'Dei-Dei', 'Berger', 700, 60, 'Cash Payment', 39, 'James Rashford', '2024-04-20'),
('Jenny', 'Simpson', 'Therapist', 'Dei-Dei', 'Maitama', 800, 80, 'Card Payment', 30, 'Julie Simpson', '2024-04-20'),
('Junior', 'Kelechukwu', 'Student', 'Dei-Dei', 'Kubwa', 200, 15, 'Card Payment', 40, 'Matthew Kelechukwu', '2024-04-20'),
('Folakemi', 'Abimbola', 'Pastor', 'Dei-Dei', 'Wuse Junction', 500, 40, 'Cash', 30, 'Kehinde Abimbola', '2024-04-20'),
('Tochukwu', 'Okafor', 'Athlete', 'Dei-Dei', 'Berger', 700, 60, 'Card Payment', 39, 'Duru Okafor', '2024-04-20'),
('Taiwo', 'Kehinde', 'Trader', 'Dei-Dei', 'Kubwa', 200, 15, 'Card Payment', 50, 'Adebayo Kehinde', '2024-04-20');

SELECT
first_name,
last_name,
age

FROM
bus;
```

The above code lists the first name, last name and age of all the passengers in the bus.