[GRASS-user] Piping a table to PostgreSQL

Robert Nuske rnuske at gwdg.de
Thu Oct 6 06:29:04 EDT 2011


> Hello
> 
> I am trying to run r.what to populate a table in PostgreSQL using;
> 
> echo 'select x, y from xy limit 10' | db.select -c fs=' ' | r.what
> input=layer fs=',' | ...
> 
> This bit works OK (I do get an extra blank column - see below)
> 
> 140.877,-33.9604,,4071
> 140.88,-33.9604,,3670
> 140.882,-33.9604,,3967
> 140.884,-33.9604,,4630
> 140.887,-33.9604,,4932
> 140.889,-33.9604,,5090
> 140.891,-33.9604,,4593
> 140.894,-33.9604,,4678
> 140.896,-33.9604,,4561
> 140.898,-33.9604,,4561
> 
> I would then like to pipe/copy/append this to another table in PostgreSQL.
> I have tried using db.copy and db.out.ogr but none seem to work.


I did something similar once like this:

cat filename.csv | psql -U username databasename -c "COPY tablename(column1, 
column2, column3, column4) FROM STDIN WITH CSV HEADER;"


- pure COPY didn't work because the database was on a remote machine
- instead of "cat filename" you use your data generating pipe
- if your data stream has no column names erase the keyword HEADER


hope it helps,
  robert 


More information about the grass-user mailing list