我正在查询我的postgresql 9.6数据库,并从Node服务器中生成json输出。我已经开始工作了,除了我的属性名称“ col1Name”和“ col2Name”被删除并替换为f1和f2。我在网上找到有关使用子查询保留键名的信息(例如“从(从表中选择col1,从表中选择col2,选择col1,从表t选择col1,col2)”),但我无法弄清楚如何在此代码段中做到这一点。我认为嵌套有误,但我眼花cross乱。
var query = "SELECT row_to_json(fc) FROM ( " +
"SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features FROM (" +
"SELECT 'Feature' As type, ST_AsGeoJSON(fg.geom)::json As geometry, " +
"row_to_json((col1Name, col2Name)) As properties FROM myTable As fg" +
") As f" +
") As fc";