0

I want to count the number of tables which is contained by a view.

In SQL Server I do it like this:

Declare v_tables int

SELECT  v_Tables = Count(*)
      FROM INFORMATION_SCHEMA.VIEW_TABLE_USAGE
      WHERE View_Name = View1;

How about PostgreSQL 9.3 ?

2
  • Yes, it's possible, because Postgresql has INFORMATION_SCHEMA. Are you wanting this in a stored procedure? Commented Jan 27, 2015 at 12:38
  • @mlinth, Yeah! Exactly. Commented Jan 27, 2015 at 12:40

1 Answer 1

1
CREATE OR REPLACE FUNCTION count_tables(p_viewname text) RETURNS integer AS $BODY$
  SELECT count(*) FROM information_schema.view_table_usage
  WHERE view_name = p_viewname;
$BODY$ LANGUAGE sql STABLE STRICT;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.