使用posgis的PostgreSQL查询

时间:2018-03-05 15:29:42

标签: sql postgresql postgis

我正在尝试在pgAdmin 4中执行此查询,但是每次尝试运行它时都会遇到错误。请参阅下面的代码和错误:

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- Name: routing; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA routing;


SET search_path = routing, pg_catalog;

SET default_with_oids = true;

--
-- Name: edges; Type: TABLE; Schema: routing; Owner: -
--

CREATE TABLE edges (
    edge_id integer NOT NULL,
    vertex_id1 integer,
    vertex_id2 integer,
    level1 integer,
    level2 integer,
    type character varying(20),
    door character varying(20),
    door_rev character varying(20),
    network character varying(20),
    length double precision,
    x1 double precision,
    y1 double precision,
    x2 double precision,
    y2 double precision,
    the_geom public.geometry,
    CONSTRAINT enforce_dims_the_geom CHECK ((st_ndims(the_geom) = 2)),
    CONSTRAINT enforce_geotype_the_geom CHECK (((geometrytype(the_geom) = 'LINESTRING'::text) OR (the_geom IS NULL))),
    CONSTRAINT enforce_srid_the_geom CHECK ((st_srid(the_geom) = 900913))
);


--
-- Name: vertices; Type: TABLE; Schema: routing; Owner: -
--

CREATE TABLE vertices (
    vertex_id integer NOT NULL,
    level integer,
    the_geom geometry,
    CONSTRAINT enforce_dims_the_geom CHECK ((st_ndims(the_geom) = 2)),
    CONSTRAINT enforce_geotype_the_geom CHECK (((geometrytype(the_geom) = 'POINT'::text) OR (the_geom IS NULL))),
    CONSTRAINT enforce_srid_the_geom CHECK ((st_srid(the_geom) = 900913))
);


--
-- Name: edges_pkey; Type: CONSTRAINT; Schema: routing; Owner: -
--

ALTER TABLE ONLY edges
    ADD CONSTRAINT edges_pkey PRIMARY KEY (edge_id);


--
-- Name: vertices_pkey; Type: CONSTRAINT; Schema: routing; Owner: -
--

ALTER TABLE ONLY vertices
    ADD CONSTRAINT vertices_pkey PRIMARY KEY (vertex_id);


--
-- Name: edges_the_geom_1335166950969; Type: INDEX; Schema: routing; Owner: -
--

CREATE INDEX edges_the_geom_1335166950969 ON edges USING gist (the_geom);


--
-- Name: edges_vertex_id1_1335166950797; Type: INDEX; Schema: routing; Owner: -
--

CREATE INDEX edges_vertex_id1_1335166950797 ON edges USING btree (vertex_id1);


--
-- Name: edges_vertex_id2_1335166950907; Type: INDEX; Schema: routing; Owner: -
--

CREATE INDEX edges_vertex_id2_1335166950907 ON edges USING btree (vertex_id2);


--
-- Name: vertices_the_geom_1335166951469; Type: INDEX; Schema: routing; Owner: -
--

CREATE INDEX vertices_the_geom_1335166951469 ON vertices USING gist (the_geom);

一些背景知识: 我有以下扩展名

  • pgrouting
  • PLPGSQL
  • PostGIS的
  • postgis_topology
  • fuzzystrmatch

在x86_64上运行PostgreSQL 10.3版本

我收到以下输出消息:

ERROR:  function st_ndims(public.geometry) does not exist
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883

我在这里出错的任何想法?原始函数是CONSTRAINT enforce_dims_the_geom CHECK ((public.ndims(the_geom) = 2)),但是当阅读这个PostgreSQL 10.3时,不再支持ndims并且现在已经切换到st_ndims。但是当我改变它时,它仍然没有被识别。

2 个答案:

答案 0 :(得分:1)

问题是您已从搜索路径中删除了public,因此找不到此架构中的任何内容。

尝试

SET search_path = public, routing, pg_catalog;

答案 1 :(得分:0)

感谢小费。 我遇到了这个问题,因为带有-a扩展名的 pg_dump 默认情况下会添加以下语句,从而删除search_path

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;    
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

我必须禁用它才能添加数据