On Fri, Jun 1, 2012 at 5:18 PM, Ziegler Stefan <[email protected]>wrote:
> Hi
>
> We are running into problems ("permission denied") when trying to insert
> some features into a postgis database. Geotools is sending a "SELECT
> lastval()" request to the db. This returns the most recently value obtained
> with nextval [1]. Since there is some trigger from slony on the table it
> tries to get the last value of the slony sequence on which I do not have
> any permission (and which would be the wrong last value anyway since it is
> not the pkey lastvalue).
> As far as I understand the select statement in the
> PostGISDialect.getLastAutoGeneratedValue(...) method should be changed to
> something like "SELECT currval(reqclass)" where regclass is the specified
> sequence.
>
> [1]: http://www.postgresql.org/docs/8.1/static/functions-sequence.html
I'm reading the page and the two calls seem pretty similar, but indeed
calling currval(seqname) would solve your
issue. The problem is that we'd need to know the sequence name, which is
something that we'd have to fetch
making a secondary query.
To avoid a loss in efficiency I guess the sequence name should have to be
fetched when creating the
feature type and stored in the attribute user data, similarly to what we do
with srid.
I guess that could be avoided by using something like:
SELECT currval(pg_get_serial_sequence('table', 'column'));
The schema has to be fed into the table name it seems, from the docs:
pg_get_serial_sequence returns the name of the sequence associated with a
column, or NULL if no sequence is associated with the column. The first
input parameter is a table name with optional schema, and the second
parameter is a column name. Because the first parameter is potentially a
schema and table, it is not treated as a double-quoted identifier, meaning
it is lowercased by default, while the second parameter, being just a
column name, is treated as double-quoted and has its case preserved. The
function returns a value suitably formatted for passing to sequence
functions (see Section 9.15). This association can be modified or removed
with ALTER SEQUENCE OWNED BY. (The function probably should have been
called pg_get_owned_sequence; its current name reflects the fact that it's
typically used with serial or bigserial columns.)
It would be nice if you could open a ticket on jira, and attach a patch
that modifies the gt-jdbc-postgis
code to use the new calls
Cheers
Andrea
--
Ing. Andrea Aime
GeoSolutions S.A.S.
Tech lead
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 962313
mob: +39 339 8844549
http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.youtube.com/user/GeoSolutionsIT
http://www.linkedin.com/in/andreaaime
http://twitter.com/geowolf
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users