| From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
|---|---|
| To: | psycopg(at)postgresql(dot)org |
| Subject: | Re: SQL If THEN |
| Date: | 2012-07-11 13:29:06 |
| Message-ID: | 4FFD7FA2.7020409@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| 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?
IF (TG_OP = 'UPDATE') is unique to the pgsql language and is not
available to straight SQL unless:
Two options.
1) Write the above as a pgsql function in the database and call the
function.
2) Depending on the version of Postgres use DO:
http://www.postgresql.org/docs/9.1/interactive/sql-do.html
>
> Thanks!
>
>
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Adrian Klaver | 2012-07-11 13:50:32 | Re: SQL If THEN |
| Previous Message | Filipe Brandão | 2012-07-11 12:12:08 | SQL If THEN |