---json
{
"description": "This Howto will show you how to create a SQL table with a SQL file that contains a ''CREATE'' SQL statement",
"low_quality_page": "false",
"name": "Create a table From SQL",
"page_id": "2y8to1aqf22td1go8fy0d"
}
---
====== Tabulify - How to create a table with a CREATE Sql statement file ======
===== About =====
This [[..:howto|Howto]] will show you how to create a [[docs:resource:sql_table|SQL table]] with a [[:docs:resource:sql_ddl|SQL DDL file]] that contains a ''CREATE'' SQL statement with the [[docs:tabul:data:create|Tabul table create command]].
===== Steps =====
==== Start Postgres ====
The next steps will be using the [[howto:postgres:howto_connection_service|postgres howto connection]].
* You need to [[howto:postgres:howto_connection_service#docker|start the postgres docker image]].
tabul service start postgres
1 service was started
Name Type
-------- ------
postgres docker
* [[docs:tabul:connection:ping|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 ====
Delete the target destination
tabul data drop --no-strict-selection *@postgres
We will execute the below [[docs:resource:sql_ddl|SQL Script]] that is located in the [[docs:connection:howto|howto connection]].
-- Create the foo table statement
create table foo (
bar integer
)
==== The data create command ====
With the [[docs:tabul:data:create|tabul data create]] command, if you use a [[docs:flow:runtime_selector|runtime selector]] as first argument, the selected [[docs:resource:runtime|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 [[docs:tabul:data:create|data create]] command
* ''(create_foo.sql@howto)@postgres'' is a [[docs:flow:runtime_selector|runtime selector]] that select the ''create_foo.sql'' in the [[docs:connection:howto|howto]] connection and executes it in the [[howto_connection_service|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 [[docs:tabul:data:describe|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 [[docs:tabul:data:create|tabul data create command]].
\\
\\
[[create_table_with_dependencies|How to copy a star/snowflake schema ?]]