如何使用原始查询添加一个点?

how to add a point using raw query?

我需要在 postgres 类型的 table 中插入一个点,我试过:

\DB::statement("SET search_path = postgis, public;");
\DB::statement("INSERT INTO points (latlong) VALUES( ST_GeomFromText('POINT(-71.060316 48.432044)', 4326));");

但我收到错误:

SQLSTATE[42883]: Undefined function: 7 ERROR: function st_geomfromtext(unknown, integer) does not exist
LINE 1: INSERT INTO points (latlong) VALUES(ST_GeomFromText('POINT(-...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. (SQL: INSERT INTO points (latlong) VALUES(ST_GeomFromText('POINT(-71.060316 48.432044)', 4326));)

我正在使用安装了 postgis 的 postgres 9.4.5 ..有什么想法吗?

  1. 使用类似 CREATE EXTENSION IF NOT EXISTS postgis
  2. 的方式安装 PostGIS
  3. 通过为 ST_GeomFromText 格式化 WKT 字符串来创建几何图形并不是制作几何图形的最佳方式(较慢、有损、容易出错等), unless 你的源数据已经是文本。要从两个浮点值创建点几何,请使用类似的东西:

    DB::insert('INSERT INTO points (latlong) VALUES(ST_SetSRID(ST_MakePoint(?, ?), 4326))',
               [lng, lat]);