Skip to content

Commit 1fb970c

Browse files
authored
Merge pull request #2 from fahimahammed/chore/hacktoberfest2025
Chore/hacktoberfest2025
2 parents 0c8fb16 + 0f31866 commit 1fb970c

4 files changed

Lines changed: 128 additions & 29 deletions

File tree

.github/workflows/pr-labeler.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "PR Labeler for Hacktoberfest"
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
add-labels:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v3
13+
14+
- name: Label PR for Hacktoberfest
15+
uses: actions-ecosystem/action-add-labels@v1
16+
with:
17+
github_token: ${{ secrets.GITHUB_TOKEN }}
18+
labels: |
19+
good first issue
20+
hacktoberfest
21+
hacktoberfest_2025
22+
hacktoberfest-accepted

CONTRIBUTING.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,58 @@
1-
# Contributing to Learn PostgreSQL
2-
3-
Thank you for considering contributing to the **Learn PostgreSQL** project! Your contributions help improve the quality of this resource and are greatly appreciated.
41

5-
## Hacktoberfest
2+
# Contributing to Learn PostgreSQL
63

7-
This repository is open to contributions as part of **Hacktoberfest**. If you are participating in Hacktoberfest, follow the guidelines below to ensure that your pull request (PR) is accepted and counts toward your Hacktoberfest contributions.
4+
Thank you for your interest in contributing to the **Learn PostgreSQL** project! Your help makes this resource better for everyone—whether by fixing typos, improving explanations, or adding new PostgreSQL tutorials.
85

9-
### What is Hacktoberfest?
6+
## Hacktoberfest 2025
107

11-
Hacktoberfest is a month-long event (October) that encourages people to contribute to open-source projects. Contributors must submit **four quality pull requests** to participating repositories to earn a Hacktoberfest T-shirt or plant a tree.
8+
This repository is open for **Hacktoberfest 2025** contributions. Hacktoberfest is a month-long event in October that encourages participants to contribute to open-source projects. Completing **four quality pull requests** to participating repositories earns you a Hacktoberfest T-shirt or a tree planted in your name.
129

