website logo
⌘K
šŸ Homepage
šŸ‘‹Introduction
Key Concepts & Architecture
šŸš€Run Oxla in 2 minutes
šŸƒā€ā™‚ļøRun Oxla on S3
šŸ›«Multi-node Deployment
šŸ‘Øā€šŸ’»SQL Reference
SQL Queries
SQL Clauses
SQL Data Types
SQL Functions
Schema
Comment Support
🚨Error Handling
šŸ†šDifferences Between Oxla vs. PostgreSQL
šŸ“ˆPublic Metrics
Docs powered by
Archbee
SQL Reference

Schema

17min

What is Schema?

Have you ever wondered how to work with your fellows in one database without interfering with each other? Is it possible to organize the database objects into logical groups which do not collide with the other objects' names?

We can do those things with Schema.

A schema is a collection of tables. A schema also contains views, indexes, sequences, data types, operators, and functions. We support multiple schemas. For example, you can have a database named oxla and have multiple schemas based on your needs, like auth, model, business, etc.

Document image


Default Schema in Oxla

By default, the public schema is used in Oxla.

When unqualified table_name is used, that table_name is equivalent to public.table_name. It also applies to CREATE, DROP, and SELECT TABLE statements.

šŸ’” Furthermore, you can create multiple schemas per your needs.

Schema Usage Scenarios

#1 - Create a Schema

The basic syntax of creating a schema is as follows:

Create schema
|
CREATE SCHEMA schema_name;


schema_name is the name of the schema you are going to create.

#2 - Create a Table in Schema

The syntax to create a table in a specified schema is as follows:

Pgsql
|
CREATE TABLE schema_name.table_name(
...
);

  • schema_name is the schema that you have created.
  • table_name is the table name you are going to create.

#3 - Select a Table in Schema

After creating the table and inserting some data, display all rows with the syntax below:

Display table
|
SELECT * FROM schema_name.table_name;

  • schema_name is the name of the schema.
  • table_name is the name of the table you want to display.

#4 - Drop the Schema

To drop an empty schema where no objects remain in it, use the command below:

Pgsql
|
DROP SCHEMA schema_name;


Tables reside in a schema, so it is impossible to drop a schema without also dropping the tables. With the command below, you will also drop the schema with the tables.

Pgsql
|
DROP SCHEMA schema_name CASCADE;


Example #1

1) First, connect to Oxla and create a schema as shown below:

Pgsql
|
CREATE SCHEMA oxlarefs;


2) Next, create a table in the above schema with the following details:

Pgsql
|
CREATE TABLE oxlarefs.functions(
  id int,
  function_name string,
  active bool
);

INSERT INTO oxlarefs.functions(id, function_name, active)
VALUES 
('1111', 'Numeric', 'TRUE'),
('2222', 'String', 'TRUE'),
('3333', 'Timestamp', 'TRUE'),
('4444', 'JSON', 'TRUE'),
('5555', 'Boolean', 'TRUE');


3) You can verify and show the table made with the command below:

Pgsql
|
SELECT * FROM oxlarefs.functions;


4) You will get the following result:

Pgsql
|
+------+---------------+---------+
| id   | function_name | active  |
+------+---------------+---------+
| 1111 | Numeric       | t       |
| 2222 | String        | t       |
| 3333 | Timestamp     | t       |
| 4444 | JSON          | t       |
| 5555 | Boolean       | t       |
+------+---------------+---------+


Example #2

From Example #1, we created a new schema and a table. Use the command below to delete the schema and also the tables in it:

Drop schema cascade
|
DROP SCHEMA oxlarefs CASCADE;


Another case is if there is no table or object created inside the schema, you can use the following command to drop the schema:

Drop schema
|
DROP SCHEMA oxlarefs;




Updated 31 Aug 2023
Did this page help you?
PREVIOUS
has_schema_privilege()
NEXT
Comment Support
Docs powered by
Archbee
TABLE OF CONTENTS
What is Schema?
Default Schema in Oxla
Schema Usage Scenarios
#1 - Create a Schema
#2 - Create a Table in Schema
#3 - Select a Table in Schema
#4 - Drop the Schema
Example #1
Example #2
Docs powered by
Archbee

Dedicated to data analytics that provides 10x faster execution of analytical queries than current state of the art solutions. We are launching SOON! Join the waiting list for more info.




©2023 Oxla