Re: check if type is valid pg type

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Dominik Moritz <domoritz(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: check if type is valid pg type
Date: 2012-10-12 22:12:38
Message-ID: CAK3UJRFoxKaC0gKQNjCgCKHN95wGDjF-tZ3fWSuSEQ0zry+Z3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Oct 12, 2012 at 6:45 AM, Dominik Moritz <domoritz(at)gmail(dot)com> wrote:
> That is exactly what I needed. Thank you very much. However, is there a way to do this without getting an exception if the type does not exist?

You could wrap the lookup in a little PL/pgSQL function, something like this:

CREATE OR REPLACE FUNCTION is_valid_type(v_type text)
RETURNS boolean
AS $$
BEGIN
PERFORM v_type::regtype;
RETURN true;
EXCEPTION WHEN undefined_object THEN
RETURN false;
END;
$$ LANGUAGE plpgsql stable;

Josh

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Adam Mackler 2012-10-15 04:39:35 Equivalence of CROSS JOIN and comma
Previous Message Tim Bowden 2012-10-12 18:31:40 Re: Make UPDATE query quicker?