Re: types

From: Andreas Wenk <a(dot)wenk(at)netzmeister-st-pauli(dot)de>
To: Mark Hage <m(dot)c(dot)hage(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: types
Date: 2009-07-06 17:44:42
Message-ID: 4A52380A.2080809@netzmeister-st-pauli.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Mark Hage schrieb:
> Hi,
>
> I'm new to postgresql, but do have some experience in MySQL.
>
> I wanted to create a new enum type and used the command:
> CREATE TYPE gender AS ENUM ('male', 'female', 'unknown')
>
> Which returned success.
> When I create a new table I can assign the gender type to a column.
>
> But is it possible to see (and manage) the types I created?
> I use pgAdmin III.

Hi,

first of all you should also use psql - the command line interface for
PostgreSQL. There you have short cut commands. To see the types in the
actual database, type

postgres=# \dT[S+]

which gives you an output of all the types available. Alternatively you
could built a statement like SELECT * FROM pg_catalog.pg_type because
the info about types is stored here. But the short cut is making it
better and fireing this statement:

SELECT n.nspname as "Schema",
pg_catalog.format_type(t.oid, NULL) AS "Name",
pg_catalog.obj_description(t.oid, 'pg_type') as "Description"
FROM pg_catalog.pg_type t
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
WHERE (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM
pg_catalog.pg_class c WHERE c.oid = t.typrelid))
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid =
t.typelem AND el.typarray = t.oid)
AND pg_catalog.pg_type_is_visible(t.oid)
ORDER BY 1, 2;

Altering types - check this out:

postgres=# \h ALTER TYPE
Command: ALTER TYPE
Description: change the definition of a type
Syntax:
ALTER TYPE name RENAME TO new_name
ALTER TYPE name OWNER TO new_owner
ALTER TYPE name SET SCHEMA new_schema

In pgAdmin you will find the types in the objectbrowser -> your database
-> cataloge -> PostgreSQL (pg_catalog) -> pg_type. Klick on the table
and let all the entries show ...

Cheers

Andy

In response to

  • types at 2009-05-12 15:02:29 from Mark Hage

Browse pgsql-novice by date

  From Date Subject
Next Message Andreas Wenk 2009-07-06 18:12:59 Re: currval, lastval, nextvar?
Previous Message pgnovice 2009-07-06 14:20:33 Copying data from one table to another