제목

Populate_Geometry_Columns — Ensures geometry columns are defined with type modifiers or have appropriate spatial constraints.

요약

text Populate_Geometry_Columns(boolean use_typmod=true);

int Populate_Geometry_Columns(oid relation_oid, boolean use_typmod=true);

설명

지오메트리 컬럼이 타입 변경자로 정의되거나 적절한 공간 제약을 가지고 있는지 확인합니다. 이 함수는 공간 관련 테이블들이 geometry_columns 뷰에 올바르게 등록되도록 합니다. 기본적으로 유형 변경자를 가지지 않는 모든 지오메트리 컬럼들을 유형 변경자를 가진 지오메트리 컬럼들로 변환시킵니다. 엣날식 동작을 원하면 use_typmod=false으로 설정

하위 호환성 및 각 차일드 테이블이 서로 다른 도형 유형을 가질 수도 있는 테이블 상속 같은 공간 필요성을 위해, 구 버전 확인 제약조건 습성을 계속 지원합니다. 구 버전 습성이 필요하다면, use_typmod=false 처럼 새 선택적 인자를 거짓으로 패스해야 합니다. 이렇게 하면 유형 변경자는 없지만 제약조건 3개가 정의된 도형 열을 생성할 것입니다. 다시 말해, 모든 도형 열이 적어도 3개의 제약조건을 가진 테이블에 종속된다는 뜻입니다:

  • enforce_dims_the_geom - ensures every geometry has the same dimension (see ST_NDims)

  • enforce_geotype_the_geom - ensures every geometry is of the same type (see GeometryType)

  • enforce_srid_the_geom - ensures every geometry is in the same projection (see ST_SRID)

oid 테이블이 제공될 경우, 이 함수는 테이블에 있는 모든 도형 열의 SRID, 차원, 그리고 도형 유형을 결정하려 하며, 필요한 경우 제약조건을 추가하기도 합니다. 함수가 제대로 작동했다면, 올바른 행이 geometry_columns 테이블에 삽입됩니다. 아닐 경우, 예외가 잡혀 문제점을 설명하는 오류 메시지가 뜹니다.

oid 테이블과 함께 oid 뷰가 제공될 경우, 이 함수는 geometry_columns 테이블에 올바른 항목을 삽입하며 뷰에 있는 모든 도형의 SRID, 차원, 유형을 결정하려 하지만, 제약조건을 강제하지는 않습니다.

이 함수의 파라미터가 없는 변종은, 공간 제약조건을 테이블의 적절한 곳에 추가하며 먼저 데이터베이스 내부의 모든 공간 테이블 및 뷰에 대해 geometry_columns 테이블의 용량을 줄이고(truncate) 다시 채우는 파라미터가 있는 변종을 위한 단순 래퍼입니다. 파라미터가 없는 변종은 데이터베이스 내부에서 감지된 도형 열의 개수 및 geometry_columns 테이블로 삽입된 개수를 요약해서 반환합니다. 파라미터가 있는 버전은 단순히 geometry_columns 테이블로 삽입된 행의 개수를 반환합니다.

1.4.0 버전부터 사용할 수 있습니다.

변경 사항: 2.0.0 버전. 이제 도형 유형을 제한하기 위해 확인 제약조건 대신 유형 변경자를 이용합니다. 새 use_typmod 를 거짓으로 설정하면, 확인 제약조건 습성을 계속 쓸 수 있습니다.

개선 사항: 2.0.0 버전. 열 생성시 유형 변경자와 함께, 또는 확인 제약조건과 함께 생성할지 통제할 수 있는 use_typmod 의 선택적 인자가 추가됐습니다.

예시

This example populates geometry column metadata using typmod behavior. For this to work, there must be existing data.

Code
CREATE TABLE public.myspatial_table(gid serial, geom geometry);
INSERT INTO myspatial_table(geom) VALUES(ST_GeomFromText('LINESTRING(1 2,3 4)', 4326) );
SELECT Populate_Geometry_Columns('public.myspatial_table'::regclass);
래스터 출력
1

Describe the table to see the typmod-based geometry column.

Code
\d myspatial_table
래스터 출력
Table "public.myspatial_table"

Columns:
  gid  integer                    not null default nextval('myspatial_table_gid_seq'::regclass)
  geom geometry(LineString,4326)

This example changes the geometry columns to use constraints if they are not typmod or already constrained. For this to work, there must be existing data.

Code
CREATE TABLE public.myspatial_table_cs(gid serial, geom geometry);
INSERT INTO myspatial_table_cs(geom) VALUES(ST_GeomFromText('LINESTRING(1 2,3 4)', 4326) );
SELECT Populate_Geometry_Columns('public.myspatial_table_cs'::regclass, false);
래스터 출력
1

Describe the table to see the constraint-based geometry column.

Code
\d myspatial_table_cs
래스터 출력
Table "public.myspatial_table_cs"
 Column |   Type   |                            Modifiers
--------+----------+------------------------------------------------------------------
 gid    | integer  | not null default nextval('myspatial_table_cs_gid_seq'::regclass)
 geom   | geometry |
Check constraints:
    "enforce_dims_geom" CHECK (st_ndims(geom) = 2)
    "enforce_geotype_geom" CHECK (geometrytype(geom) = 'LINESTRING'::text OR geom IS NULL)
    "enforce_srid_geom" CHECK (st_srid(geom) = 4326)