Zia*_*Zia 3 postgresql constraint postgis
继我之前的相关问题之后,让我详细说明一下这个话题。
raster2pgsql是一个光栅加载器可执行文件,它在 PostGIS 中加载 GDAL 支持的光栅格式。它有一个-C定义如下的标志:
gislinux@gislinux-Precision-M4600:~$ raster2pgsql
输出:
-C Set the standard set of constraints on the raster
column after the rasters are loaded. Some constraints may fail
if one or more rasters violate the constraint.
Run Code Online (Sandbox Code Playgroud)
当我像这样导入我的光栅文件时:
gislinux@gislinux-Precision-M4600:~$ raster2pgsql -d -I -C -M -F -t 100x100 -s 4326
us_tmin_2012.01.asc chp05.us_tmin_new | psql -h localhost -p 5432 -U postgres -d pgrouting
Run Code Online (Sandbox Code Playgroud)
输出:
ANALYZE
NOTICE: Adding SRID constraint
CONTEXT: PL/pgSQL function addrasterconstraints line 53 at RETURN
NOTICE: Adding scale-X constraint
Run Code Online (Sandbox Code Playgroud)
-C标志对这个新表应用的约束很少。
pgrouting=# \d+ chp05.us_tmin_new
Run Code Online (Sandbox Code Playgroud)
输出:
Indexes:
"us_tmin_new_pkey" PRIMARY KEY, btree (rid)
"us_tmin_new_rast_gist" gist (st_convexhull(rast))
Check constraints:
"enforce_height_rast" CHECK (st_height(rast) = ANY (ARRAY[100, 21]))
"enforce_max_extent_rast" CHECK (st_coveredby(st_convexhull(rast),
Run Code Online (Sandbox Code Playgroud)
标准约束包括以下规则(尽管这些约束独立作用于所有传入的栅格切片):
现在,为了运行ST_MapAlgebra函数,我不得不单独删除这些 std 约束,我使用过:
ALTER TABLE chp05.us_tmin_new DROP CONSTRAINT enforce_scalex_rast
Run Code Online (Sandbox Code Playgroud)
在 pgAdmin SQL Editor 中为每个 std 约束。但是现在我不知道如何将这些标准约束带回来?以下命令不起作用:
ALTER TABLE chp05.us_tmin_new ADD CONSTRAINT enforce_scalex_rast unique (rast);
Run Code Online (Sandbox Code Playgroud)
并给出以下错误:
Run Code Online (Sandbox Code Playgroud)ERROR: data type raster has no default operator class for access method "btree" HINT: You must specify an operator class for the index or define a default operator class for the data type.
好的,所以你:
您只在输出中显示了两个约束(为什么?),但您显示的两个是CHECK约束,而不是UNIQUE约束。因此,尝试用UNIQUE约束替换它们是绝对没有意义的。
你必须:
因此,假设您"enforce_height_rast" CHECK (st_height(rast) = ANY (ARRAY[100, 21]))对 table有约束chp05.us_tmin_new。要重新创建它,您必须使用相同的约束表达式和名称。那就是:
ALTER TABLE chp05.us_tmin_new
ADD CONSTRAINT "enforce_height_rast" CHECK (st_height(rast) = ANY (ARRAY[100, 21]));
Run Code Online (Sandbox Code Playgroud)
看看它如何方便地匹配psql约束的输出?您只需复制并粘贴即可。
我不知道你为什么要尝试创建一个独特的约束,而它不可能产生你上面描述的效果。
(顺便说一句,您的描述有点不准确。这些检查约束并没有断言所有栅格都具有相同数量的波段等。他们断言所有约束的波段数都等于某个特定值。换句话说,该约束与表中的其他值无关,它为每一行独立检查。)