PostgreSQL triggers with Django?

1,356 views
Skip to first unread message

Daniel Quinn

unread,
Nov 16, 2009, 3:26:09 AM11/16/09
to Django users
I may be new to triggers, but I think that I've managed to figure out how to
write one properly with plpgsql and it works even... when I copy/paste the SQL
into psql client window.

However, when I put the aforementioned SQL into a .sql file and run syncdb, I
run into:

Installing custom SQL for nodes.Node model
Failed to install custom SQL for nodes.Node model: unterminated dollar-quoted
string at or near "$compile_events$
BEGIN
IF (TG_OP = 'DELETE') THEN
DELETE
FROM
nodes_feed
WHERE
node_id = OLD.node_ptr_id;"
LINE 3: ...LACE FUNCTION compile_events() RETURNS TRIGGER AS $compile_e...

Now my first option was to run this by my good and dear friend Google, who
pointed me to this two-year old mailing list message:

http://www.mail-archive.com/django...@googlegroups.com/msg20409.html

The solution there though was hacking core... so I'm hoping that there's been
some development in the past two years. Anyone care to help me out? Ideally,
I need the triggers to load after table creation, but before the fixtures are
run.

Alessandro Pasotti

unread,
Nov 16, 2009, 3:43:35 AM11/16/09
to django...@googlegroups.com
2009/11/16 Daniel Quinn <m...@danielquinn.org>
Hi,

after banging my head for a few hours, I've found a solution to this problem with a snippet:


This works for me with the standard SQL syntax (dollar quoting), just put your custom sql in 

your_app/sql/custom.sql

Hope this helps

 
--
Alessandro Pasotti
w3:   www.itopen.it

Daniel Quinn

unread,
Nov 16, 2009, 4:47:11 AM11/16/09
to django...@googlegroups.com
On Monday 16 November 2009 08:43:35 Alessandro Pasotti wrote:
> after banging my head for a few hours, I've found a solution to this
> problem with a snippet:
>
> http://www.djangosnippets.org/snippets/1338/
>
> This works for me with the standard SQL syntax (dollar quoting), just put
> your custom sql in
>
> your_app/sql/custom.sql

That totally worked! Thank you. Could someone please explain to me though
what exactly that snippet is doing? I'm still quite new to Django, and I'm
not yet used to this "drop this file in here and watch the magic go" way of
doing things.
Reply all
Reply to author
Forward
0 new messages