X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C1F2D14B2800 for ; Wed, 11 Aug 2004 04:48:40 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82555-08 for ; Wed, 11 Aug 2004 07:48:38 +0000 (GMT) Received: from bubba.e-complex.com (unknown [69.44.60.111]) by svr1.postgresql.org (Postfix) with ESMTP id 4B76414B2804 for ; Wed, 11 Aug 2004 04:48:36 -0300 (ADT) Received: from [192.168.2.2] (d137-186-198-143.abhsia.telus.net [137.186.198.143]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by bubba.e-complex.com (Postfix) with ESMTP id 43D2F29C147 for ; Wed, 11 Aug 2004 02:42:46 -0600 (MDT) Subject: Type implemented in plpythonu crashes backend From: pgsql@groks.org To: pgsql-interfaces@postgresql.org Content-Type: text/plain Message-Id: <1092210515.2350.100.camel@january.e-complex.ca> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Wed, 11 Aug 2004 01:48:35 -0600 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.4 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME, RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200408/18 X-Sequence-Number: 5066 I'd like to implement new postgres types in a language other than C for prototyping speed. plpgsql won't let me create a function which takes a cstring, and neither will pltcl. Happily, plpythonu will, and it seems to work fine. However, the code below causes the backend to crash... I'm guessing that plpython is trying to format the return value using the appropriate registered function, which just happens to be itself. My goal is to prototype new types, operators and gist indexes without getting bogged down in with the guts of posgresql in C, so if it's unreasonable to expect the below code to work, do you have any other suggestions? Thanks. create or replace function pycomplex_in(cstring) returns opaque as ' import struct import re p = re.compile(" *\\( *([0-9]+(\\.[0-9]+)?) *, *([0-9]+(\\.[0-9]+)?)*\\)*") m = p.match(args[0]) if m: (x, y) = m.group(1, 3) else: (x, y) = (0, 0) #plpy.error("incorrect format for pycomplex: %s" % args[0]) return struct.pack("dd", float(x), float(y)) ' language plpythonu immutable strict; create or replace function pycomplex_out(opaque) returns cstring as ' import struct (x, y) = struct.unpack("dd", args[0]) return "(%f, %f)", (x, y) ' language plpythonu immutable strict; create type pycomplex ( internallength = 16, input = pycomplex_in, output = pycomplex_out, alignment = double ); select pycomplex_out(pycomplex_in('(1,2)'));