Found 4 bookmarks
Newest
dbdiagram Public API | dbdiagram Docs
dbdiagram Public API | dbdiagram Docs
# Introduction ***API access is currently in Beta and only available if you have a paid plan.*** Using these APIs, you are able to programmatically work with dbdiagram. For example: - You can programmatically CRUD the diagram. - Generate an [embed link](https://docs.dbdiagram.io/embedding) for a specific diagram. This is useful especially if you need to attach the diagram into your documents, blogs and websites. # Authorization - API tokens are managed at the [workspace](https://docs.dbdiagram.io/workspaces) level, granting access to all diagrams within the workspace. - Workspace owners can generate new tokens via the "API Tokens" tab in the workspace window. - API tokens should be securely held within the user's environment to avoid leaking the key. # Errors HTTP Code Description 200 - OK Everything worked as expected. 400 - Bad Request The request was unacceptable due to missing request parameter or wrong request structure. 401 - Unauthorized No valid API key provided. 403 - Forbidden The API Key owner does not have permission to perform the request. 404 - Not Found The requested resource does not exist or cannot found. 429 - Too Many Requests Too many requests were sent. 500 - Internal Error Something went wrong on dbdiagram side (rarely). # Rate-Limiting ## Overview To prevent DDoS attacks, every API request should go through our rate limit layer which will throttle the request if a user exceeds limit quotas. The rate limit is based on user and endpoint, quotas (per time frame) which maybe different for each endpoint are divided by levels as the table below: Level Quota Note Level 1 120 requests / minute At least every API request is this level Level 2 60 requests / minute Request requires a lot of resource Level 3 20 requests / minute Request that heavily affect our server's resources ## Return Header And Status Code If a request is blocked because of it exceed the limit quota, status code is set to **429: Too Many Requests**. Every API request's response header contains the following fields: - **RateLimit-Limit**: *your_limit_quota_of_endpoint* - **RateLimit-Remaining**: *remaining_requests_until_reset* - **RateLimit-Reset**: *next_reset_time* - **Retry-After**: *next_reset_time(only available when status code is 429)*
·docs.dbdiagram.io·
dbdiagram Public API | dbdiagram Docs
PostgreSQL Generated Columns
PostgreSQL Generated Columns
In this tutorial, you will learn about PostgreSQL generated columns whose values are automatically calculated from other columns.
In PostgreSQL, a generated column is a special type of column whose values are automatically calculated based on expressions or values from other columns. A generated column is referred to as a computed column in the SQL Server or a virtual column in Oracle .
There are two kinds of generated columns: Stored: A stored generated column is calculated when it is inserted or updated and occupies storage space. Virtual: A virtual generated column is computed when it is read and does not occupy storage space.
A virtual generated column is like a view, whereas a stored generated column is similar to a materialized view. Unlike a material view, PostgreSQL automatically updates data for stored generated columns.
PostgreSQL currently implements only stored generated columns.
·neon.tech·
PostgreSQL Generated Columns
PostgreSQL Identity Column
PostgreSQL Identity Column
This tutorial shows you how to use the GENERATED AS IDENTITY constraint to create the PostgreSQL identity column for a table.
PostgreSQL version 10 introduced a new constraint GENERATED AS IDENTITY that allows you to automatically assign a unique number to a column.
The GENERATED AS IDENTITY constraint is the SQL standard-conforming variant of the good old SERIAL column.
The following illustrates the syntax of the GENERATED AS IDENTITY constraint: column_name type GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY[ ( sequence_option ) ]
In this syntax: The type can be SMALLINT, INT, or BIGINT. The GENERATED ALWAYS instructs PostgreSQL to always generate a value for the identity column. If you attempt to insert (or update) values into the GENERATED ALWAYS AS IDENTITY column, PostgreSQL will issue an error. The GENERATED BY DEFAULT instructs PostgreSQL to generate a value for the identity column. However, if you supply a value for insert or update, PostgreSQL will use that value to insert into the identity column instead of using the system-generated value.
PostgreSQL allows a table to have more than one identity column. Like the SERIAL, the GENERATED AS IDENTITY constraint also uses the SEQUENCE object internally.
To fix the error, you can use the OVERRIDING SYSTEM VALUE clause as follows: INSERT INTO color (color_id, color_name) OVERRIDING SYSTEM VALUE VALUES(2, 'Green');
Alternatively, you can use GENERATED BY DEFAULT AS IDENTITY instead.
Because the GENERATED AS IDENTITY constraint uses the SEQUENCE object, you can specify the sequence options for the system-generated values.
For example, you can specify the starting value and the increment as follows: DROP TABLE color; CREATE TABLE color ( color_id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10 INCREMENT BY 10), color_name VARCHAR NOT NULL );
In this example, the system-generated value for the color_id column starts with 10 and the increment value is also 10.
·neon.tech·
PostgreSQL Identity Column