13-
You can read more about Hacktoberfest [here](https://hacktoberfest.com).
10+
Learn more about Hacktoberfest [here](https://hacktoberfest.com).
1411

1512
## How to Contribute
1613

17-
1. **Fork the repository**: Start by forking this repository to your own GitHub account. Click the "Fork" button at the top right of this page.
18-
19-
2. **Clone the repository**: Clone your fork locally.
14+
1. **Fork the repository** Click the "Fork" button at the top right of this page.
15+
2. **Clone your fork** – Clone it to your local machine:
16+
2017
```bash
2118
git clone https://github.com/fahimahammed/learn-postgresql.git
2219
```
20+
3. **Create a branch** – Make a new branch for your work:
2321

24-
3. **Create a branch**: Create a new branch to work on your changes.
2522
```bash
2623
git checkout -b your-branch-name
2724
```
25+
4. **Make your changes** – Fix typos, improve guides, or add new PostgreSQL content.
26+
5. **Commit your changes** – Write a clear and descriptive commit message:
2827

29-
4. **Make your changes**: Implement your changes. You can improve documentation, fix issues, or add new PostgreSQL learning content.
30-
31-
5. **Commit your changes**: After making changes, commit them with a descriptive message.
3228
```bash
3329
git add .
34-
git commit -m "Your descriptive commit message"
30+
git commit -m "Add guide for PostgreSQL JSON functions"
3531
```
32+
6. **Push your branch** – Push your changes to your fork:
3633

37-
6. **Push your changes**: Push the changes to your fork.
3834
```bash
3935
git push origin your-branch-name
4036
```
41-
42-
7. **Create a pull request**: Go to the original repository and create a pull request from your fork. Ensure you provide a detailed description of the changes you made.
37+
7. **Open a Pull Request** – Go to the original repository and submit a PR with a detailed description of your changes.
4338

4439
## Contribution Guidelines
4540

46-
- **New to open source?** No problem! Feel free to start by reviewing the [issues](https://github.com/fahimahammed/learn-postgresql/issues) in this repository and addressing bugs, typos, or other enhancements.
47-
- **Documentation**: If you're improving the documentation (e.g., README, guides), make sure to use clear and concise language.
48-
- **Code Contributions**: If you're contributing code or examples, make sure your code is clean, follows best practices, and is well-documented.
49-
- **Respect Community Standards**: Please be kind and respectful to others in your interactions. We strive to maintain a welcoming and supportive community.
41+
* **New to open source?** Start by reviewing [issues](https://github.com/fahimahammed/learn-postgresql/issues) and fixing small bugs, typos, or formatting errors.
42+
* **Documentation** – Keep language clear and concise. Improve readability wherever possible.
43+
* **Code & Examples** – Ensure your code is clean, follows best practices, and includes comments when necessary.
44+
* **Community Standards** – Be respectful, kind, and supportive in all interactions.
5045

5146
## Issues
5247

53-
Feel free to browse open issues or create new ones if you spot any problems or have suggestions. When creating an issue, try to provide as much information as possible.
48+
If you find a bug, have suggestions, or want to propose new content, feel free to [create an issue](https://github.com/fahimahammed/learn-postgresql/issues) with detailed information.
5449

5550
## Review Process
5651

57-
Once you submit a pull request:
58-
- Your contribution will be reviewed by the maintainers.
59-
- Feedback may be provided, and updates may be requested to ensure the quality of the content.
60-
- Once everything looks good, your pull request will be merged!
52+
* Submitted PRs will be reviewed by maintainers.
53+
* Feedback may be provided, and updates requested to ensure quality.
54+
* Once approved, your PR will be merged into the main repository.
6155

6256
## License
6357

64-
By contributing, you agree that your contributions will be licensed under the MIT License, as detailed in the [LICENSE](LICENSE) file.
58+
By contributing, you agree that your contributions will be licensed under the **MIT License** as detailed in the [LICENSE](LICENSE) file.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Welcome to the **Learn PostgreSQL** repository! This guide provides comprehensiv
1414
- [Querying Data](psql/query.md)
1515
- [SQL Clauses](psql/clauses.md)
1616
- [Advanced Concepts](psql/advance.md)
17+
- [Functions & Procedures](psql/functions.md)
1718
- [Contributing](#contributing)
1819
- [License](#license)
1920
- [Acknowledgements](#acknowledgements)

psql/functions.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# PostgreSQL Functions & Stored Procedures
2+
3+
PostgreSQL provides powerful support for creating **functions** and **stored procedures** to encapsulate SQL logic, improve code reusability, and optimize performance. Functions can return values, while stored procedures can perform actions without necessarily returning data.
4+
5+
---
6+
7+
## Types of Functions
8+
9+
- **SQL Functions**: Written directly in SQL.
10+
- **PL/pgSQL Functions**: Use PostgreSQL’s procedural language for more complex logic.
11+
- **Trigger Functions**: Special functions invoked automatically by triggers.
12+
13+
---
14+
15+
## Creating a Function
16+
17+
```sql
18+
CREATE FUNCTION add_numbers(a INT, b INT)
19+
RETURNS INT AS $$
20+
BEGIN
21+
RETURN a + b;
22+
END;
23+
$$ LANGUAGE plpgsql;
24+
````
25+
26+
**Usage:**
27+
28+
```sql
29+
SELECT add_numbers(5, 10);
30+
```
31+
32+
---
33+
34+
## Stored Procedures
35+
36+
Stored procedures are similar to functions but are called using the `CALL` statement and can perform transactions.
37+
38+
```sql
39+
CREATE PROCEDURE log_message(msg TEXT)
40+
LANGUAGE plpgsql
41+
AS $$
42+
BEGIN
43+
INSERT INTO logs(message, created_at) VALUES (msg, NOW());
44+
END;
45+
$$;
46+
```
47+
48+
**Usage:**
49+
50+
```sql
51+
CALL log_message('Database operation completed');
52+
```
53+
54+
---
55+
56+
## Triggers with Functions
57+
58+
You can use functions as **triggers** to automate actions:
59+
60+
```sql
61+
CREATE OR REPLACE FUNCTION update_timestamp()
62+
RETURNS TRIGGER AS $$
63+
BEGIN
64+
NEW.updated_at = NOW();
65+
RETURN NEW;
66+
END;
67+
$$ LANGUAGE plpgsql;
68+
69+
CREATE TRIGGER update_user_timestamp
70+
BEFORE UPDATE ON users
71+
FOR EACH ROW
72+
EXECUTE FUNCTION update_timestamp();
73+
```
74+
75+
---
76+
77+
## Best Practices
78+
79+
* Use `plpgsql` for procedural logic.
80+
* Keep functions modular and reusable.
81+
* Add exception handling for reliability.
82+
* Use triggers carefully to avoid hidden performance issues.

0 commit comments

Comments
 (0)