Search Postgresql Archives

Re: %TYPE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Aug 22, 2007, at 21:42 , Ged wrote:

I've been looking to see if postgresql allows type definitions like
the ones I'm used to from Oracle, where I can say:

CREATE TYPE npc_page_details_type AS
(
    ...
    instance_name instances.name%type,
    ...
);

and it will pick up the current type of instances.name when the user
type gets compiled.

I think you could use domains for something like this.

CREATE DOMAIN instance_name_type AS character varying;

And then use the domain in your types.

CREATE TYPE npc_page_details_type AS
(
    instance_name instance_name_type
);

CREATE table publications
(
    name instance_name_type PRIMARY KEY
);

However, in this particular case I don't see the point. There is no performance advantage to using varchar(n) over just plain varchar or the PostgreSQL type text, which although nonstandard tends to be more common among developers used to PostgreSQL. Only if you have a specific business reason that these columns absolutely must not have more than x number of characters should you use varchar(n). Otherwise you're going to be changing data types every time you want to change the limit which is not all that much fun.

Michael Glaesemann
grzm seespotcode net



---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

              http://www.postgresql.org/docs/faq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux