Re: Proposal for resolving casting issues

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Proposal for resolving casting issues
Date: 2002-09-17 15:36:40
Message-ID: 24357.1032277000@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> I think we must extend pg_cast's castimplicit column to a three-way value:
> * okay as implicit cast in expression (or in assignment)
> * okay as implicit cast in assignment only
> * okay only as explicit cast

> Question: what shall we call these alternatives in CREATE CAST? The SQL99
> phrase AS ASSIGNMENT looks like it should mean the second, but I think
> the spec semantics require it to mean the first. Ugh. Perhaps AS
> ASSIGNMENT ONLY for the second case?

On looking more closely, SQL99 appears to define user-defined casts as
invocable *only* in explicit cast and assignment contexts. Part 2 sez:

4.13 Data conversions

Explicit data conversions can be specified by a CAST operator.
A CAST operator defines how values of a source data type are
converted into a value of a target data type according to
the Syntax Rules and General Rules of Subclause 6.22, "<cast
specification>". Data conversions between predefined data types
and between constructed types are defined by the rules of this part
of ISO/IEC 9075. Data conversions between one or more user-defined
types are defined by a user-defined cast.

A user-defined cast identifies an SQL-invoked function, called the
cast function, that has one SQL parameter whose declared type is
the same as the source data type and a result data type that is the
target data type. A cast function may optionally be specified to
be implicitly invoked whenever values are assigned to targets of
its result data type. Such a cast function is called an implicitly
invocable cast function.

This seems to mean that we can get away with defining AS ASSIGNMENT to
mean my second category (implicit in assignment only), and then picking
some more natural term for my first category (implicit anywhere).

I favor using IMPLICIT, which would make the syntax of CREATE CAST be

CREATE CAST (sourcetype AS targettype)
WITH FUNCTION funcname (argtype)
[ AS ASSIGNMENT | IMPLICIT ]

CREATE CAST (sourcetype AS targettype)
WITHOUT FUNCTION
[ AS ASSIGNMENT | IMPLICIT ]

Or possibly it should be AS IMPLICIT?

Comments?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Lamar Owen 2002-09-17 15:43:55 Re: [HACKERS] An opportunity to prove PostgreSQL and our requirement of Case Study info
Previous Message Andrew Sullivan 2002-09-17 15:19:44 Re: [GENERAL] Still big problems with pg_dump!