Skip site navigation (1) Skip section navigation (2)


From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Filipe Brandão <fgbrandao(at)emepc-portugal(dot)org>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: SQL If THEN
Date: 2012-07-11 13:50:32
Message-ID: (view raw, whole thread or download thread mbox)
Lists: psycopg
On 07/11/2012 05:12 AM, Filipe Brandão wrote:
> Hi all.
> I was wondering if somenone can help me.
> I needed to do a cursor.execute of a function writen in sql.
> The function is:
> cursor.execute("""BEGIN
>              IF (TG_OP = 'UPDATE') THEN
>              select NEW.test;
>              RETURN NEW;
>              END IF;
>          END;)""")
> I always get an error message saying ProgrammingError: syntax error at
> or near "IF"
> is there a way to execute this function inside a python script?

Have had coffee, am now ready for correct answer:( The above code 
snippet will only work in a trigger function. My previous suggestion to 
use DO was wrong. The only way the above is going to work is in a pgsql 
function that is then attached to a trigger.

> Thanks!

Adrian Klaver

In response to

  • SQL If THEN at 2012-07-11 12:12:08 from Filipe Brandão

psycopg by date

Next:From: P. ChristeasDate: 2012-07-20 16:45:02
Subject: binary protocol, again
Previous:From: Adrian KlaverDate: 2012-07-11 13:29:06
Subject: Re: SQL If THEN

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group