| From: | "Guillermo E(dot) Villanueva" <guillermovil(at)gmail(dot)com> |
|---|---|
| To: | pgsql-es-ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
| Subject: | plpython |
| Date: | 2015-09-21 21:43:39 |
| Message-ID: | CANm+PCD1SMoyJjfunOFit07aQuEKVxBi-h=+nQwruq-K6MZEzA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-es-ayuda |
Buenas tardes, en una función python que devuelve una tabla, ¿*cómo hago
para agregar líneas al conjunto de resultados*?
Suponiendo que el resultado de una consulta es una lista de diccionarios,
intenté agregar un dicc a la lista, pero no funciona.
Mi intento fue así:
create or replace function fn_detalle(id integer)
returns table(orderid integer, category text, title text) as
$$
res = plpy.execute('select orderid,category,title from orderlines inner
join products using (prod_id)where orderid = '+str(id))
dict={"orderid":123,"categgory":"prueba","title":"Título"}
res.append(dict)
return res
$$
LANGUAGE plpython3u;
luego el llamado a la función así:
select orderid,category,title from fn_detalle(16)
y el error obtenido es:
ERROR: AttributeError: 'PLyResult' object has no attribute 'append'
CONTEXT: Traceback (most recent call last):
PL/Python function "fn_detalle", line 4, in <module>
res.append(dict)
función PL/Python «fn_detalle»
También probé utilizando contatenación de la siguietne manera:
res=res+dict
Pero obtengo otro error:
ERROR: TypeError: unsupported operand type(s) for +: 'PLyResult' and 'dict'
CONTEXT: Traceback (most recent call last):
PL/Python function "fn_detalle", line 4, in <module>
res=res+dict
función PL/Python «fn_detalle»
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Guillermo E. Villanueva | 2015-09-21 23:44:17 | Re: plpython |
| Previous Message | lacesco | 2015-09-18 06:04:24 | Fw: important message |