Trigger an SQL command after update?

27 views
Skip to first unread message

Sven Geggus

unread,
Dec 12, 2018, 5:48:36 AM12/12/18
to imp...@googlegroups.com
Hello,

I need to trigger an SQL command after a database update done by
"imposm run".

As there does not seem to be such an option in imposm.

Would it be possible to use a generic database trigger for this purpose?

Sven

--
If you can spend five minutes on the Internet and do not run Linux,
you're a genius. (Dirk Hohndel)

/me is giggls@ircnet, http://sven.gegg.us/ on the Web

Imre Samu

unread,
Dec 12, 2018, 6:56:52 AM12/12/18
to imp...@googlegroups.com
>Would it be possible to use a generic database trigger for this purpose?

imho:  You can create triggers[1] with "psql"[2]  before running imposm update;  
[1] https://www.postgresql.org/docs/current/sql-createtrigger.html
[2] https://www.postgresql.org/docs/current/app-psql.html

Best,
 Imre




--
--
_______________________________________________
Imposm mailing list
imp...@googlegroups.com
http://groups.google.com/group/imposm

---
You received this message because you are subscribed to the Google Groups "imposm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to imposm+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sven Geggus

unread,
Dec 12, 2018, 8:20:02 AM12/12/18
to imp...@googlegroups.com
Imre Samu schrieb am Wednesday, den 12. December um 12:56 Uhr:

> imho: You can create triggers[1] with "psql"[2] *before* running
Shure, but how would such a trigger look like when it should be run _after_
imposm has finished its update transaction(s)?

I intend to do hourly updates thus I would like to run a trigger function
once every hour right after imposm has finished updating its tables.

Sven

--
.. this message has been created using an outdated OS (UNIX-like) with an
outdated mail- or newsreader (text-only) :-P

Imre Samu

unread,
Dec 12, 2018, 10:33:13 AM12/12/18
to imp...@googlegroups.com
>Shure, but how would such a trigger look like when it should be run _after_
>imposm has finished its update transaction(s)?

If the "FOR EACH ROW" trigger is not perfect for you, then I don't have quick answer ... 
Sorry,

maybe others?   ( but please give more information. )

Best,
 Imre







Martin Ždila

unread,
Dec 12, 2018, 10:37:08 AM12/12/18
to imp...@googlegroups.com
On Wed, Dec 12, 2018 at 2:20 PM Sven Geggus <li...@fuchsschwanzdomain.de> wrote:
Imre Samu schrieb am Wednesday, den 12. December um 12:56 Uhr:

> imho:  You can create triggers[1] with "psql"[2]  *before* running
> imposm update;
> [1] https://www.postgresql.org/docs/current/sql-createtrigger.html
> [2] https://www.postgresql.org/docs/current/app-psql.html

Shure, but how would such a trigger look like when it should be run _after_
imposm has finished its update transaction(s)?

Dirty solution could be scanning imposm console output.
 
--
Ing. Martin Ždila 

Sven Geggus

unread,
Dec 12, 2018, 10:56:27 AM12/12/18
to imp...@googlegroups.com
Martin Ždila schrieb am Wednesday, den 12. December um 16:36 Uhr:

> Dirty solution could be scanning imposm console output.

Unfortunately my knowledge of go is next to zero, but would'nt it be a good
idea to add an optional execution of a post-update sql command into

https://github.com/omniscale/imposm3/blob/master/update/run.go

somewhere around line 148?

Sven

--
It's easier for our software to compete with Linux when there's piracy than
when there's not. (Bill Gates)

Martin Ždila

unread,
Dec 13, 2018, 2:28:34 AM12/13/18
to imp...@googlegroups.com
On Wed, Dec 12, 2018 at 4:56 PM Sven Geggus <li...@fuchsschwanzdomain.de> wrote:
Martin Ždila schrieb am Wednesday, den 12. December um 16:36 Uhr:

> Dirty solution could be scanning imposm console output.

Unfortunately my knowledge of go is next to zero, but would'nt it be a good
idea to add an optional execution of a post-update sql command into

For my proposal no go knowledge is required. Just reading from standard output (stdout) of imposm application.

--
Ing. Martin Ždila 

Sven Geggus

unread,
Dec 15, 2018, 1:33:38 PM12/15/18
to imp...@googlegroups.com
Martin Ždila schrieb am Donnerstag, den 13. Dezember um 08:28 Uhr:

> For my proposal no go knowledge is required. Just reading from standard
> output (stdout) of imposm application.

I know, but I consider this a somewhat dirty hack.

I made a patch despite the fact that my Go language knowledge is close to
zero:

https://github.com/giggls/imposm3/tree/PostReplicateScript

Please comment.

Regards

Sven

--
Das allgemeine Persönlichkeitsrecht (Art. 2 Abs.1 i.V.m. Art.1 Abs. 1GG)
umfasst das Grundrecht auf Gewährleistung der Vertraulichkeit und Integrität
informationstechnischer Systeme. (BVerfG, 1BvR 370/07)

Imre Samu

unread,
Dec 17, 2018, 12:23:45 PM12/17/18
to imp...@googlegroups.com
>I made a patch despite the fact that my Go language knowledge is close to zero:
>https://github.com/giggls/imposm3/tree/PostReplicateScript
>Please comment.

( not tested ) 
for me : it is looks ok  ; it is useful  ..
Please create a pull request! 

Imre





Oliver Tonnhofer

unread,
Dec 18, 2018, 2:44:52 AM12/18/18
to imp...@googlegroups.com
Hi Sven,

thanks for your patch.

I think an option to `imposm run` to exit after one import is a nicer solution. This way you can integrate Imposm into your script, instead of adding a "process management" to Imposm. You can do this already with the undocumented IMPOSM3_SINGLE_DIFF environment (IMPOSM3_SINGLE_DIFF=1 imposm run).


Another solution would be to make Imposm to call arbitrary SQL commands after an import/update. This makes it more complex, but the commands can run in the same SQL transaction, giving you a clean all-or-nothing.


Regards,
Oliver

--
Oliver Tonnhofer | Omniscale GmbH & Co KG | https://omniscale.com
OpenStreetMap WMS and tile services | https://maps.omniscale.com

Sven Geggus

unread,
Dec 18, 2018, 4:47:14 AM12/18/18
to Oliver Tonnhofer, imp...@googlegroups.com
Oliver Tonnhofer schrieb am Tuesday, den 18. December um 08:44 Uhr:

> I think an option to `imposm run` to exit after one import is a nicer
> solution. This way you can integrate Imposm into your script, instead of
> adding a "process management" to Imposm. You can do this already with the
> undocumented IMPOSM3_SINGLE_DIFF environment (IMPOSM3_SINGLE_DIFF=1 imposm
> run).

Looks reasonable.

Instead of just calling "imposm run -config config.json" I would
instead build a wrapperscript with an endless loop calling imposm and some
post-update stuff in an endless loop.

> Another solution would be to make Imposm to call arbitrary SQL commands
> after an import/update. This makes it more complex, but the commands can
> run in the same SQL transaction, giving you a clean all-or-nothing.

Frankly, this is what I tried to implement first, but as a complete Go noob
I did not understand how to execute raw SQL from this database abstraction
layer. Likely also only a few lines of code in process.go, right?

Sven

--
# Turn on/off security. Off is currently the default
(found in MongoDB default configfile)
Reply all
Reply to author
Forward
0 new messages