curl - curl中的PostgreSQL查询

标签 curl elasticsearch postgresql-9.1

我有一个Postgresql 9.1表,其中包含“city”,“admin1”和“country”列。我想选择输出格式为“city,admin1,country”的唯一值。

我可能有纽约和明尼苏达州罗切斯特的多个条目,但我只想要其中一个。这是为了填充 flex 搜索索引,而我正在使用JDBC river plugin

以下SELECT在PGAdmin3的SQL编辑器中执行我想要的操作:

SELECT city || ', ' || admin1 || ', ' || country AS city FROM table GROUP BY city, admin1, country;

但在以下方面失败
curl -XPUT 'localhost:9200/_river/nibbel_river/_meta' -d '{

           "type" : "jdbc",
           "jdbc" : {
               "driver" : "org.postgresql.Driver",
               "url" : "jdbc:postgresql://localhost:5432/table",
               "user" : "",
               "password" : "",
           "sql" : "SELECT city || ', ' || admin1 || ', ' || country AS city FROM everything GROUP BY city, admin1, country",
           "poll" : "7d"
           },
           "index" : {
               "index" : "city",
               "type" : "everything"
           }
       }'

与错误
curl: (6) Couldn't resolve host ' || admin1 || ,'
curl: (3) [globbing] unmatched close brace/bracket at pos 102
{"error":"MapperParsingException[Failed to parse [jdbc.sql]]; nested: JsonParseException[Unexpected end-of-input in VALUE_STRING\n at [Source: [B@1192b0c; line: 8, column: 565]]; ","status":400}

这是什么语法?

最佳答案

查询中的所有撇号都必须像这样进行转义:'\''例如:

curl -XPUT 'localhost:9200/_river/nibbel_river/_meta' -d '{
    "type" : "jdbc",
    "jdbc" : {
        "driver" : "org.postgresql.Driver",
        "url" : "jdbc:postgresql://localhost:5432/table",
        "user" : "",
        "password" : "",
        "sql" : "SELECT city || '\'', '\'' || admin1 || '\'', '\'' || country AS city FROM everything GROUP BY city, admin1, country",
        "poll" : "7d"
    },
    "index" : {
        "index" : "city",
        "type" : "everything"
    }
}'

关于curl - curl中的PostgreSQL查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13443628/

相关文章:

sql - PostgreSQL - CTE upsert 返回修改后的行

ubuntu - postgres, ubuntu 如何在启动时重启服务?实例重启后卡在集群上

java - 在 POST 期间突然收到 405 方法不允许在 box-api 中创建文件夹

php - 在 Ubuntu 上将 Google OAuth 与 PHP 集成时需要 CURL PHP 扩展时出错

string - 字符串标记化程序过滤器,例如Elasticsearch中的Shingle

spring-boot - Spring Boot使用基本身份验证连接到Elasticsearch

linux - Perl/curl 如何获取状态码和响应体

Github "Problems parsing JSON",在 Windows 10 上从控制台创建存储库

python - 紧固查询elasticsearch

case - PostgreSQL CASE 语句语法错误