About
This Howto will show you how to create a SQL table with a SQL DDL file that contains a CREATE SQL statement with the Tabul table create command.
Steps
Start Postgres
The next steps will be using the postgres howto connection.
- You need to start the postgres docker image.
tabul service start postgres
1 service was started
Name Type
-------- ------
postgres docker
- Ping your connection to check that the database is up.
tabul connection ping postgres
The connection (postgres) has been pinged successfully
The CREATE table statement
We will execute the below SQL Script that is located in the howto connection.
-- Create the foo table statement
create table foo (
bar integer
)
The data create command
With the tabul data create command, if you use a runtime selector as first argument, the selected runtime are executed.
To execute the previous SQL script, the below the command should be executed:
tabul data create '(create_foo.sql@howto)@postgres'
# The quotes are mandatory because parenthesis have a meaning in Bash (ie they start a subshell)
where:
- data create is the data create command
- (create_foo.sql@howto)@postgres is a runtime selector that select the create_foo.sql in the howto connection and executes it in the postgres connection
List of runtime executed
runtime_data_uri exit_code count latency data_uri error_message
------------------------------- --------- ----- ------- ------------------------------------------------------------- -------------
(create_foo.sql@howto)@postgres 0 1 0.23s execute/20251110-204521-829-pipe-anonymous/create_foo.log@tmp
Check the metadata
Check the metadata with the tabul data describe command
tabul data describe foo@postgres
Structure of the resource foo@postgres
position name type precision scale primary_key nullable autoincrement comment
-------- ---- ------- --------- ----- ----------- -------- ------------- -------
1 bar integer 10 0 x
Next
You can also create a table and its dependencies (foreign tables) at once with the tabul data create command.