postgresql - 如何从 SpatialLite 合并到 PostGIS?

标签 postgresql sqlite merge postgis spatialite

如何将 SpatiaLite 数据库合并到 PostGIS 数据库?

我尝试通过以下命令使用 pgloader:

pgloader db.sqlite3 postgresql:///mydb

但它不起作用。 (我猜它不被支持)。请查看错误输出:

KABOOM!
FATAL error: Could not prepare an sqlite statement.
Code ERROR: no such module: VirtualSpatialIndex.
Database: /tmp/db.sqlite3
SQL: PRAGMA table_info(`SpatialIndex`)

An unhandled error condition has been signalled:
   Could not prepare an sqlite statement.
Code ERROR: no such module: VirtualSpatialIndex.
Database: /tmp/db.sqlite3
SQL: PRAGMA table_info(`SpatialIndex`)




FATAL: Failed to start the monitor thread.

error opening #P"/tmp/pgloader/pgloader.log": Permission denied

我在 SpatialLite 中仅使用简单的 POINT 字段。 SpatialLite 没有其他内容。 (有 Lat/Lng 值)

编辑 1: @Corion

如果我尝试按照您的方式进行操作,我不会出错:

pgloader --before load_spatialite.sql db.sqlite3

但是使用此命令将其加载到 PostGIS:

pgloader --before load_spatialite.sql db.sqlite3 postgresql:///mydb

给我以下错误信息:

2018-10-10T11:29:16.056000Z ERROR Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')
KABOOM!
FATAL error: Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')
An unhandled error condition has been signalled:
   Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')




What I am doing here?

Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')

这里有什么问题?

最佳答案

SpatiaLite是 SQLite 内置的扩展。您将需要一个使用静态链接的 SpatiaLite 构建的 SQLite 二进制文件/库,或者在导入时加载 SpatiaLite 动态扩展(参见链接)。

从盯着 pgloader manpage ,您似乎可以像这样在 SQL 命令前添加 SpatiaLite 扩展以将 SpatiaLite 扩展加载到 SQLite 中:

pgloader --before load_spatialite.sql  /tmp/db.sqlite3

load_spatialite.sql包含

SELECT load_extension('mod_spatialite');

您可能需要也可能不需要设置额外的环境变量,以便为您的进程找到动态库。

关于postgresql - 如何从 SpatialLite 合并到 PostGIS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52738729/

相关文章:

postgresql - 强制 postgres_fdw 使用密码?

sql - SELECT 有优惠条件

postgresql - 如何减去瞬间并与 jOOQ 中的持续时间进行比较

c# - Xamarin Forms 无法创建 SQLite 数据库

java - 想要在进行事务之前检查表是否存在

r - 合并具有可预测拼写错误的数据框

git - 发生冲突时如何强制 merge 成功?

postgresql - 同时删除索引 PostgreSQL 9.1

ios - 如何将 PreCreated 和 Pre Populated 完整的 sqlite database.db 文件复制到 iOS App

java - 合并时如何避免 hsqldb 中的 OOM?