You can create a new table by specifying the table name, along with all column names and their types.
Along with sharded tables and managed objects, Postgres Pro Shardman supports creation of standart DB objects from PostgreSQL, Postgres Pro Standard, and Postgres Pro Enterprise. These objects can only be created on a current node. This can serve as support for the gradual migration to the distributed Postgres Pro Shardman.
Operations with sharded and unmanaged tables have a number of limitations:
Sharded tables can be parent to unmanaged tables, which can only be joined on a node where the unmanaged table is located.
Unmanaged tables cannot be parent to sharded tables.
Unmanaged tables cannot inherit replicated tables.
Temporary tables cannot participate in the distributed transactions.
Let's try to create a sharded table and check if everything is working properly.
postgres=# create table x(id int primary key, t text) with (distributed_by='id',num_parts=2);
CREATE TABLE
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+---------+-------------------+----------
public | x | partitioned table | postgres
public | x_0 | table | postgres
public | x_1_fdw | foreign table | postgres
(3 rows)
postgres=# \d x_0
Table "public.x_0"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | not null |
t | text | | |
Partition of: x FOR VALUES WITH (modulus 2, remainder 0)
Indexes:
"x_0_pkey" PRIMARY KEY, btree (id)
postgres=# \d x_1_fdw
Foreign table "public.x_1_fdw"
Column | Type | Collation | Nullable | Default | FDW options
--------+---------+-----------+----------+---------+-------------
id | integer | | not null | |
t | text | | | |
Partition of: x FOR VALUES WITH (modulus 2, remainder 1)
Server: shardman_rg_2
FDW options: (table_name 'x_1')
postgres=# insert into x values (1,'t'),(2,'t'),(3,'t');
INSERT 0 3
postgres=# select * from x_0;
id | t
----+---
1 | t
2 | t
(2 rows)
postgres=# select * from x_1_fdw;
id | t
----+---
3 | t
(1 row)
Everything works as expected.
For regular tables:
CREATE TABLE weather (
city varchar(80),
temp_lo int, -- low temperature
temp_hi int, -- high temperature
prcp real, -- precipitation
date date
);
You can enter this into psql with the line
breaks. psql will recognize that the command
is not terminated until the semicolon.
White space (i.e., spaces, tabs, and newlines) can be used freely
in SQL commands. That means you can type the command aligned
differently than above, or even all on one line. Two dashes
(“--”) introduce comments.
Whatever follows them is ignored up to the end of the line. SQL
is case-insensitive about key words and identifiers, except
when identifiers are double-quoted to preserve the case (not done
above).
varchar(80) specifies a data type that can store
arbitrary character strings up to 80 characters in length.
int is the normal integer type. real is
a type for storing single precision floating-point numbers.
date should be self-explanatory. (Yes, the column of
type date is also named date.
This might be convenient or confusing — you choose.)
Postgres Pro Shardman supports the standard
SQL types int,
smallint, real, double
precision, char(,
N)varchar(, N)date,
time, timestamp, and
interval, as well as other types of general utility
and a rich set of geometric types.
Postgres Pro Shardman can be customized with an
arbitrary number of user-defined data types. Consequently, type
names are not key words in the syntax, except where required to
support special cases in the SQL standard.
The second example will store cities and their associated geographical location:
CREATE TABLE cities (
name varchar(80),
location point
);
The point type is an example of a
Postgres Pro Shardman-specific data type.
Finally, it should be mentioned that if you don't need a table any longer or want to recreate it differently you can remove it using the following command:
DROP TABLE tablename;