Posts

Showing posts with the label exclusion constraint

Seed Data for PostgreSQL with pg-promise and faker

Image
Introduction pg-promise is a powerful library for Node.js dedicated to interacting with PostgreSQL databases. This library is built on top of the native pg driver but provides a high-level abstraction layer with a Promise-based architecture, making the source code cleaner, easier to read and more maintainable. Advantages Automatically manages connections and transactions safely Features a built-in powerful SQL formatting system to prevent SQL Injection attacks Supports handling external SQL files via Query Files and offers exceptionally high performance for bulk data insertion thanks to optimized utilities like pgp.helpers.insert and pgp.helpers.update . Prerequisites In the previous article, I provided instructions on using Prisma to seed data, but using ORMs always introduces limitations such as lack of support for all data types as well as advanced database features. Since ORMs are designed to work with various database types, they sacrifice specific functionalities to solve gener...

GiST Index

Image
Introduction GiST (Generalized Search Tree) is also a high-order balanced tree, which has a hierarchical structure similar to the traditional B-Tree structure. However, the core difference lies in the storage content inside nodes including Root Node and Internal Nodes: each entry in a branch node contains two pieces of information: Predicate: This is the data area created by Postgres from a general level (at the root node) to a detailed level (at the internal node) Nodes at higher levels will contain a general description for all child nodes below them With such a structure, it helps to eliminate extremely quickly data areas that definitely do not satisfy the condition, instead of having to check each row one by one. TID points to lower-level child nodes. Leaf Nodes contain information Specific actual data of the field value TID points to the row data in the Heap Data type GiST supports well for handling data types without linear order (cannot be sorted from smallest to largest like re...