或者这样做:
可以写语句或采用以下的方法
网上转录下来的方法:
步骤:
1.将excel表格字段,按照postgresql
2.用记事本打开csv文件,另存为utf-8格式。
3.使用pgadmin客户端链接postgresql数据库,执行如下脚本,导入csv文件到postgresql数据表:
copy
testdata
from
'd:/test/testdata.csv'
delimiter
as','
csv
quote
as
'"'
注:testdata
是postgresql数据库表的名称。
注意事项:
1.test目录需要赋予postgres
用户可读写的权限,否则会有如下报错信息:
error:
could
not
open
file
"d:/testdata2.csv"
forwriting:
permission
denied
2.csv文件要为utf-8格式,否则导入时可能会有报错:
error:
invalid
bytesequence
for
encoding
"utf8":
0xcdf5
3.注意windows环境下文件路径的表述方式,如:d:/test/data.csv
如将一Shapfile文件“c:\road.shp”导入到数据表“road”中,数据库为“sjzmap”。1、运行“命令提示符”。
2、切换至PostgreSQL数据库安装目录中的bin目录下。
3、执行此目录下的shp2pgsql命令:“shp2pgsql c:\road.shp road >c:\road.sql”。
4、如将此文件直接导入数据库(不推荐):“shp2pgsql -c c:\road.shp road sjzmap | psql -d sjzmap”。
5、使用pgAdmin3 选择数据库,再导入表。
注:
Drops the database table before creating a new table with the data in the Shape file.
Appends data from the Shape file into the database table. Note that to use this option to load multiple files, the files must have the same attributes and same data types.
Creates a new table and populates it from the Shape file.
Only produces the table creation SQL code, without adding any actual data. This can be used if you need to completely separate the table creation and data loading steps.
Use the PostgreSQL "dump" format for the output data. This can be combined with -a, -c and -d. It is much faster to load than the default "insert" SQL format. Use this for very large data sets.
Creates and populates the geometry tables with the specified SRID.
Keep identifiers' case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.
Coerce all integers to standard 32-bit integers, do not create 64-bit bigints, even if the DBF header signature appears to warrant it.
Create a GiST index on the geometry column.
Output WKT format, for use with older (0.x) versions of PostGIS. Note that this will introduce coordinate drifts and will drop M values from shapefiles.
Specify encoding of the input data (dbf file). When used, all attributes of the dbf are converted from the specified encoding to UTF8. The resulting SQL output will contain a command, so that the backend will be able to reconvert from UTF8 to whatever encoding the database is configured to use internally.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)