Re: CREATE TYPE with array - Mailing list pgsql-novice

From Wolfgang Drotschmann
Subject Re: CREATE TYPE with array
Date
Msg-id 3F1E458D.B96F7B13@fgan.de
Whole thread Raw
In response to CREATE TYPE with array  (Wolfgang Drotschmann <drotschm@fgan.de>)
Responses Re: CREATE TYPE with array  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Thank you Tom,

so far so good.  I tried the following for a database "foo" and being a
"normal" user...

Tom Lane <tgl@sss.pgh.pa.us> schrieb:
> [...]
> You could hack your way to a working datatype by creating extra pg_proc
> entries for array_in/_out:
>
> regression=# create function int4array_in(cstring) returns int4array
> regression-# as 'array_in' language internal strict immutable;
> NOTICE:  ProcedureCreate: type int4array is not yet defined
> CREATE FUNCTION
> regression=# create function int4array_out(int4array) returns cstring
> regression-# as 'array_out' language internal strict immutable;
> NOTICE:  Argument type "int4array" is only a shell
> CREATE FUNCTION
> regression=# create type int4array (
> regression(# input=int4array_in, output=int4array_out,
> regression(# internallength=variable,element=int4
> regression(# );
> CREATE TYPE
> regression=#

create function int4array_in(cstring) returns int4array
as 'array_in' language internal strict immutable;
ERROR:  internal: permission denied

Okay, switch to "root":

\c foo postgres
Password:
You are now connected to database foo as user postgres.
create function int4array_in(cstring) returns int4array
as 'array_in' language internal strict immutable;
NOTICE:  ProcedureCreate: type int4array is not yet defined
CREATE FUNCTION

create function int4array_out(int4array) returns cstring
as 'array_out' language internal strict immutable;
NOTICE:  Argument type "int4array" is only a shell
CREATE FUNCTION

Back to user "bpe" and trying to create a type

create type int4array (
input=int4array_in, output=int4array_out,
internallength=variable,element=int4
);
CREATE TYPE

Now!  Creating a table...

create table xs ( a char(5), l int4array[]);
CREATE TABLE

...and inserting a row:

insert into xs values('abcde', '{1,2,3,4}');
ERROR:  array_in: Need to specify dimension

Ups!?!

Best regards,
    Wolfgang

pgsql-novice by date:

Previous
From: Markus Bertheau
Date:
Subject: Re: Locking tables
Next
From: Jason Topaz
Date:
Subject: Struggling with set-returning functions, seeking advice