Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "PR Labeler for Hacktoberfest"

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
add-labels:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Label PR for Hacktoberfest
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: |
good first issue
hacktoberfest
hacktoberfest_2025
hacktoberfest-accepted
52 changes: 23 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,58 @@
# Contributing to Learn PostgreSQL

Thank you for considering contributing to the **Learn PostgreSQL** project! Your contributions help improve the quality of this resource and are greatly appreciated.

## Hacktoberfest
# Contributing to Learn PostgreSQL

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.
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.

### What is Hacktoberfest?
## Hacktoberfest 2025

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.
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.

You can read more about Hacktoberfest [here](https://hacktoberfest.com).
Learn more about Hacktoberfest [here](https://hacktoberfest.com).

## How to Contribute

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.
2. **Clone the repository**: Clone your fork locally.
1. **Fork the repository** Click the "Fork" button at the top right of this page.
2. **Clone your fork** – Clone it to your local machine:

```bash
git clone https://github.com/fahimahammed/learn-postgresql.git
```
3. **Create a branch** – Make a new branch for your work:

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

4. **Make your changes**: Implement your changes. You can improve documentation, fix issues, or add new PostgreSQL learning content.

5. **Commit your changes**: After making changes, commit them with a descriptive message.
```bash
git add .
git commit -m "Your descriptive commit message"
git commit -m "Add guide for PostgreSQL JSON functions"
```
6. **Push your branch** – Push your changes to your fork:

6. **Push your changes**: Push the changes to your fork.
```bash
git push origin your-branch-name
```

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.
7. **Open a Pull Request** – Go to the original repository and submit a PR with a detailed description of your changes.

## Contribution Guidelines

- **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.
- **Documentation**: If you're improving the documentation (e.g., README, guides), make sure to use clear and concise language.
- **Code Contributions**: If you're contributing code or examples, make sure your code is clean, follows best practices, and is well-documented.
- **Respect Community Standards**: Please be kind and respectful to others in your interactions. We strive to maintain a welcoming and supportive community.
* **New to open source?** Start by reviewing [issues](https://github.com/fahimahammed/learn-postgresql/issues) and fixing small bugs, typos, or formatting errors.
* **Documentation** – Keep language clear and concise. Improve readability wherever possible.
* **Code & Examples** – Ensure your code is clean, follows best practices, and includes comments when necessary.
* **Community Standards** – Be respectful, kind, and supportive in all interactions.

## Issues

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.
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.

## Review Process

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

## License

By contributing, you agree that your contributions will be licensed under the MIT License, as detailed in the [LICENSE](LICENSE) file.
By contributing, you agree that your contributions will be licensed under the **MIT License** as detailed in the [LICENSE](LICENSE) file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Welcome to the **Learn PostgreSQL** repository! This guide provides comprehensiv
- [Querying Data](psql/query.md)
- [SQL Clauses](psql/clauses.md)
- [Advanced Concepts](psql/advance.md)
- [Functions & Procedures](psql/functions.md)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgements](#acknowledgements)
Expand Down
82 changes: 82 additions & 0 deletions psql/functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# PostgreSQL Functions & Stored Procedures

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.

---

## Types of Functions

- **SQL Functions**: Written directly in SQL.
- **PL/pgSQL Functions**: Use PostgreSQL’s procedural language for more complex logic.
- **Trigger Functions**: Special functions invoked automatically by triggers.

---

## Creating a Function

```sql
CREATE FUNCTION add_numbers(a INT, b INT)
RETURNS INT AS $$
BEGIN
RETURN a + b;
END;
$$ LANGUAGE plpgsql;
````

**Usage:**

```sql
SELECT add_numbers(5, 10);
```

---

## Stored Procedures

Stored procedures are similar to functions but are called using the `CALL` statement and can perform transactions.

```sql
CREATE PROCEDURE log_message(msg TEXT)
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO logs(message, created_at) VALUES (msg, NOW());
END;
$$;
```

**Usage:**

```sql
CALL log_message('Database operation completed');
```

---

## Triggers with Functions

You can use functions as **triggers** to automate actions:

```sql
CREATE OR REPLACE FUNCTION update_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER update_user_timestamp
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_timestamp();
```

---

## Best Practices

* Use `plpgsql` for procedural logic.
* Keep functions modular and reusable.
* Add exception handling for reliability.
* Use triggers carefully to avoid hidden performance issues.
Loading