agora inbox for postgres@postgres.berkeley.edu  
help / color / mirror / Atom feed
From: lmr <ren@math.ohio-state.edu>
To: postgres@postgres.Berkeley.EDU
Subject: About "Queries over variable sized arrays" too!
Date: Thu, 12 May 1994 15:54:03 -0400 (EDT)
Message-ID: <199405121954.PAA11902@math.mps.ohio-state.edu> (raw)

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.
===============================================================================




reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: postgres@postgres.berkeley.edu
  Cc: ren@math.ohio-state.edu
  Subject: Re: About "Queries over variable sized arrays" too!
  In-Reply-To: <199405121954.PAA11902@math.mps.ohio-state.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox