Обсуждение: copy a text type.

Поиск
Список
Период
Сортировка

copy a text type.

От
David Raznick
Дата:
Hello,

It there a way to create a new type, not a composite one, that acts in
exactly the same way as the text type except that it has a different
name.

The only way I can see to do this is by writing simple c functions
into create type but even then I am not sure that I will get the
semantics completely correct..

Is there a simple way to do this?

Thanks

David

P.S the reason for this is that I want the application to infer types
off the database and do not want to keep it as application specific.
For example I want a yaml type and want to the application to know
that what is in the field (should be) yaml.  I know that the database
will not validate it iss yaml but I am fine with that.

Re: copy a text type.

От
Tom Lane
Дата:
David Raznick <kindly@gmail.com> writes:
> It there a way to create a new type, not a composite one, that acts in
> exactly the same way as the text type except that it has a different
> name.

Perhaps a domain will do what you want?

            regards, tom lane

Re: copy a text type.

От
David Raznick
Дата:
On Sun, Jul 22, 2012 at 1:18 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> David Raznick <kindly@gmail.com> writes:
>> It there a way to create a new type, not a composite one, that acts in
>> exactly the same way as the text type except that it has a different
>> name.
>
> Perhaps a domain will do what you want?

Yes it absolutely should be.  Thanks.

The issue I have now is that psycopg2 the python library does not
extract the oid of the domain (only the oid of the original type) when
it describes the columns in returned query.  I am not sure if that is
an issue with libpq generally or this library.

>
>                         regards, tom lane

Thanks again.

David

Re: copy a text type.

От
Tom Lane
Дата:
David Raznick <kindly@gmail.com> writes:
> On Sun, Jul 22, 2012 at 1:18 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Perhaps a domain will do what you want?

> Yes it absolutely should be.  Thanks.

> The issue I have now is that psycopg2 the python library does not
> extract the oid of the domain (only the oid of the original type) when
> it describes the columns in returned query.  I am not sure if that is
> an issue with libpq generally or this library.

Oh, you're looking at PQftype?  Yeah, it will report the base type's OID
not the domain's OID; and this is a server-side behavior not something
the client can easily change.  It didn't use to be like that, but we
changed it back in (checks logs...) 2003.  IIRC, the winning argument
was that most clients wouldn't care and would be more likely to be
broken by seeing an OID they didn't recognize.

So yeah, it looks like you'd need a custom type.  Sorry about that.

            regards, tom lane