Custom type with width specifier

Lists: pgsql-hackers
From: Shachar Shemesh <psql(at)shemesh(dot)biz>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Custom type with width specifier
Date: 2004-06-27 14:25:43
Message-ID: 40DED8E7.3090809@shemesh.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi list,

I'm trying to create a varchar clone (called varcharci). I have defined
new functions called "varcharciin", "varcharciout", "varcharcisend" and
"recv", using the "varcharin" etc. definitions (i.e. - builtin
functions). I defined the type. Everything works, except that when I try
to create a table it fails. This only happens when I try to give maximum
length to the type. So the command:
create table foo ( bar varcharci );
succeeds, but
create table foo (bar varcharci(12) );
fails.

What do I need to do in order to get the width specifier into my type?
I'm not even sure what function is called in order to say that the type
needs a width specifier.

Many thanks
Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting ltd.
http://www.lingnu.com/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Shachar Shemesh <psql(at)shemesh(dot)biz>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Custom type with width specifier
Date: 2004-06-27 14:53:19
Message-ID: 11995.1088347999@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Shachar Shemesh <psql(at)shemesh(dot)biz> writes:
> What do I need to do in order to get the width specifier into my type?

Rewrite the grammar. Width modifiers are only supported on types that
are hard-wired into the grammar, mainly because they look way too much
like function calls to be distinguished without special hacking.

Consider for example the implications of the fact that this works:

regression=# select numeric(17,10) '1.23';
numeric
--------------
1.2300000000
(1 row)

bison has to decide *before scanning beyond the left parenthesis*
whether "numeric" is a function name or a type name.

If you can think of a more general solution, I'm all ears, but it looks
like a hard problem that would require considerable rethinking of the
present grammar for these things.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Shachar Shemesh <psql(at)shemesh(dot)biz>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Custom type with width specifier
Date: 2004-06-27 14:56:32
Message-ID: 200406271656.32767.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Shachar Shemesh wrote:
> What do I need to do in order to get the width specifier into my
> type?

This is not possible with user-defined types.


From: Hannu Krosing <hannu(at)tm(dot)ee>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Shachar Shemesh <psql(at)shemesh(dot)biz>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Custom type with width specifier
Date: 2004-06-29 10:19:36
Message-ID: 1088504376.2680.4.camel@fuji.krosing.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On P, 2004-06-27 at 17:53, Tom Lane wrote:
> Shachar Shemesh <psql(at)shemesh(dot)biz> writes:
> > What do I need to do in order to get the width specifier into my type?
>
> Rewrite the grammar. Width modifiers are only supported on types that
> are hard-wired into the grammar, mainly because they look way too much
> like function calls to be distinguished without special hacking.
>
> Consider for example the implications of the fact that this works:
>
> regression=# select numeric(17,10) '1.23';
> numeric
> --------------
> 1.2300000000
> (1 row)
>
> bison has to decide *before scanning beyond the left parenthesis*
> whether "numeric" is a function name or a type name.
>
> If you can think of a more general solution, I'm all ears, but it looks
> like a hard problem that would require considerable rethinking of the
> present grammar for these things.

can't we make type(width) an actual function which returns another type
?

this would make it even possible to add support for things like
NUMBER(17,10) as an alias for NUMERIC(17,10) as an user-level addon.

---------------
Hannu