加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 将POINT插入postgres数据库

发布时间:2020-12-13 16:06:27 所属栏目:百科 来源:网络整理
导读:我需要在postgres数据库中插入/更新点列类型. 我正在使用node-postgres 使用POSTGRES管理面板生成的脚本将更新查询显示为 UPDATE public.places SET id =?,user_id =?,business_name = ?,alternate_name = ?,primary_category = ?,categories = ?,descript
我需要在postgres数据库中插入/更新点列类型.

我正在使用node-postgres

使用POSTGRES管理面板生成的脚本将更新查询显示为

UPDATE public.places SET id =?,user_id =?,business_name = ?,alternate_name = ?,primary_category = ?,categories = ?,description = ?,address = ?,city = ?,state = ?,country =?,zip = ?,指向WHERE< condition&gt ;; 我如何从纬度和经度中获得点数? 我已经看过几个使用POSTGIS的答案,但无法使其正常工作. 在POSTGRES(https://www.postgresql.org/docs/9.2/static/xfunc-sql.html)的文档中提到我们可以使用点'(2,1)’,但这不适用于pg查询.

我现在拥有的:

var config = {
  user: 'postgres',database: 'PGDATABASE',password: 'PGPASSWORD!',host: 'localhost',port: 5432,max: 10,idleTimeoutMillis: 30000
};

更新部分:

app.post('/updatePlaces',function(req,res,next) {
    console.log("Update");
    console.log(req.body.places);
    pool.query('UPDATE places SET address = $1,alternate_name = $2,business_name = $3,categories = $4,city = $5,country = $6,description = $7,point = $8,primary_category = $9,state = $10,zip = $11',[req.body.places.address,req.body.places.alternate_name,req.body.places.business_name,req.body.places.categories,req.body.places.city,req.body.places.country,req.body.places.description,(req.body.places.point.x,req.body.places.point.y),req.body.places.primary_category,req.body.places.state,req.body.places.zip],function(err,result) {
      if(err) {
          console.log(err);
          return err;
      }

      res.send(result.rows[0]);
    });
});

尝试了许多不同的传递方式:

>(req.body.places.point.x,req.body.places.point.y)
> point(req.body.places.point.x,req.body.places.point.y)
>点'(2,1)’

所有上述抛出错误.我需要使用POSTGIS吗?

解决方法

经过几次组合,发现这个有效.!!

(‘(‘req.body.places.point.x’,’req.body.places.point.y’)’)

如果有人尝试使用node-postgres尝试执行此操作,则发布回答.

所以你可以使用单引号:插入x值(‘(1,2)’);

但是使用insert into x值(point(1,2));在查询中不起作用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读