Re: check if type is valid pg type - Mailing list pgsql-novice

From Josh Kupershmidt
Subject Re: check if type is valid pg type
Date
Msg-id CAK3UJRFoxKaC0gKQNjCgCKHN95wGDjF-tZ3fWSuSEQ0zry+Z3w@mail.gmail.com
Whole thread Raw
In response to Re: check if type is valid pg type  (Dominik Moritz <domoritz@gmail.com>)
List pgsql-novice
On Fri, Oct 12, 2012 at 6:45 AM, Dominik Moritz <domoritz@gmail.com> wrote:
> That is exactly what I needed. Thank you very much. However, is there a way to do this without getting an exception
ifthe 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


pgsql-novice by date:

Previous
From: Tim Bowden
Date:
Subject: Re: Make UPDATE query quicker?
Next
From: Adam Mackler
Date:
Subject: Equivalence of CROSS JOIN and comma