[gdal-dev] Appending a column on shapefile import to postgis via
ogr2ogr
Tamas Szekeres
szekerest at gmail.com
Fri May 23 15:51:54 EDT 2008
Aaron,
The only limitation around here is that you cannot create fields with
constant values at the moment.
However you can create fields with the desired name and type based on
an existing field or a predefinied special field, like:
SELECT *, CAST(OGR_STYLE AS character(255)) AS 'MyNewField' FROM mytable
You can probably alter the values of this field later on.
Best regards,
Tamas
2008/5/23 Aaron Racicot <aaronr at z-pulley.com>:
> Probably a silly SQL type question but...
>
> So I am trying to run ogr2ogr from a php script with the intent of auto
> loading some shapefile data into a pre-existing postgis table. Since the
> shapefile I am loading could be any arbitrary shapefile (It does not have
> any unique identifier I have access to at the time of loading) I need a way
> to append an attribute to it upon loading it into postgis.
>
> Normal loading of the shapefile works fine, but when I try to append an
> attribute when loading the data via ogr2ogr things don't seem to work. (I am
> probably showing my lack of true SQL foo here...)
>
> Inside of postgres I can easily do something like the following to get a new
> column 'author' appended to the results of a query:
>
> select 'aaron' as author, * from mytable;
>
> In the database something like appending a static string in the select works
> fine, but what I would like to do is execute an sql like that inside the
> ogr2ogr call with the -sql flag. My initial attempts at this don't seem to
> work.
>
> Is something like that possible?
>
> Basically in the end I would like something like:
> ogr2ogr -update -append -f PostgreSQL PG:'host=localhost user=racicot
> dbname=xxx' -sql "select 'aaronr' as author, * from test" test.shp -nln
> user_shapes
>
> My hope was that I could add the author field to the -sql statement and have
> it populate the 'author' column in my postgis table. If something like this
> from the command line would work then I could just swap in an arbitrary
> username for 'aaronr' in the above example on the data import via my script
> and have a unique way to keep track of the data once it is imported.
>
> Any advice appreciated...
>
> Aaron
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
More information about the gdal-dev
mailing list