我在postgresql中有一个parcels表,其中分区和zoning_description列是array_agg转换为文本.new.universities表有9行,我需要在输出中返回9行.
此查询的目的是查找这些大学所在的所有属性,并将分区类型折叠为1个唯一列,并将其几何结合/溶解为多个多边形
select array_agg(distinct dp.zoning) zoning,array_agg(distinct dp.zoning_description) zoning_description,
uni.school name_,uni.address,'University' type_,1000 buff,st_union(dp.geom)
from new.universities uni join new.detroit_parcels_update dp
on st_intersects(st_buffer(uni.geom,-10),dp.geom)
group by name_,uni.address,type_,buff
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
ERROR: cannot accumulate arrays of different dimensionality
********** Error **********
ERROR: cannot accumulate arrays of different dimensionality
SQL state: 2202E
Run Code Online (Sandbox Code Playgroud)
我可以做array_agg(不同的dp.zoning :: text)分区等.但这会返回一个完全混乱的列,其中包含数组中的嵌套数组...
基于这里的答案是我更新的查询,它不起作用
select array_agg(distinct zoning_u) zoning,array_agg(distinct zoning_description_u) zoning_description,
uni.school name_,uni.address,'University' type_,1000::int buff,st_union(dp.geom) geom
from new.detroit_parcels_update dp,unnest(zoning) zoning_u,
unnest(zoning_description) zoning_description_u
join new.universities uni
on st_intersects(st_buffer(uni.geom,-10),dp.geom)
group by name_,uni.address,type_,buff order by name_
Run Code Online (Sandbox Code Playgroud)
得到这个错误
ERROR: invalid reference …
Run Code Online (Sandbox Code Playgroud) 我有一个 SQL 语句,它可以 100% 正常工作并返回我需要的内容。
select t1.*,sg.shape from species_geom sg join
(select sg.linkid,array_agg((st.nj_status,st.fed_status)) species
from species_geom sg join species_table st
on sg.linkid = st.linkid
group by sg.linkid)t1
on sg.linkid=t1.linkid
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用查询创建表时,它给了我这个错误
ERROR: column "species" has pseudo-type record[]
********** Error **********
ERROR: column "species" has pseudo-type record[]
SQL state: 42P16
Run Code Online (Sandbox Code Playgroud)
有人可以给我一个很好的解释为什么我不能创建这个表以及如何解决这个问题
ps* 我用create table species2 as
作为我的创建表语句
我试图用一个选择查询更新一个表中的列.
它运行并将整个type_
列更新为religious
(文本字段).
我试图只更新宗教几何与宗地几何相交的行.
update wash_parcels_final
set type_ = t.religious
from (select wash_worship.religious
from wash_parcels_final
join wash_worship
on st_intersects(wash_worship.geom, wash_parcels_final.geom)) t
Run Code Online (Sandbox Code Playgroud) 如何使我创建的所有表都具有架构所有者作为表所有者?
在名为layers的数据库中,我有一个名为hi_ow的架构,所有者为hi_ow。当我运行create table命令时,它将在hi_ow模式中创建表,但所有者默认为Postgres
例:
drop table if exists hi_ow.how_dump;
create table hi_ow.how_dump as
select (st_dump(geom)).geom geom from hi_ow.how;
Run Code Online (Sandbox Code Playgroud)
我知道我可以跑步
alter table hi_ow.how owner to hi_ow
Run Code Online (Sandbox Code Playgroud)
但我希望仅此架构的默认所有者为hi_ow
set owner = hi_ow
在运行多个查询之前是否有某种形式的?还是我需要启用的架构设置中的某些内容?
reassign命令对我不起作用,因为我要切换所有权的表由Postgres拥有。
尝试使用pg_dump备份postgres数据库
我通过命令提示符连接,这是本教程http://www.postgresqltutorial.com/postgresql-backup-database/之后的命令
pg_dump -U postgres -W -F t lucz_2017 > X:\postgres_backup\lucz_backup.tar
Run Code Online (Sandbox Code Playgroud)
它给我一个错误
Invalid command \postgres_backup. Try \? for help.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
数据库名称和路径正确
从CMD运行Windows 7
我正在写入 csv,效果很好,除了某些行的名称中有逗号,当我写入 csv 时,这些逗号会导致字段消失...我如何写入 csv 并忽略 csv 中的逗号行
header = "Id, FACID, County, \n"
row = "{},{},{}\n".format(label2,facidcsv,County)
with open('example.csv', 'a') as wildcsv:
if z==0:
wildcsv.write(header)
wildcsv.write(row)
else:
wildcsv.write(row)
Run Code Online (Sandbox Code Playgroud) 给定一个像'0104002'这样的短信字符串,我需要一个回报01
4002
.
当数字大于0时,基本上返回数字文本字符串的第一部分.然后对于第二部分,返回以下一个非零数字开头的部分,直到字符串结尾.每个输入的数字位置会有所不同,字符串的长度也不一样
到目前为止,我只能得到我需要的第一部分
def lot(num):
lot=""
for x in num:
lot+=x
y=int(x)
if y>0: break
print lot
lot('0104002')
Run Code Online (Sandbox Code Playgroud) 使用 postgis 扩展运行 postgres:尝试在 select into table 语句期间更改列的数据类型
munsummary 表中的 sum_popint 列是双精度的,我想在 select 语句期间将其更改为整数列。我知道我可以使用 update/alter 语句在 select into 语句之前或之后将列数据类型更改为整数,但我想在 select 语句中执行此操作。
SELECT county,
SUM(sum_popint) AS residentialpopulation,
st_union(geom)
INTO countysummary
FROM munsummary
GROUP BY county;
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
reclass=""
for x in xrange(1,32):
if x <=30:
reclass+="remap"+str(x)+"+"
else:
reclass+="remap"+str(x)
print reclass
Run Code Online (Sandbox Code Playgroud)
哪个印刷品:
remap1+remap2+remap3+remap4+...
Run Code Online (Sandbox Code Playgroud)
但我想要打印字符串:
'remap1'+'remap2'+'remap3'+...
Run Code Online (Sandbox Code Playgroud)
我该如何做到这一点?