PostgreSQL ERROR: Table '' does not occur in the search_path

PostgreSQL 出现这个错误的原因是表名大小写导致的.例如:

create table Test(
    objectid integer not null,                              /*唯一编号*/
    name varchar(32) not null,                              /*名称*/
    constraint pk_test_objectid primary key (objectid)
);
--创建成功后pg自动将表名Test转换为test;
--这里创建空间字段将抛出异常 ERROR:  Table 'Test' does not occur in the search_path
select AddGeometryColumn ('Test','geom',4326,'POINT',2);

解决方案

1.直接将使用的表名转换为小写

select AddGeometryColumn ('test','geom',4326,'POINT',2);

2.禁止pg将表名转换为小写

用双引号将名称括起来.

create table "Test"(
    objectid integer not null,                              /*唯一编号*/
    name varchar(32) not null,                              /*名称*/
    constraint pk_test_objectid primary key (objectid)
);
--创建空间字段
select AddGeometryColumn ('Test','geom',4326,'POINT',2);

猜你喜欢

转载自blog.csdn.net/kmblack1/article/details/81163857