Re: SQL99 ARRAY support proposal - Mailing list pgsql-hackers

From Joe Conway
Subject Re: SQL99 ARRAY support proposal
Date
Msg-id 3E6C0818.1070405@joeconway.com
Whole thread Raw
In response to Re: SQL99 ARRAY support proposal  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: SQL99 ARRAY support proposal  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: SQL99 ARRAY support proposal  (Hannu Krosing <hannu@tm.ee>)
List pgsql-hackers
Tom Lane wrote:
>>I played with generalizing array functions a bit for plr and ran into 
>>some problems (which I can't specifically recall at the moment), but 
>>clearly that's the way to go. I'll start playing with your suggestions 
>>in C code, and report back for more feedback as it solidifies.
> 
> It'd be useful if you can reconstruct what problems you ran into.
> 

I've played around a bit more and refreshed my memory -- here are two 
problems:

CREATE OR REPLACE FUNCTION array_push (anyarray, any)
RETURNS anyarray
AS '$libdir/plr','array_push'
LANGUAGE 'C';
ERROR:  parser: parse error at or near "any" at character 50


It seems that "any" is not accepted as a function parameter type. From 
gram.y it appears that the cause is that "any" is a reserved keyword:

<snip>
/* * Name classification hierarchy. * * IDENT is the lexeme returned by the lexer for identifiers that match * no known
keyword. In most cases, we can accept certain keywords as
 
</snip>

<snip>
/* Type identifier --- names that can be type names. */
type_name:    IDENT    { $$ = $1; }    | unreserved_keyword { $$ = pstrdup($1); }    ;
</snip>

So for grins I did this:
regression=# select oid,typname from pg_type where typname like '%any%'; oid  | typname
------+---------- 2276 | any 2277 | anyarray
(2 rows)

regression=# update pg_type set typname = 'anyscalar' where oid = 2276;
UPDATE 1

CREATE OR REPLACE FUNCTION array_push (anyarray, anyscalar)
RETURNS anyarray
AS '$libdir/plr','array_push'
LANGUAGE 'C';

regression=# select array_push('{1,2}'::integer[],3::integer); array_push
------------ {1,2,3}
(1 row)

So far, so good. But now the second problem:
select f1[2] from   (select array_push('{1,2}'::integer[],3::integer) as f1) as t;
ERROR:  transformArraySubscripts: type anyarray is not an array

I'm just starting to dig into this one.

Joe



pgsql-hackers by date:

Previous
From: "Christopher Kings-Lynne"
Date:
Subject: Re: Cursors and backwards scans and SCROLL
Next
From: Tom Lane
Date:
Subject: Re: SQL99 ARRAY support proposal