PostgreSQL Server Programming Second Edition by Second Edition

PostgreSQL Server Programming Second Edition by Second Edition

Author:Second Edition
Language: eng
Format: epub
Publisher: Packt Publishing


Functions returning a record

To return a record from a Python function, you can use:

A sequence or list of values in the same order as the fields in the return record

A dictionary with keys matching the fields in the return record

A class or type instance with attributes matching the fields in the return record

Here are samples of the three ways to return a record:

First, using an instance:

CREATE OR REPLACE FUNCTION userinfo( INOUT username name, OUT user_id oid, OUT is_superuser boolean) AS $$ class PGUser: def __init__(self,username,user_id,is_superuser): self.username = username self.user_id = user_id self.is_superuser = is_superuser u = plpy.execute("""\ select usename,usesysid,usesuper from pg_user where usename = '%s'""" % username)[0] user = PGUser(u['usename'], u['usesysid'], u['usesuper']) return user $$ LANGUAGE plpythonu;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.