{"id":20345761,"url":"https://github.com/izzypt/postgresql_101","last_synced_at":"2026-03-19T15:24:59.262Z","repository":{"id":251236513,"uuid":"836810870","full_name":"izzypt/PostGreSQL_101","owner":"izzypt","description":"Learn PGSQL basic concepts , uses and examples.","archived":false,"fork":false,"pushed_at":"2024-08-05T13:26:54.000Z","size":122,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T15:48:01.411Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izzypt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-01T15:52:34.000Z","updated_at":"2024-08-08T18:48:59.000Z","dependencies_parsed_at":"2025-01-14T21:34:21.975Z","dependency_job_id":"2cd0c33e-8426-4804-8bbd-9b8afbe39209","html_url":"https://github.com/izzypt/PostGreSQL_101","commit_stats":null,"previous_names":["izzypt/postgressql_101"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/izzypt/PostGreSQL_101","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FPostGreSQL_101","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FPostGreSQL_101/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FPostGreSQL_101/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FPostGreSQL_101/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzypt","download_url":"https://codeload.github.com/izzypt/PostGreSQL_101/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FPostGreSQL_101/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30206580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T03:24:23.086Z","status":"ssl_error","status_checked_at":"2026-03-07T03:23:11.444Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T22:09:41.409Z","updated_at":"2026-03-07T03:32:51.744Z","avatar_url":"https://github.com/izzypt.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostGresSQL_101\nLearn PGSQL basic concepts , uses and examples.\n\n# Index\n\n- [What is Postgres](#whatispostgres)\n- [Change Database to Dark Theme](#darktheme)\n- [PostGreSQL server](#psqlserver)\n- [What are Schemas and Owners](#schemasandowners)\n- [Connecting to a Database](#connecting)\n- [Create a Database](#createDB)\n- [Database Objects](#DBObjects)\n- [Design a Database](#designdb)\n- [Make a Table](#createtable)\n- [Data Types](#datatypes)\n- [Adding Data to Table](#datatotable)\n- [To See Data](#seedata)\n- [Create Custom Type](#customtype)\n- [Change Column Data Type](#changecolumndatatype)\n- Thinking About Tables\n- Breaking Up Tables\n-  Primary \u0026 Foreign Keys\n- Foreign \u0026 Primary Keys\n- Altering Tables Many Examples\n- Getting Data from One Table\n- Where\n- Conditional Operators\n- Logical Operators\n- Order By\n- Limit\n- GROUP BY\n- Distinct\n- Getting Data from Multiple Tables\n- Inner Join\n- Join 3 Tables\n-  Arithmetic Operators\n- Join with Where\n- Outer Joins\n- Cross Joins\n- Unions\n- Extract\n- IS NULL\n- SIMILAR LIKE \u0026 ~ \n- GROUP BY\n-  HAVING\n- AGGREGATE FUNCTIONS\n- WORKING WITH VIEWS\n- SQL Functions\n- Dollar Quotes\n- Functions that Return Void\n- Get Maximum Product Price\n- Get Total Value of Inventory\n- Get Number of Customers\n- Named Parameters\n- Return a Row / Composite\n- Get Multiple Rows\n- PL/pgSQL\n- Variables in Functions\n- Store Rows in Variables\n- IN INOUT and OUT\n- Using Multiple Outs\n- Return Query Results\n- IF ELSEIF and ELSE\n-  CASE Statement\n- Loop Statement\n- FOR LOOP\n- Result Sets, Blocks \u0026 Raise Notice\n- For Each and Arrays\n- While Loop\n- Continue\n- Stored Procedures\n- Triggers\n- Cursors\n- Installation\n\n\u003ca id=\"whatispostgres\"\u003e\u003c/a\u003e\n\n# What is Postgres ?\n\nIs a powerful, open-source relational database management system (RDBMS) that emphasizes extensibility and SQL compliance.\n\nTo start using `PostgreSQL`, you can install it on your local machine, set up a PostgreSQL server, and use client tools like `psql` (command-line interface) or graphical interfaces like `pgAdmin`. The official PostgreSQL documentation provides detailed installation guides and tutorials to help you get up and running.\n\n### Key Features of PostgreSQL\n\n1. **Open Source**: PostgreSQL is released under the PostgreSQL License, a permissive free software license. This means it is free to use, modify, and distribute.\n\n2. **SQL Compliance**: PostgreSQL supports a substantial portion of the SQL standard and offers many modern features such as foreign keys, triggers, views, and stored procedures.\n\n3. **Extensibility**: One of the standout features of PostgreSQL is its extensibility. You can define your own data types, operators, index types, and even functional languages to use in your queries.\n\n4. **Advanced Data Types**: In addition to standard SQL data types, PostgreSQL supports advanced data types like arrays, hstore (key-value store), JSON/JSONB, XML, and geometric types.\n\n5. **ACID Compliance**: PostgreSQL is fully ACID (Atomicity, Consistency, Isolation, Durability) compliant, ensuring reliable transactions and data integrity.\n\n6. **Concurrency Control**: PostgreSQL uses Multi-Version Concurrency Control (MVCC) to handle concurrent transactions efficiently without requiring read locks.\n\n7. **Full-Text Search**: Built-in support for full-text search, enabling efficient searching within text fields.\n\n8. **Replication and Backup**: PostgreSQL supports various forms of replication (streaming replication, logical replication) and offers tools for robust backup and recovery (pg_dump, pg_basebackup).\n\n9. **Indexing**: It offers a wide range of indexing techniques, including B-tree, hash, GiST, GIN, and BRIN indexes, which can significantly improve query performance.\n\n10. **Community and Ecosystem**: PostgreSQL has a vibrant community and a rich ecosystem of tools, extensions, and third-party applications. Popular extensions include PostGIS for geographic data, pg_stat_statements for tracking query performance, and many more.\n\n### Why Choose PostgreSQL?\n\n- **Reliability and Stability**: PostgreSQL is known for its robustness and stability, making it a trusted choice for critical applications.\n- **Performance**: With its advanced features and optimization capabilities, PostgreSQL can handle large-scale, high-transaction databases efficiently.\n- **Flexibility**: Whether you need to handle simple relational data or complex, unstructured data, PostgreSQL's flexible data model can accommodate various needs.\n- **Community Support**: The active and supportive PostgreSQL community provides extensive documentation, forums, and third-party resources to help you troubleshoot issues and learn new features.\n\n### Use Cases for PostgreSQL\n\n- **Web Applications**: Many web applications use PostgreSQL as their backend database due to its reliability and performance.\n- **Data Warehousing**: PostgreSQL's powerful querying and indexing capabilities make it suitable for data warehousing and business intelligence applications.\n- **Geospatial Data**: With the PostGIS extension, PostgreSQL becomes a powerful database for handling geographic information system (GIS) data.\n- **Financial Systems**: Its ACID compliance and support for complex transactions make PostgreSQL a popular choice for financial applications.\n\n\u003ca id=\"darktheme\"\u003e\u003c/a\u003e\n\n# Change Database to Dark theme\n\nIn `pgAdmin`:\n\n- File -\u003e Preferences -\u003e Miscellaneous -\u003e Themes -\u003e Theme -\u003e Dark\n\n\n\u003ca id=\"psqlserver\"\u003e\u003c/a\u003e\n\n# PostGreSQL server\n\n### PostgreSQL Server Hierarchy\n\n1. **PostgreSQL Server**: This is the top-level instance that manages everything. It can run on a physical or virtual machine and can host multiple databases. When you install PostgreSQL, you are setting up this server.\n\n2. **Databases**: Each PostgreSQL server can contain multiple databases. Databases are separate from each other, and each one can hold its own set of schemas and data. \n\n3. **Schemas**: Within each database, there can be multiple schemas. Schemas help organize database objects like tables, views, functions, etc.\n\n4. **Database Objects**: These include tables, views, indexes, sequences, functions, and more, which reside within schemas.\n\n### Connecting to PostgreSQL\n\n- **Client Connection**: Clients connect to the PostgreSQL server using client software (e.g., `psql`, PgAdmin, applications using database drivers). The connection is typically made to a specific database on the server.\n\n### Example of a Typical Setup\n\n1. **PostgreSQL Server**: Runs on a machine with an IP address and a port (default is 5432).\n2. **Databases on the Server**:\n   - `database1`\n   - `database2`\n3. **Schemas within `database1`**:\n   - `public` (default schema)\n   - `schema1`\n4. **Tables within `schema1` in `database1`**:\n   - `table1`\n   - `table2`\n\n### Connecting to the Server\n\n1. **Server Connection**: Connect to the PostgreSQL server using an IP address or hostname and port number.\n2. **Database Selection**: Specify which database you want to connect to on that server.\n\n### Example Commands\n\n1. **Starting the PostgreSQL Server**:\n   - Typically, the server starts automatically, but it can also be started manually with:\n     ```bash\n     pg_ctl start -D /path/to/data_directory\n     ```\n\n2. **Connecting to the Server and a Specific Database**:\n   - Using `psql`:\n     ```bash\n     psql -h localhost -p 5432 -U username -d database1\n     ```\n     Here:\n     - `-h localhost` specifies the host (local machine in this case).\n     - `-p 5432` specifies the port number.\n     - `-U username` specifies the username.\n     - `-d database1` specifies the database to connect to.\n\n### Visual Representation\n\nHere's a simplified visual representation:\n\n```\nPostgreSQL Server (IP: localhost, Port: 5432)\n  ├── Database: database1\n  │     ├── Schema: public\n  │     │     ├── Table: table1\n  │     │     └── Table: table2\n  │     └── Schema: schema1\n  │           ├── Table: table3\n  │           └── Function: function1\n  ├── Database: database2\n        └── Schema: public\n              ├── Table: table4\n              └── View: view1\n```\n\n### Summary\n\n- **PostgreSQL Server**: The top-level instance managing all databases.\n- **Databases**: Multiple databases can exist within a single PostgreSQL server.\n- **Schemas**: Each database can have multiple schemas for organizing objects.\n- **Client Connections**: Clients connect to the server and specify which database to use.\n\n\u003ca id=\"schemasandowners\"\u003e\u003c/a\u003e\n\n# What are Schemas and Owners\n\n### **Schemas**\nThink of a **schema** like a bookshelf in a library. In a library, there are many bookshelves, and each one holds a collection of books that belong together. For example, one bookshelf might have all the science books, another has storybooks, and another has history books. \n\nIn PostgreSQL, a schema is like that bookshelf. It helps keep all the database objects (like tables and other things) organized. So, instead of all the books (or database objects) being mixed up, they are neatly placed in different sections (schemas).\n\n### **Owners**\nNow, let's talk about **owners**. Imagine that every bookshelf in the library has a librarian who takes care of it. This librarian makes sure that the books are in order, decides who can borrow the books, and who can put new books on the shelf. \n\nIn PostgreSQL, the owner is like that librarian. The owner of a schema or table is the person (or role) who has full control over it. They can decide who gets to see or use the data and who can add new data.\n\n### Importance\n- **Schemas (Bookshelves)**: Keep everything organized. Just like you wouldn't want storybooks mixed in with science books, schemas keep different parts of the database neat and easy to find.\n- **Owners (Librarians)**: Make sure everything is taken care of properly. They decide who can see and use the data, just like a librarian decides who can borrow which books.\n\n### Example\nLet's say we have a school library. We could have:\n\n- **Schema (Bookshelf) for Science**: All science tables (books) go here.\n- **Schema (Bookshelf) for Stories**: All story tables (books) go here.\n\nEach bookshelf has its own librarian:\n- **Owner (Librarian) for Science**: Mrs. Smith takes care of the science bookshelf.\n- **Owner (Librarian) for Stories**: Mr. Brown takes care of the story bookshelf.\n\nMrs. Smith and Mr. Brown make sure the books (tables) are well-organized and decide who can read them.\n\nBy having schemas and owners, PostgreSQL keeps everything tidy and well-managed, just like a well-run library.\n\nIn PostgreSQL, it is the database (DB) that holds multiple schemas, not the other way around. Here's how it works:\n\n### Database and Schemas Relationship\n\n- **Database (DB)**: This is the top-level container. A PostgreSQL server can manage multiple databases.\n- **Schemas**: These are organizational units within a single database. Each schema can contain multiple tables, views, functions, and other database objects.\n\n### Visual Representation\n\nThink of it like this:\n\n```\nPostgreSQL Server\n  ├── Database 1\n  │     ├── Schema A\n  │     │     ├── Table 1\n  │     │     ├── Table 2\n  │     │     └── Function 1\n  │     └── Schema B\n  │           ├── Table 3\n  │           └── View 1\n  ├── Database 2\n  │     ├── Schema C\n  │     └── Schema D\n  └── Database 3\n        └── Schema E\n```\n\n### Example Explanation\n\n- **PostgreSQL Server**: The server can have many databases.\n- **Database 1**: Contains Schema A and Schema B.\n- **Schema A**: Contains Table 1, Table 2, and Function 1.\n- **Schema B**: Contains Table 3 and View 1.\n- **Database 2**: Contains Schema C and Schema D.\n- **Database 3**: Contains Schema E.\n\n### Key Points\n\n- **A schema is part of a single database**.\n- **A database can have multiple schemas**.\n- **Each schema can have multiple database objects (tables, views, etc.)**.\n\n### Creating Databases and Schemas\n\nHere's how you create databases and schemas in PostgreSQL:\n\n1. **Create a Database**\n   ```sql\n   CREATE DATABASE library;\n   ```\n\n   This command creates a new database named `library`.\n\n2. **Connect to the Database**\n   ```sql\n   \\c library\n   ```\n\n   This command connects to the `library` database. In SQL client tools like `psql`, this is how you switch to a different database.\n\n3. **Create Schemas in the Database**\n   ```sql\n   CREATE SCHEMA science;\n   CREATE SCHEMA stories;\n   ```\n\n   These commands create two schemas named `science` and `stories` within the `library` database.\n\n### Summary\n\n- **A PostgreSQL server** can have multiple databases.\n- **Each database** can contain multiple schemas.\n- **Each schema** can contain multiple database objects like tables, views, and functions.\n\n\n\u003ca id=\"connecting\"\u003e\u003c/a\u003e\n\n# Connecting to a DB\n\nTo connect to a PostgreSQL database, you typically need several key pieces of information. Here’s a breakdown of the essential requirements:\n\n### Essential Requirements for Connecting to a PostgreSQL Database\n\n1. **Host**:\n   - The hostname or IP address of the server where the PostgreSQL instance is running. If the server is on the same machine you are connecting from, you can use `localhost`.\n\n2. **Port**:\n   - The port number on which the PostgreSQL server is listening for connections. The default port is `5432`.\n\n3. **Database Name**:\n   - The name of the specific database you want to connect to within the PostgreSQL server.\n\n4. **User**:\n   - The username of the PostgreSQL role that you are using to connect. This role must have the appropriate permissions to access the database.\n\n5. **Password**:\n   - The password associated with the user/role, if password authentication is required.\n\n### Additional Optional Requirements\n\n1. **SSL Mode**:\n   - Specifies whether to use SSL for the connection and what level of validation to perform. Options include `disable`, `allow`, `prefer`, `require`, `verify-ca`, and `verify-full`.\n\n2. **Client Encoding**:\n   - Specifies the character set encoding to use for the connection.\n\n### Example Connection Strings\n\n#### Using `psql` Command-Line Tool\n\n```bash\npsql -h localhost -p 5432 -U myuser -d mydatabase\n```\n\n- `-h localhost`: Specifies the host.\n- `-p 5432`: Specifies the port.\n- `-U myuser`: Specifies the user.\n- `-d mydatabase`: Specifies the database name.\n\nThe tool will prompt for the password unless provided in a secure way (e.g., a `.pgpass` file).\n\n#### Using a Connection String in a Programming Language (e.g., Python with `psycopg2`)\n\n```python\nimport psycopg2\n\nconnection = psycopg2.connect(\n    host=\"localhost\",\n    port=5432,\n    user=\"myuser\",\n    password=\"mypassword\",\n    dbname=\"mydatabase\"\n)\n\ncursor = connection.cursor()\ncursor.execute(\"SELECT version();\")\nprint(cursor.fetchone())\nconnection.close()\n```\n\n- `host=\"localhost\"`: Specifies the host.\n- `port=5432`: Specifies the port.\n- `user=\"myuser\"`: Specifies the user.\n- `password=\"mypassword\"`: Specifies the password.\n- `dbname=\"mydatabase\"`: Specifies the database name.\n\n### Summary of Connection Requirements\n\n1. **Host**: The server address (e.g., `localhost` or an IP address).\n2. **Port**: The server port (default is `5432`).\n3. **Database Name**: The name of the database you want to connect to.\n4. **User**: The username for authentication.\n5. **Password**: The password for authentication.\n6. **SSL Mode** (Optional): For secure connections.\n7. **Client Encoding** (Optional): For character set encoding.\n\nBy providing these details, you can establish a connection to a PostgreSQL database from various clients and programming environments.\n\n\u003ca id=\"createDB\"\u003e\u003c/a\u003e\n\n# Create a Database\n\n- Servers -\u003e PostgreSQL -\u003e Databases (right click) -\u003e Create -\u003e Database\n\n- \u003cimg width=\"1626\" alt=\"image\" src=\"https://github.com/user-attachments/assets/78e85642-8b37-45c8-b9e5-866076188ace\"\u003e\n\nWhen you start creating a DB, you need to: \n\n- Make sure 1 table only represent 1 real world object, for example: \n  - customers\n  - orders\n  - sales\n\n- Columns are going to store only 1 piece of information, like:\n  - name\n  - address\n  - state\n \n- How do different tables relate?\n  - If we have a sales order we are going to need to relate our customer table to the sales table.\n\n\u003ca id=\"DBObjects\"\u003e\u003c/a\u003e\n\n# Database Objects\n\n### Database Objects Include:\n\n1. **Tables**: Store data in rows and columns.\n2. **Indexes**: Improve query performance.\n3. **Views**: Simplify complex queries.\n4. **Sequences**: Generate unique values.\n5. **Functions**: Perform operations and return results.\n6. **Triggers**: Execute procedures automatically on specific events.\n7. **Constraints**: Ensure data integrity.\n8. **Types**: Define custom data types.\n9. **Schemas**: Organize database objects within a database.\n10. **Extensions**: Add additional functionality.\n\n1. **Tables**: The primary storage objects for data. Tables are structured with rows and columns.\n   - Example:\n     ```sql\n     CREATE TABLE employees (\n         id SERIAL PRIMARY KEY,\n         name VARCHAR(100) NOT NULL,\n         position VARCHAR(50),\n         salary NUMERIC CHECK (salary \u003e 0)\n     );\n     ```\n\n2. **Indexes**: Used to speed up the retrieval of rows by creating quick lookup references for table data.\n   - Example:\n     ```sql\n     CREATE INDEX idx_employees_name ON employees (name);\n     ```\n\n3. **Views**: Virtual tables that are based on the result of a SELECT query. They simplify complex queries and provide a level of abstraction.\n   - Example:\n     ```sql\n     CREATE VIEW high_salary_employees AS\n     SELECT name, salary\n     FROM employees\n     WHERE salary \u003e 50000;\n     ```\n\n4. **Sequences**: Objects that generate unique numeric values, often used for auto-incrementing primary keys.\n   - Example:\n     ```sql\n     CREATE SEQUENCE employee_id_seq\n     START WITH 1\n     INCREMENT BY 1;\n     ```\n\n5. **Functions**: Stored procedures that perform operations and return a result. They can be written in various languages, including SQL, PL/pgSQL, and others.\n   - Example:\n     ```sql\n     CREATE FUNCTION get_employee_count() RETURNS INTEGER AS $$\n     BEGIN\n         RETURN (SELECT COUNT(*) FROM employees);\n     END;\n     $$ LANGUAGE plpgsql;\n     ```\n\n6. **Triggers**: Procedures that are automatically executed in response to certain events on a table or view, such as INSERT, UPDATE, or DELETE.\n   - Example:\n     ```sql\n     CREATE TRIGGER update_timestamp\n     BEFORE UPDATE ON employees\n     FOR EACH ROW\n     EXECUTE FUNCTION update_modified_column();\n     ```\n\n7. **Constraints**: Rules enforced on table columns to ensure data integrity. These include PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and NOT NULL constraints.\n   - Example:\n     ```sql\n     ALTER TABLE employees ADD CONSTRAINT unique_name UNIQUE (name);\n     ```\n\n8. **Types**: Custom data types that can be defined to extend PostgreSQL's built-in types.\n   - Example:\n     ```sql\n     CREATE TYPE mood AS ENUM ('happy', 'sad', 'neutral');\n     ```\n\n9. **Schemas**: As mentioned, schemas themselves are also objects that help organize the above objects within a database.\n   - Example:\n     ```sql\n     CREATE SCHEMA hr;\n     ```\n\n10. **Extensions**: Packages that add additional functionality to PostgreSQL. Common extensions include PostGIS (for geographic objects) and pg_trgm (for text search and similarity).\n    - Example:\n      ```sql\n      CREATE EXTENSION IF NOT EXISTS postgis;\n      ```\n\n\u003ca id=\"createtable\"\u003e\u003c/a\u003e\n\n# Create a Table\n\nGo into the `Query`tool and \n\n```\nCREATE TABLE customer(\nfirst_name VARCHAR(30) NOT NULL,\nlast_name VARCHAR(30) NOT NULL,\nemail VARCHAR(60) NOT NULL,\ncompany VARCHAR(60) NOT NULL,\nstreet VARCHAR(50) NOT NULL,\ncity VARCHAR(40) NOT NULL,\nstate CHAR(2) NOT NULL,\nzipcode SMALLINT NOT NULL,\nphone VARCHAR(20) NOT NULL,\nbirth_data DATE NULL,\nsex CHAR(1) NOT NULL,\ndate_entered TIMESTAMP NOT NULL,\nid SERIAL PRIMARY KEY\n)\n\n```\n\n\u003cimg width=\"1687\" alt=\"image\" src=\"https://github.com/user-attachments/assets/85c09c51-f92f-4427-8bc2-cb0cfd550dbd\"\u003e\n\n\nIt should appear under your dbname-\u003e Schemas -\u003e Tables -\u003e tableName (customer)\n\nLet's create  asecond table for the sales person:\n\n\u003cimg width=\"1706\" alt=\"image\" src=\"https://github.com/user-attachments/assets/7eb9e7f7-c80d-488a-9e20-adb0ceacd439\"\u003e\n\n\n\u003ca id=\"datatypes\"\u003e\u003c/a\u003e\n# Data Types\n\n### Numeric Types\n- **SMALLINT**: Small-range integer\n- **INTEGER**: Standard integer\n- **BIGINT**: Large-range integer\n- **DECIMAL**: Exact numeric with user-defined precision\n- **NUMERIC**: Exact numeric with user-defined precision\n- **REAL**: Single precision floating-point number\n- **DOUBLE PRECISION**: Double precision floating-point number\n- **SERIAL**: Auto-incrementing integer\n- **BIGSERIAL**: Auto-incrementing large integer\n\n### Character Types\n- **CHAR(N)**: Fixed-length character string\n- **VARCHAR(N)**: Variable-length character string\n- **TEXT**: Variable-length character string with no length limit\n\n### Binary Data Types\n- **BYTEA**: Binary data (\"byte array\")\n\n### Date/Time Types\n- **DATE**: Calendar date (year, month, day)\n- **TIME**: Time of day (without time zone)\n- **TIME WITH TIME ZONE**: Time of day (with time zone)\n- **TIMESTAMP**: Date and time (without time zone)\n- **TIMESTAMP WITH TIME ZONE**: Date and time (with time zone)\n- **INTERVAL**: Time span\n\n### Boolean Type\n- **BOOLEAN**: Boolean value (true/false)\n\n### Enumerated Type\n- **ENUM**: Enumeration of predefined values\n\n### Geometric Types\n- **POINT**: Geometric point\n- **LINE**: Infinite line\n- **LSEG**: Line segment\n- **BOX**: Rectangular box\n- **PATH**: Geometric path (open or closed)\n- **POLYGON**: Closed geometric path\n- **CIRCLE**: Circle\n\n### Network Address Types\n- **CIDR**: IPv4 or IPv6 network\n- **INET**: IPv4 or IPv6 host address\n- **MACADDR**: MAC address\n\n### Bit String Types\n- **BIT(N)**: Fixed-length bit string\n- **VARBIT(N)**: Variable-length bit string\n\n### Text Search Types\n- **TSVECTOR**: Text search vector\n- **TSQUERY**: Text search query\n\n### UUID Type\n- **UUID**: Universally unique identifier\n\n### JSON Types\n- **JSON**: Textual JSON data\n- **JSONB**: Binary JSON data, optimized for storage and querying\n\n### Arrays\n- **ARRAY**: Array of any data type\n\n### Composite Types\n- **Composite Types**: Custom user-defined composite types\n\n### Range Types\n- **INT4RANGE**: Range of integers\n- **INT8RANGE**: Range of big integers\n- **NUMRANGE**: Range of numerics\n- **TSRANGE**: Range of timestamps without time zone\n- **TSTZRANGE**: Range of timestamps with time zone\n- **DATERANGE**: Range of dates\n\n\n\u003ca id=\"datatotable\"\u003e\u003c/a\u003e\n\n# Adding data to Table\n\n\u003cimg width=\"1673\" alt=\"image\" src=\"https://github.com/user-attachments/assets/075d886b-e1e7-4380-8fda-0108b14824b2\"\u003e\n\n\u003ca id=\"seedata\"\u003e\u003c/a\u003e\n\n# To see data\n\n![image](https://github.com/user-attachments/assets/f515a723-84c0-43f1-8ece-7f146432a25c)\n\n\u003ca id=\"customtype\"\u003e\u003c/a\u003e\n\n# Create Custom Type\n\n\u003cimg width=\"1704\" alt=\"image\" src=\"https://github.com/user-attachments/assets/37c94174-e939-4df5-bcfe-57465502c318\"\u003e\n\n\u003ca id=\"changecolumndatatype\"\u003e\u003c/a\u003e\n\n# Change Column Data Type\n\n\u003cimg width=\"1604\" alt=\"image\" src=\"https://github.com/user-attachments/assets/e76e765e-cfdb-47ad-a787-3cd4e14a6055\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fpostgresql_101","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzypt%2Fpostgresql_101","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fpostgresql_101/lists"}