Skip site navigation (1) Skip section navigation (2)

Re: Using substr with user defined types

From: darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain)
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using substr with user defined types
Date: 2000-05-18 10:54:20
Message-ID: m12sNwa-000AXnC@druid.net (view raw or flat)
Thread:
Lists: pgsql-sql
Thus spake Tom Lane
> darcy(at)druid(dot)net (D'Arcy J.M. Cain) writes:
> > I created a type (for passwords) but I can't seem to use substr.  I
> > suppose that's because it is my own type because the errors suggest that
> > there is no substr (actually it says ltrim) function for that type.
> 
> Yup --- the system has no idea how to apply any functions to a
> user-defined type except the ones you specifically define for that type.

OK, I created a function in the C file called chkpass_rout (Raw OUTput)
which does exactly what I want.  I create a function like this.

create function chkpass_rout(opaque)
    returns opaque
    as '/usr/pgsql/modules/chkpass.so'
    language 'c';

Here is what happens.

soccer=> select chkpass_rout('hello'::chkpass);
ERROR:  typeidTypeRelid: Invalid type - oid = 0

I tried various combinations of chkpass instead of opaque with no success.

> If you make a type-conversion function "text(yourtype) returns text"
> then the system will figure out that it should apply that function
> whenever you use your type as the argument of a function that needs
> text.  But without such a function, the system will not assume that
> it can do anything text-ish with the datatype.

OK, I'll go try this.  Thanks.

-- 
D'Arcy J.M. Cain <darcy(at){druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

In response to

Responses

pgsql-sql by date

Next:From: mkresseDate: 2000-05-18 10:57:29
Subject: Foreign keys and access privileges
Previous:From: christineDate: 2000-05-18 09:35:55
Subject: translate from oracle

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group