Here comes the true power of the information scheme. A simple request will point you in the right direction
SELECT * FROM information_schema.tables WHERE table_name='salesorders';
This can then be used in the plpg function.
CREATE OR REPLACE FUNCTION table_exists(v_table text) RETURNS boolean AS $BODY$ DECLARE v_count int; v_sql text; BEGIN v_sql = 'SELECT ' || ' count(1) ' || 'FROM ' || ' information_schema.tables ' || 'WHERE ' || E' table_name=\'' || v_table || E'\''; EXECUTE v_sql INTO v_count; RETURN v_count>0; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE COST 100;
Use function
select * from table_exists('salesordesrs');
That should be enough for you to go.
OOPS It seems that I am not reading the question correctly with the original posters. I was responsible for PostgreSQL.
Peter.
Peter Henderson
source share