Return-Path: owner-postman Delivery-Date: Thu, 12 May 94 15:58:04 -0700 Return-Path: owner-postman Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id MAA12158 for postgres-redist; Thu, 12 May 1994 12:54:07 -0700 Resent-From: POSTGRES mailing list Resent-Message-Id: <199405121954.MAA12158@nobozo.CS.Berkeley.EDU> X-Authentication-Warning: nobozo.CS.Berkeley.EDU: Host localhost didn't use HELO protocol Sender: owner-postman@postgres.Berkeley.EDU X-Return-Path: owner-postman Received: from math.mps.ohio-state.edu (math.mps.ohio-state.edu [128.146.110.30]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with ESMTP id MAA12148 for ; Thu, 12 May 1994 12:54:06 -0700 Received: (from ren@localhost) by math.mps.ohio-state.edu (8.6.9/8.6.6) id PAA11902 for postgres@postgres.berkeley.edu; Thu, 12 May 1994 15:54:04 -0400 From: lmr Message-Id: <199405121954.PAA11902@math.mps.ohio-state.edu> Subject: About "Queries over variable sized arrays" too! To: postgres@postgres.Berkeley.EDU Date: Thu, 12 May 1994 15:54:03 -0400 (EDT) X-Mailer: ELM [version 2.4 PL23] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Length: 1312 Resent-To: postgres-redist@postgres.Berkeley.EDU Resent-Date: Thu, 12 May 94 12:54:07 -0700 Resent-XMts: smtp I worked on the exact same problem yesterday and thought about to post yesterday but did not. I create a class by: create manager (name=char16, employee=text[])\g append manager (name="mike", employee="{"wei", "greg", "jeff"}")\g append manager (name="tom", employee="{"bill", "joe", "ren", "jeff"}")\g and want to write rule or C code to find the length of the array. The C code I used: int array_length(t) TUPLE t; { int i; char** names; bool isnull=FALSE; i=0; names=(char**)GetAttributeByName(t, "employee", &isnull); for(i=0; !isnull&& names[i]!=NULL; i++) { /* printf("%s\n", names[i]);*/ } return i; } /* define function array_length (language="c", returntype=int4) arg is (manager) as "/n/music/0/ren/postgres/array_length.o"\g */ It runs but gives incorrect result. * retrieve (x=array_length(m)) from m in manager\g Query sent to backend is "retrieve (x=array_length(m)) from m in manager" --------------- | x | --------------- | 7 | --------------- | 9 | --------------- How does postgres encode the end of a variable array? -- Liming Ren | (614) 292-8989 | Dept. of Mathematics | 231 West 18th Avenue The Ohio State University | Columbus, Ohio43210 =============================================================================== To add/remove yourself from the POSTGRES mailing list: send mail with the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU" If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and a human will deal with it. DO NOT post to the "postgres" mailing list. ===============================================================================