RDS PostgreSQL

Creating a Table

2024-05-27 03:18:28

In RDS-PostgreSQL, you can create a table using SQL. Unless otherwise specified, the table is created under a schema named public in the database by default. When you create a table through pgAdmin, the created database generally has a public schema. When creating a table, you need to specify schema.

Prerequisites

The RDS-PostgreSQL instance has been connected through pgAdmin and added to Servers.

Creating a Schema

1.           Double-click the database to connect to the Server and go to the database menu bar. Select the specified database and click to expand the menu bar that belongs to that database.

2.           Click the Schema option and right-click Create > Schema... This operation will open a schema creation box, as shown in the figure:

                

3.           The creation box of schema and column information is as follows:

                

General: Basic information (mandatory), including the schema name and owner. The default owner is the user who started the database connection.

Security: Permission configuration, including permission granting and security labels. This is an optional item.

Default privileges: Default permissions (optional), including the default permissions for table, sequence, function, and type.

SQL: After you fill in the previous items, the SQL for the created schema is automatically generated, which cannot be filled in or modified.

Click Save. If no error is reported, it means that schema is successfully created.

Creating a Table

Click to open the schema, drop down the menu bar, and click Create > Table... This operation will open a table creation box, as shown in the figure:

General: Basic information (mandatory), including table name, owner, schema, tablespace, and whether it is a partition table. The default owner is the user who started the database connection.

Columns: Column. Here, you can set the column for this table, including column name, data type, data length, precision, whether it is empty, whether it is primary key, and default value. Alternatively, you can select to inherit from a table.

Advanced: Advanced options, including whether to set RLS, whether to force setting RLS, whether to create tables directly by customizing the Type, and so on. These options are optional.

Constraints: Constraint items (optional), such as setting primary keys, foreign keys, and checks, which can be set according to your own needs.

Partitions: Partition table configuration (optional): you can configure partition table properties.

Parameters: Table parameters (optional), including table vacuum and table age limit.

Security: Permission configuration, including permission granting and security labels. This is an optional item.

SQL: After you fill in the previous items, the SQL for the created database is automatically generated, which cannot be filled in or modified.

Click Save to save. If there is no error, it means that the table is created successfully.


AjxJ3jv4CU9R