About
This Howto will show you how to copy the data definition of a SQL table from another SQL table by using the Tabul table create command.
This command does not copy the data. It just create the structure (ie it performs a SQL CREATE statement). If you want to copy the data, use the tabul data transfer command instead.
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
Create a table from another table
The below command will create:
- the table tpcds_sales into the Postgres Howto connection
- from the data definition of the tpcds store_sales table
- with the tabul data create command.
tabul data create store_sales@tpcds tpcds_sales@postgres
where:
- store_sales@tpcds is a data selector
- and tpcds_sales@postgres is a target data URI
Results of the create operation
input target
----------------- --------------------
store_sales@tpcds tpcds_sales@postgres
Check the metadata
Check the metadata with the tabul data describe command
tabul data describe tpcds_sales@postgres
Structure of the resource tpcds_sales@postgres
position name type precision scale primary_key nullable autoincrement comment
-------- --------------------- ------- --------- ----- ----------- -------- ------------- -------
1 ss_sold_date_sk integer 10 0 x
2 ss_sold_time_sk integer 10 0 x
3 ss_item_sk integer 10 0 x
4 ss_customer_sk integer 10 0 x
5 ss_cdemo_sk integer 10 0 x
6 ss_hdemo_sk integer 10 0 x
7 ss_addr_sk integer 10 0 x
8 ss_store_sk integer 10 0 x
9 ss_promo_sk integer 10 0 x
10 ss_ticket_number integer 10 0 x
11 ss_quantity integer 10 0 x
12 ss_wholesale_cost numeric 7 2 x
13 ss_list_price numeric 7 2 x
14 ss_sales_price numeric 7 2 x
15 ss_ext_discount_amt numeric 7 2 x
16 ss_ext_sales_price numeric 7 2 x
17 ss_ext_wholesale_cost numeric 7 2 x
18 ss_ext_list_price numeric 7 2 x
19 ss_ext_tax numeric 7 2 x
20 ss_coupon_amt numeric 7 2 x
21 ss_net_paid numeric 7 2 x
22 ss_net_paid_inc_tax numeric 7 2 x
23 ss_net_profit numeric 7 2 x
Next
You can also create a table and its dependencies (foreign tables) at once with the tabul data create command.
How to copy a star/snowflake schema ?