pg_sample_ext is a PostgreSQL extension that provides a sample function to demonstrate extending PostgreSQL's functionality. The extension includes a custom function to calculate the square of a number and introduces new features in version 1.0.1.


  1. Make sure you have PostgreSQL installed and running.

  2. Clone or download the repository pg_sample_ext to your local machine.

  3. Change to the extension directory:

    $ cd pg_sample_ext

  4. Build and install the extension:

    $ make $ make install

  5. Enable the extension:

CREATE EXTENSION pg_sample_ext;


Once the pg_sample_ext extension is installed and upgraded to version 1.0.1, you can use the included functions and new features in your SQL queries.


The square function calculates the square of a number.

SELECT square(5); -- Returns 25

Composite Type (person_type)

The extension now includes a composite type named person_type that represents a person's name and age. This allows for more structured data storage and retrieval. To insert a row with values from the composite type, use the following syntax:

INSERT INTO my_table (person) VALUES (('John Doe', 30));

Enumerated Type (status_type)

A new enumerated type called status_type is introduced, which provides a predefined set of values for representing different statuses. This enhances data integrity and enables more meaningful data classification. To insert a row with a value from the enumerated type, use the following syntax:

INSERT INTO status_table (status) VALUES ('active');

Domain Type (positive_integer)

The extension now includes a domain type called positive_integer, which is a specialized data type that represents positive integers. This allows for better constraint enforcement and data validation. To insert a row with a positive integer value, use the following syntax:

INSERT INTO quant_table (quantity) VALUES (10);


Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository pg_sample_ext.


This project is licensed under the PostgreSQL License.