From: | Jorge Godoy <jgodoy(at)gmail(dot)com> |
---|---|
To: | km(at)mrna(dot)tn(dot)nic(dot)in |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: plpython |
Date: | 2006-10-27 13:56:38 |
Message-ID: | 87iri5n9pl.fsf@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
km <km(at)mrna(dot)tn(dot)nic(dot)in> writes:
> Can someone hint on resources for using plpython for writing stored
> procedures ?
Sure. But it depends a lot on what you're willing to do. The docs have the
details. This one I did just to learn it:
CREATE FUNCTION f_v_fechamento(p_cliente_id integer, p_data date, p_pago boolean, OUT retorno record) RETURNS record
AS $$
p_cliente_id = args[0]
p_data = args[1]
p_pago = args[2]
w_total = 0
w_amostra = 0
w_final_do_mes = plpy.execute("SELECT f_v_final_do_mes(%s::date)" % p_data)
w_inicio_do_mes = plpy.execute("SELECT f_v_inicio_mes(%s::date)" % p_data)
retorno = dict()
retorno['w_inicio_do_mes'] = w_inicio_do_mes
retorno['w_final_do_mes'] = w_final_do_mes
return retorno
$$
LANGUAGE plpythonu STABLE;
It can be rewritten in a better way but was the handier example I had here
that had queries and used a bit more of PostgreSQL 8.1 :-)
> I have gone thru official docs for 8.1.5 for plpythonu but its not in
> detail/with examples.
It's just pure Python. And you use plpy for querying the database.
> When is plpython going to be considered safe ? any targeted version ?
I hope never, otherwise we loose some facilities. You understood the concept
of 'safe' and 'unsafe' in PostgreSQL's docs, right? It might not be what
you're thinking.
Be seeing you,
--
Jorge Godoy <jgodoy(at)gmail(dot)com>
From | Date | Subject | |
---|---|---|---|
Next Message | Alban Hertroys | 2006-10-27 13:59:02 | Replicating changes |
Previous Message | Alexander Staubo | 2006-10-27 13:41:17 | Re: skip duplicate key error during inserts |