CREATE TABLE countrymeasurements ( countrycode int NOT NULL, countryname character varying(30) NOT NULL, languagename character varying (30) NOT NULL, daysofoperation character varying(30) NOT NULL, salesparts bigint, replaceparts bigint ) PARTITION BY LIST(countrycode) ( partition india values(1), partition japan values(2), partition china values(3), partition malaysia values(4) );Recibo ERROR: error de sintaxis en o cerca de "(". Lo que me falta aquí. Estoy usando postgres12
No sé dónde encontraste esa sintaxis, obviamente no en el manual . Como puede ver , las particiones se crean usando create table .. as partition of en Postgres:
Defina la tabla:
CREATE TABLE countrymeasurements ( countrycode int NOT NULL, countryname character varying(30) NOT NULL, languagename character varying (30) NOT NULL, daysofoperation character varying(30) NOT NULL, salesparts bigint, replaceparts bigint ) PARTITION BY LIST(countrycode);Defina las particiones:
create table india partition of countrymeasurements for values in (1); create table japan partition of countrymeasurements for values in (2); create table china partition of countrymeasurements for values in (3); create table malaysia partition of countrymeasurements for values in (4);¡Bienvenido a stackoverflow! Tenga en cuenta que hacer preguntas aquí sin mostrar una investigación previa puede rechazar a personas que de otro modo les encantaría ayudar.
En este caso, verifiqué y no encontré ningún ejemplo oficial para la partición de listas. Pero, si simplemente acorta su declaración, creará una tabla usando los valores en la columna de countrycode de país para particionar:
CREATE TABLE countrymeasurements ( countrycode int NOT NULL, countryname character varying(30) NOT NULL, languagename character varying (30) NOT NULL, daysofoperation character varying(30) NOT NULL, salesparts bigint, replaceparts bigint ) PARTITION BY LIST(countrycode) ;El comando psql describe table muestra que la partición es la solicitada:
psql=# \d countrymeasurements Table "public.countrymeasurements" Column | Type | Collation | Nullable | Default -----------------+-----------------------+-----------+----------+--------- countrycode | integer | | not null | countryname | character varying(30) | | not null | languagename | character varying(30) | | not null | daysofoperation | character varying(30) | | not null | salesparts | bigint | | | replaceparts | bigint | | | Partition key: LIST (countrycode)Luego puede definir las particiones como en la respuesta de @a_horse_with_no_name. Pero, algunas notas sobre el uso de tal estrategia pueden estar en orden.
Notas: