YSQL vs PostgreSQL
YugabyteDB's YSQL API reuses a fork of the query layer of PostgreSQL as its starting point and runs on top of YugabyteDB’s distributed storage layer called DocDB. This architecture allows YSQL to support most PostgreSQL features such as data types, queries, expressions, operators and functions, stored procedures, triggers, extensions, and so on, all of which are expected to work identically on both database systems.
TipA large portion of the documentation and examples written for PostgreSQL would work against YSQL.
The following diagram demonstrates how YugabyteDB reuses the PostgreSQL query layer of, specifically its components that receive the query (postman), the query parser, rewriter, analyzer, as well as components responsible for planning and executing the query. Some of these components have been modified to perform efficiently in a distributed SQL database.
PostgreSQL Features in YSQL
The following table lists the most important YSQL features which you would find familiar if you have worked with PostgreSQL.
|Basics||SQL shell with
|Data Types||String, numeric, temporal types,
|Expressions and Operators||Basic operators and boolean, numeric, date expressions|
|Queries and Joins||Queries, joins,
|Stored Procedures||Support for stored procedures|
|Table Partitions||List, range, and hash partitioning of tables|
|Tablespaces||Definition of tablespaces in YSQL|
|Triggers||Triggers (on data modification) and event triggers (on schema changes)|
|Views||Views and updatable views|
|Cursor||Declaration of cursors in YSQL|
What's Extra in YSQL?
Since YugabyteDB is a distributed SQL database, YSQL has a number of features that are not present in PostgreSQL, as summarized in the following table.
|Data distribution with
||Enables the use of
||Enables pinning of data in tables and table partitions to different geographic locations|
||Enables colocation of multiple smaller tables into one tablet for better performance|