<?xml version="1.0" encoding="UTF-8"?>
<!--
    Information schema for Libgda's dictionary DB.
    This is the base schema and can be extended by applications by adding new
    DBMS objects, but: the '_' prefix is reserved for Libgda's internals...

    NOTE: when modified, please:
    * run tools/information-schema-doc and move the generated file to doc/C/
    * run tools/information-schema-types and move the generated file to libgda/providers-support/
    * increment the CURRENT_SCHEMA_VERSION define in libgda/gda-meta-store.c and implement the corresponding
      schema migration in that file
-->


<schema>
  <!-- provider specific information 
       use <replace> to replace something with something else (context can only be "/FIELDS_A/@COLUMN_TYPE" at the moment)
       use <ignore> to ignore some parts (context can only be "/FKEY_S" or "/FIELDS_A/@COLUMN_PKEY" at the moment)
    -->
  <specifics>
    <provider name="PostgreSQL">
      <replace context="/FIELDS_A/@COLUMN_TYPE" expr="string" replace_with="varchar"/>
      <replace context="/FIELDS_A/@COLUMN_TYPE" expr="gint" replace_with="int"/>
    </provider>
    <provider name="MySQL">
      <replace context="/FIELDS_A/@COLUMN_TYPE" expr="string" replace_with="text"/>
      <replace context="/FIELDS_A/@COLUMN_TYPE" expr="gint" replace_with="int"/>
      <ignore context="/FKEY_S"/>
      <ignore context="/FIELDS_A/@COLUMN_PKEY"/>
    </provider>
    <provider name="SQLite">
      <replace context="/FIELDS_A/@COLUMN_TYPE" expr="gint" replace_with="int"/>
    </provider>
  </specifics>

  <!-- schema description -->
  <table name="_attributes" descr="Table to store (key,value) pairs (keys starting with '_' are reserved)">
    <column name="att_name" pkey="TRUE"/>
    <column name="att_value"/>
  </table>

  <table name="_information_schema_catalog_name" descr="Name of the current database (current catalog), has only one row">
    <column name="catalog_name" pkey="TRUE"/>
  </table>

  <table name="_schemata" descr="List of schemas">
    <column name="catalog_name" pkey="TRUE" descr="Name of the catalog that contains the schema"/>
    <column name="schema_name" pkey="TRUE" ident="TRUE"/>
    <column name="schema_owner" nullok="TRUE" descr="Name of the schema"/>
    <column name="schema_internal" type="boolean"  descr="Tells if the schema is specific to the database implementation (and usually can't be modified)"/>
    <fkey ref_table="_information_schema_catalog_name">
      <part column="catalog_name" ref_column="catalog_name"/>
    </fkey>
  </table>

  <table name="_builtin_data_types" descr="List of built-in data types such as varchar, int, ...">
    <column name="short_type_name" descr="Short name of the data type"/>
    <column name="full_type_name" pkey="TRUE" descr="Full name of the data type"/>
    <column name="gtype" nullok="TRUE"/>
    <column name="comments" nullok="TRUE"/>
    <column name="synonyms" nullok="TRUE"/>
    <column name="internal" type="boolean" descr="Tells if the data type is reserved for the database implementation and should not be used in applications"/>
    <unique>
      <column name="short_type_name"/>
    </unique>
  </table>

  <table name="_udt" descr="User defined data types">
    <column name="udt_catalog" pkey="TRUE" descr="Name of the catalog that contains the data type"/>
    <column name="udt_schema" pkey="TRUE" descr="Name of the schema that contains the data type" ident="TRUE"/>
    <column name="udt_name" pkey="TRUE" descr="Name of the data type" ident="TRUE"/>
    <column name="udt_gtype" nullok="TRUE" descr="GType associated to the data type"/>
    <column name="udt_comments" nullok="TRUE"/>
    <column name="udt_short_name" ident="TRUE"/>
    <column name="udt_full_name" ident="TRUE"/>
    <column name="udt_internal" type="boolean" descr="Tells if the data type is reserved for the database implementation and should not be used in applications"/>
    <column name="udt_owner" nullok="TRUE"/>
    <fkey ref_table="_schemata">
      <part column="udt_catalog" ref_column="catalog_name"/>
      <part column="udt_schema" ref_column="schema_name"/>
    </fkey>
    <unique>
      <column name="udt_full_name"/>
    </unique>
  </table>

  <table name="_udt_columns" descr="List of components for a user defined data type for composed data types (such as a complex number data type which has real and imaginary parts)">
    <column name="udt_catalog" pkey="TRUE" descr="Name of the catalog that contains the user defined data type for which the column is"/>
    <column name="udt_schema" pkey="TRUE" descr="Name of the schema that contains the user defined data type for which the column is" ident="TRUE"/>
    <column name="udt_name" pkey="TRUE" descr="Name of the user defined data type for which the column is" ident="TRUE"/>
    <column name="udt_column" pkey="TRUE" descr="Name of the column (part)" ident="TRUE"/>
    <column name="ordinal_position" type="gint" descr="Column position, starts at 1"/>
    <column name="data_type" nullok="TRUE" descr="Data type of the column (if the column is an array, then 'array_spec' is set, and this may be NULL)"/>
    <column name="array_spec" nullok="TRUE" descr="Array description if the column is an array"/>
    <column name="character_maximum_length" type="gint" nullok="TRUE"/>
    <column name="character_octet_length" type="gint" nullok="TRUE"/>
    <column name="numeric_precision" type="gint" nullok="TRUE"/>
    <column name="numeric_scale" type="gint" nullok="TRUE"/>
    <column name="datetime_precision" type="gint" nullok="TRUE"/>
    <column name="character_set_catalog" nullok="TRUE"/>
    <column name="character_set_schema" nullok="TRUE" ident="TRUE"/>
    <column name="character_set_name" nullok="TRUE" ident="TRUE"/>
    <column name="collation_catalog" nullok="TRUE"/>
    <column name="collation_schema" nullok="TRUE" ident="TRUE"/>
    <column name="collation_name" nullok="TRUE" ident="TRUE"/>
    <fkey ref_table="_udt">
      <part column="udt_catalog"/>
      <part column="udt_schema"/>
      <part column="udt_name"/>
    </fkey>
    <fkey ref_table="_element_types">
      <part column="array_spec" ref_column="specific_name"/>
    </fkey>
    <!--
    <fkey ref_table="_all_types">
      <part column="data_type" ref_column="full_type_name"/>
    </fkey>
    -->
  </table>

  <table name="_enums" descr="List of possible enumeration labels for enumerations">
    <column name="udt_catalog" pkey="TRUE" descr="Name of the catalog that contains the ENUM user defined data type"/>
    <column name="udt_schema" pkey="TRUE" descr="Name of the schema that contains the ENUM user defined data type" ident="TRUE"/>
    <column name="udt_name" pkey="TRUE" descr="Name of the ENUM user defined data type" ident="TRUE"/>
    <column name="label" pkey="TRUE"/>
    <column name="ordinal_position" type="gint" descr="Position, starts at 1"/>
    <fkey ref_table="_udt">
      <part column="udt_catalog"/>
      <part column="udt_schema"/>
      <part column="udt_name"/>
    </fkey>
  </table>

  <table name="_element_types" descr="Array specific attributes for array data types">
    <column name="specific_name" pkey="TRUE" descr="No specific meaning, used as a primary key, and for joining"/>
    <column name="object_catalog" descr="Name of the catalog that contains the object that uses the array being described"/>
    <column name="object_schema" descr="Name of the schema that contains the object that uses the array being described" ident="TRUE"/>
    <column name="object_name" descr="Name of the object that uses the array being described" ident="TRUE"/>
    <column name="object_type" descr="The type of the object that uses the array being described TABLE_COL, DOMAIN, UDT_COL, ROUTINE_COL, ROUTINE_PAR"/>
    <column name="data_type" nullok="TRUE" descr="Base data type of the array (if the base data type is an array, then 'array_spec' is set, and this may be NULL)"/>
    <column name="array_spec" nullok="TRUE" descr="Array description if the base data type is an array"/>
    <column name="min_cardinality" type="gint" nullok="TRUE"/>
    <column name="max_cardinality" type="gint" nullok="TRUE"/>
  </table>

  <table name="_domains" descr="List of domains">
    <column name="domain_catalog" pkey="TRUE" descr="Name of catalog that contains the domain"/>
    <column name="domain_schema" pkey="TRUE" descr="Name of schema that contains the domain" ident="TRUE"/>
    <column name="domain_name" pkey="TRUE" descr="Name of the domain" ident="TRUE"/>
    <column name="data_type" nullok="TRUE" descr="Data type of the domain (if the domain is an array, then 'array_spec' is set, and this may be NULL)"/>
    <column name="array_spec" nullok="TRUE" descr="Array description if the domain is an array"/>
    <column name="domain_gtype"/>
    <column name="character_maximum_length" type="gint" nullok="TRUE"/>
    <column name="character_octet_length" type="gint" nullok="TRUE"/>
    <column name="collation_catalog" nullok="TRUE" descr="Name of catalog that contains the associated collation"/>
    <column name="collation_schema" nullok="TRUE" descr="Name of schema that contains the associated collation" ident="TRUE"/>
    <column name="collation_name" nullok="TRUE" descr="Name of the associated collation" ident="TRUE"/>
    <column name="character_set_catalog" nullok="TRUE" descr="Name of catalog that contains the associated character set"/>
    <column name="character_set_schema" nullok="TRUE" descr="Name of schema that contains the associated character set" ident="TRUE"/>
    <column name="character_set_name" nullok="TRUE" descr="Name of the associated character set" ident="TRUE"/>
    <column name="numeric_precision" type="gint" nullok="TRUE"/>
    <column name="numeric_scale" type="gint" nullok="TRUE"/>
    <column name="domain_default" nullok="TRUE"/>
    <column name="domain_comments" nullok="TRUE"/>
    <column name="domain_short_name" ident="TRUE"/>
    <column name="domain_full_name" ident="TRUE"/>
    <column name="domain_internal" type="boolean"/>
    <column name="domain_owner" nullok="TRUE"/>
    <fkey ref_table="_schemata">
      <part column="domain_catalog" ref_column="catalog_name"/>
      <part column="domain_schema" ref_column="schema_name"/>
    </fkey>
    <fkey ref_table="_element_types">
      <part column="array_spec" ref_column="specific_name"/>
    </fkey>
    <!--
    <fkey ref_table="_all_types">
      <part column="data_type" ref_column="full_type_name"/>
    </fkey>
    -->
    <unique>
      <column name="domain_full_name"/>
    </unique>
  </table>

  <table name="_tables" descr="List of tables (tables, views or other objects which can contain data)">
    <column name="table_catalog" pkey="TRUE" descr="Name of catalog that contains the table"/>
    <column name="table_schema" pkey="TRUE" descr="Name of schema that contains the table" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" descr="Name of the table" ident="TRUE"/>
    <column name="table_type" descr="Type of table: BASE TABLE, VIEW, LOCAL TEMPORARY, SYSTEM TABLE, GLOBAL TEMPORARY, ALIAS or SYNONYM"/>
    <column name="is_insertable_into" type="boolean" nullok="TRUE" descr="Tells if the table's contents can be modified"/>
    <column name="table_comments" nullok="TRUE"/>
    <column name="table_short_name" ident="TRUE"/>
    <column name="table_full_name" ident="TRUE"/>
    <column name="table_owner" nullok="TRUE"/>
    <fkey ref_table="_schemata">
      <part column="table_catalog" ref_column="catalog_name"/>
      <part column="table_schema" ref_column="schema_name"/>
    </fkey>
    <unique>
      <column name="domain_full_name"/>
    </unique>
  </table>

  <table name="_views" descr="List of views and their specific information">
    <column name="table_catalog" pkey="TRUE" descr="Name of catalog that contains the view"/>
    <column name="table_schema" pkey="TRUE" descr="Name of schema that contains the view" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" descr="Name of the view" ident="TRUE"/>
    <column name="view_definition" nullok="TRUE" descr="View as SQL"/>
    <column name="check_option" nullok="TRUE" descr="CASCADE if the statement used to create the view included the WITH CHECK OPTION; otherwise, NONE"/>
    <column name="is_updatable" type="boolean" nullok="TRUE" descr="Tells if the view's contents can be modified"/>
    <fkey ref_table="_tables">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
    </fkey>
  </table>

  <table name="_collations" descr="List of collations methods">
    <column name="collation_catalog" pkey="TRUE"/>
    <column name="collation_schema" pkey="TRUE" ident="TRUE"/>
    <column name="collation_name" pkey="TRUE" ident="TRUE"/>
    <column name="collation_comments" nullok="TRUE"/>
    <column name="collation_short_name" ident="TRUE"/>
    <column name="collation_full_name" ident="TRUE"/>
    <fkey ref_table="_schemata">
      <part column="collation_catalog" ref_column="catalog_name"/>
      <part column="collation_schema" ref_column="schema_name"/>
    </fkey>
    <unique>
      <column name="collation_full_name"/>
    </unique>
  </table>

  <table name="_character_sets" descr="List of character sets">
    <column name="character_set_catalog" pkey="TRUE"/>
    <column name="character_set_schema" pkey="TRUE" ident="TRUE"/>
    <column name="character_set_name" pkey="TRUE" ident="TRUE"/>
    <column name="default_collate_catalog" nullok="TRUE"/>
    <column name="default_collate_schema" nullok="TRUE" ident="TRUE"/>
    <column name="default_collate_name" nullok="TRUE" ident="TRUE"/>
    <column name="character_set_comments" nullok="TRUE"/>
    <column name="character_set_short_name" ident="TRUE"/>
    <column name="character_set_full_name" ident="TRUE"/>
    <fkey ref_table="_schemata">
      <part column="character_set_catalog" ref_column="catalog_name"/>
      <part column="character_set_schema" ref_column="schema_name"/>
    </fkey>
    <fkey ref_table="_collations">
      <part column="default_collate_catalog" ref_column="collation_catalog"/>
      <part column="default_collate_schema" ref_column="collation_schema"/>
      <part column="default_collate_name" ref_column="collation_name"/>
    </fkey>
    <unique>
      <column name="character_set_full_name"/>
    </unique>
  </table>

  <table name="_routines" descr="List of functions and stored procedures (note: the primary jey for that table is composed of (specific_catalog, specific_schema, specific_name))">
    <column name="specific_catalog" pkey="TRUE" descr="Specific name of catalog that contains the routine"/>
    <column name="specific_schema" pkey="TRUE" descr="Specific name of schema that contains the routine" ident="TRUE"/>
    <column name="specific_name" pkey="TRUE" descr="Specific name of the routine (may be mangled for polymorphic routines)"/>
    <column name="routine_catalog" nullok="TRUE" descr="Name of catalog that contains the routine (may be NULL)"/>
    <column name="routine_schema" nullok="TRUE" descr="Name of schema that contains the routine (may be NULL)" ident="TRUE"/>
    <column name="routine_name" descr="Name of the routine" ident="TRUE"/>
    <column name="routine_type" nullok="TRUE" descr="FUNCTION, PROCEDURE, AGGREGATE"/>
    <column name="return_type" nullok="TRUE" descr="Data type returned by the routine (may be NULL if routine does not return any value)"/>
    <column name="returns_set" type="boolean" descr="True if routine returns a set (i.e., multiple values of the specified data type or if data type may vary)"/>
    <column name="nb_args" type="gint" descr="Number of arguments (-1 for variable number of arguments)"/>
    <column name="routine_body" nullok="TRUE" descr="If the routine is an SQL function, then SQL, else EXTERNAL"/>
    <column name="routine_definition" nullok="TRUE" descr="The source text of the routine"/>
    <column name="external_name" nullok="TRUE" descr="If the routine is an external function, then the external name (link symbol) of the function"/>
    <column name="external_language" nullok="TRUE" descr="The language the routine is written in"/>
    <column name="parameter_style" nullok="TRUE" descr="Parameter style (GENERAL, JAVA, SQL, GENERAL WITH NULLS)"/>
    <column name="is_deterministic" type="boolean" nullok="TRUE" descr="Tells if the routine returns the same results given the same arguments forever"/>
    <column name="sql_data_access" nullok="TRUE" descr="Whether the routine contains SQL and whether it reads or modifies data (NONE, CONTAINS, READS, MODIFIES)"/>
    <column name="is_null_call" type="boolean" nullok="TRUE" descr="Tells if the routine will be called if any one of its arguments is NULL"/>
    <column name="routine_comments" nullok="TRUE"/>
    <column name="routine_short_name" ident="TRUE"/>
    <column name="routine_full_name" ident="TRUE"/>
    <column name="routine_owner" nullok="TRUE"/>
    <fkey ref_table="_schemata">
      <part column="specific_catalog" ref_column="catalog_name"/>
      <part column="specific_schema" ref_column="schema_name"/>
    </fkey>
    <unique>
      <column name="routine_full_name"/>
    </unique>
  </table>

  <table name="_triggers" descr="List of triggers">
    <column name="trigger_catalog" pkey="TRUE"/>
    <column name="trigger_schema" pkey="TRUE" ident="TRUE"/>
    <column name="trigger_name" pkey="TRUE" ident="TRUE"/>
    <column name="event_manipulation" pkey="TRUE" descr="Event that fires the trigger (INSERT, UPDATE, or DELETE)"/>
    <column name="event_object_catalog" pkey="TRUE" descr="Name of the database that contains the table that the trigger is defined on"/>
    <column name="event_object_schema" pkey="TRUE" descr="Name of the schema that contains the table that the trigger is defined on" ident="TRUE"/>
    <column name="event_object_table" pkey="TRUE" descr="Name of the table that the trigger is defined on" ident="TRUE"/>

    <column name="action_statement" nullok="TRUE" descr="Statement that is executed by the trigger"/>
    <column name="action_orientation" descr="Identifies whether the trigger fires once for each processed row or once for each statement (ROW or STATEMENT)"/>
    <column name="condition_timing" descr="Time at which the trigger fires (BEFORE or AFTER)"/>
    <column name="trigger_comments" nullok="TRUE"/>
    <column name="trigger_short_name" ident="TRUE"/>
    <column name="trigger_full_name" ident="TRUE"/>
    <fkey ref_table="_schemata">
      <part column="trigger_catalog" ref_column="catalog_name"/>
      <part column="trigger_schema" ref_column="schema_name"/>
    </fkey>
    <fkey ref_table="_tables">
      <part column="event_object_catalog" ref_column="table_catalog"/>
      <part column="event_object_schema" ref_column="table_schema"/>
      <part column="event_object_table" ref_column="table_name"/>
    </fkey>
    <unique>
      <column name="trigger_full_name"/>
    </unique>
  </table>

  <table name="_columns" descr="List of columns composing tables">
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="column_name" pkey="TRUE" ident="TRUE"/>
    <column name="ordinal_position" type="gint" descr="Column position, starts at 1"/>
    <column name="column_default" nullok="TRUE"/>
    <column name="is_nullable" type="boolean"/>
    <column name="data_type" nullok="TRUE" descr="Data type of the column (if the column is an array, then 'array_spec' is set, and this may be NULL)"/>
    <column name="array_spec" nullok="TRUE" descr="Array description if the column is an array"/>
    <column name="gtype"/>
    <column name="character_maximum_length" type="gint" nullok="TRUE"/>
    <column name="character_octet_length" type="gint" nullok="TRUE"/>
    <column name="numeric_precision" type="gint" nullok="TRUE" descr="If data_type identifies a numeric type, this column contains the precision of the type for this column (the number of significant digits)"/>
    <column name="numeric_scale" type="gint" nullok="TRUE" descr="If data_type identifies an exact numeric type, this column contains the scale of the type for this column (the number of significant digits to the right of the decimal point)"/>
    <column name="datetime_precision" type="gint" nullok="TRUE"/>
    <column name="character_set_catalog" nullok="TRUE"/>
    <column name="character_set_schema" nullok="TRUE" ident="TRUE"/>
    <column name="character_set_name" nullok="TRUE" ident="TRUE"/>
    <column name="collation_catalog" nullok="TRUE"/>
    <column name="collation_schema" nullok="TRUE" ident="TRUE"/>
    <column name="collation_name" nullok="TRUE" ident="TRUE"/>
    <column name="extra" nullok="TRUE" descr="CSV string with: AUTO_INCREMENT"/> <!-- set the gda-enums.h file -->
    <column name="is_updatable" type="boolean" nullok="TRUE"/>
    <column name="column_comments" nullok="TRUE"/>
    <fkey ref_table="_tables">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
    </fkey>
    <fkey ref_table="_character_sets">
      <part column="character_set_catalog"/>
      <part column="character_set_schema"/>
      <part column="character_set_name"/>
    </fkey>
    <fkey ref_table="_collations">
      <part column="collation_catalog"/>
      <part column="collation_schema"/>
      <part column="collation_name"/>
    </fkey>
    <fkey ref_table="_element_types">
      <part column="array_spec" ref_column="specific_name"/>
    </fkey>
    <!--
    <fkey ref_table="_all_types">
      <part column="data_type" ref_column="full_type_name"/>
    </fkey>
    -->
  </table>

  <table name="_table_constraints" descr="List of constraints applied to tables (Check, primary or foreign key, or unique constraints)">
    <column name="constraint_catalog" nullok="TRUE" descr="Name of the catalog that contains the constraint"/>
    <column name="constraint_schema" nullok="TRUE" descr="Name of the schema that contains the constraint" ident="TRUE"/>

    <column name="constraint_name" pkey="TRUE" ident="TRUE"/>
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="constraint_type" descr="CHECK, FOREIGN KEY, PRIMARY KEY or UNIQUE"/>
    <column name="check_clause" nullok="TRUE" descr="The check expression if the constraint is a check constraint, NULL otherwise"/>
    <column name="is_deferrable" type="boolean" nullok="TRUE"/>
    <column name="initially_deferred" type="boolean" nullok="TRUE"/>
    <fkey ref_table="_tables">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
    </fkey>
  </table>

  <table name="_referential_constraints" descr="List of foreign key constraints, along with some specific attributes">
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="constraint_name" pkey="TRUE" ident="TRUE"/>

    <column name="ref_table_catalog"/>
    <column name="ref_table_schema" ident="TRUE"/>
    <column name="ref_table_name" ident="TRUE"/>
    <column name="ref_constraint_name" ident="TRUE"/>

    <column name="match_option" nullok="TRUE" descr="FULL, PARTIAL or NONE"/>
    <column name="update_rule" nullok="TRUE" descr="CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION or NONE"/>
    <column name="delete_rule" nullok="TRUE" descr="CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION or NONE"/>
    <fkey ref_table="_table_constraints">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
      <part column="constraint_name"/>
    </fkey>
    <fkey ref_table="_table_constraints">
      <part column="ref_table_catalog" ref_column="table_catalog"/>
      <part column="ref_table_schema" ref_column="table_schema"/>
      <part column="ref_table_name" ref_column="table_name"/>
      <part column="ref_constraint_name" ref_column="constraint_name"/>
    </fkey>
  </table>

  <table name="_key_column_usage" descr="List of primary key constraints and the name of the tables' columns involved">
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="constraint_name" pkey="TRUE" ident="TRUE"/>
    <column name="column_name" pkey="TRUE" ident="TRUE"/>
    <column name="ordinal_position" type="gint" pkey="TRUE" descr="Ordinal position of the column within the constraint key (count starts at 1)"/>
    <fkey ref_table="_table_constraints">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
      <part column="constraint_name"/>
    </fkey>
    <fkey ref_table="_columns">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
      <part column="column_name"/>
    </fkey>
  </table>

  <table name="_check_column_usage" descr="List of check constraints and the name of the tables' columns involved">
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="constraint_name" pkey="TRUE" ident="TRUE"/>
    <column name="column_name" pkey="TRUE" ident="TRUE"/>
    <fkey ref_table="_table_constraints">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
      <part column="constraint_name"/>
    </fkey>
    <fkey ref_table="_columns">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
      <part column="column_name"/>
    </fkey>
  </table>

  <table name="_view_column_usage" descr="List of the tables' columns involved in a view">
    <column name="view_catalog" pkey="TRUE"/>
    <column name="view_schema" pkey="TRUE" ident="TRUE"/>
    <column name="view_name" pkey="TRUE" ident="TRUE"/>
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="column_name" pkey="TRUE" ident="TRUE"/>
    <fkey ref_table="_views">
      <part column="view_catalog" ref_column="table_catalog"/>
      <part column="view_schema" ref_column="table_schema"/>
      <part column="view_name" ref_column="table_name"/>
    </fkey>
    <fkey ref_table="_columns">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
      <part column="column_name"/>
    </fkey>
  </table>

  <table name="_domain_constraints" descr="List of constraints applicable to domains">
    <column name="constraint_catalog" nullok="TRUE" descr="Name of the catalog that contains the constraint"/>
    <column name="constraint_schema" nullok="TRUE" descr="Name of the schema that contains the constraint" ident="TRUE"/>

    <column name="constraint_name" pkey="TRUE" ident="TRUE"/>
    <column name="domain_catalog" pkey="TRUE"/>
    <column name="domain_schema" pkey="TRUE" ident="TRUE"/>
    <column name="domain_name" pkey="TRUE" ident="TRUE"/>

    <column name="check_clause" nullok="TRUE"/>
    <column name="is_deferrable" type="boolean" nullok="TRUE"/>
    <column name="initially_deferred" type="boolean" nullok="TRUE"/>
    <fkey ref_table="_domains">
      <part column="domain_catalog"/>
      <part column="domain_schema"/>
      <part column="domain_name"/>
    </fkey>
    <fkey ref_table="_schemata">
      <part column="constraint_catalog" ref_column="catalog_name"/>
      <part column="constraint_schema"  ref_column="schema_name"/>
    </fkey>
  </table>

  <table name="_parameters" descr="List of routines' (functions and stored procedures) parameters (may not contain data for some routines which accept any type of parameter)">
    <column name="specific_catalog" pkey="TRUE"/>
    <column name="specific_schema" pkey="TRUE" ident="TRUE"/>
    <column name="specific_name" pkey="TRUE"/>
    <column name="ordinal_position" type="gint" pkey="TRUE"/>
    <column name="parameter_mode"/>
    <column name="parameter_name" nullok="TRUE" ident="TRUE"/>
    <column name="data_type" nullok="TRUE" descr="Data type of the parameter (if the parameter is an array, then 'array_spec' is set, and this may be NULL; can also be NULL if any type of parameter is accepted)"/>
    <column name="array_spec" nullok="TRUE" descr="Array description if the parameter is an array"/>
    <fkey ref_table="_routines">
      <part column="specific_catalog"/>
      <part column="specific_schema"/>
      <part column="specific_name"/>
    </fkey>
    <fkey ref_table="_element_types">
      <part column="array_spec" ref_column="specific_name"/>
    </fkey>
    <!--
    <fkey ref_table="_all_types">
      <part column="data_type" ref_column="full_type_name"/>
    </fkey>
    -->
  </table>

  <table name="_routine_columns" descr="List of routines' (functions and stored procedures) returned values' parts (columns) for routines returning composed values">
    <column name="specific_catalog" pkey="TRUE"/>
    <column name="specific_schema" pkey="TRUE" ident="TRUE"/>
    <column name="specific_name" pkey="TRUE"/>
    <column name="column_name" pkey="TRUE" ident="TRUE"/>
    <column name="ordinal_position" type="gint" nullok="TRUE" pkey="TRUE"/>
    <column name="data_type" nullok="TRUE" descr="Data type of the column (if the column is an array, then 'array_spec' is set, and this may be NULL)"/>
    <column name="array_spec" nullok="TRUE" descr="Array description if the column is an array"/>
    <fkey ref_table="_routines">
      <part column="specific_catalog"/>
      <part column="specific_schema"/>
      <part column="specific_name"/>
    </fkey>
    <fkey ref_table="_element_types">
      <part column="array_spec" ref_column="specific_name"/>
    </fkey>
    <!--
    <fkey ref_table="_all_types">
      <part column="data_type" ref_column="full_type_name"/>
    </fkey>
    -->
  </table>

  <table name="_table_indexes" descr="List of tables' indexes which do not relate to primary keys">
    <column name="index_catalog" nullok="TRUE" descr="Name of the catalog that contains the index"/>
    <column name="index_schema" nullok="TRUE" descr="Name of the schema that contains the index" ident="TRUE"/>
    <column name="index_name" pkey="TRUE" ident="TRUE"/>
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="is_unique" type="boolean" descr="" nullok="TRUE"/>
    <column name="index_def" descr="Index definition" nullok="TRUE"/>
    <column name="index_type" nullok="TRUE" descr="Database specific type of index such as BTREE, ..."/>
    <column name="extra" nullok="TRUE" descr="CSV string with: ASCENDING, ..."/>
    <column name="index_owner" nullok="TRUE"/>
    <column name="index_comments" nullok="TRUE"/>
    <fkey ref_table="_tables">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
    </fkey>
  </table>

  <table name="_index_column_usage" descr="List of the tables' columns involved in an index listed in the _table_indexes table">
    <column name="index_catalog" nullok="TRUE"/>
    <column name="index_schema" nullok="TRUE" ident="TRUE"/>
    <column name="index_name" pkey="TRUE" ident="TRUE"/>
    <column name="table_catalog" pkey="TRUE"/>
    <column name="table_schema" pkey="TRUE" ident="TRUE"/>
    <column name="table_name" pkey="TRUE" ident="TRUE"/>
    <column name="column_name" pkey="TRUE" nullok="TRUE" ident="TRUE"/>
    <column name="column_expr" pkey="TRUE" nullok="TRUE"/>
    <column name="ordinal_position" type="gint" descr="Column position in the index, starts at 1"/>
    <fkey ref_table="_table_indexes">
      <part column="index_name"/>
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
    </fkey>
    <!--
    <fkey ref_table="_columns">
      <part column="table_catalog"/>
      <part column="table_schema"/>
      <part column="table_name"/>
      <part column="column_name"/>
    </fkey>
    -->
  </table>
  
  <view name="_all_types" descr="List of all the data types">
    <definition>SELECT short_type_name AS short_type_name, gtype, full_type_name AS full_type_name, comments, internal AS internal, synonyms,
       NULL AS domain_catalog, NULL AS domain_schema, NULL AS domain_name,
       NULL AS udt_catalog, NULL AS udt_schema, NULL AS udt_name
       FROM _builtin_data_types
UNION
SELECT udt_short_name, udt_gtype, udt_full_name, udt_comments, udt_internal, NULL,
       NULL, NULL, NULL, udt_catalog, udt_schema, udt_name FROM _udt
UNION
SELECT domain_short_name, domain_gtype, domain_full_name, domain_comments, domain_internal, NULL,
       domain_catalog, domain_schema, domain_name , NULL, NULL, NULL FROM _domains</definition>
  </view>

  <view name="_detailled_fk" descr="For each foreign key constraint, lists all the tables' columns involved and the constraint name">
    <definition>SELECT rc.table_catalog as fk_table_catalog, rc.table_schema as fk_table_schema, rc.table_name as fk_table_name, kc1.column_name as fk_column,
      rc.ref_table_catalog as ref_table_catalog, rc.ref_table_schema as ref_table_schema, rc.ref_table_name as ref_table_name, kc2.column_name as ref_column,
      rc.constraint_name as fk_constraint_name, kc1.ordinal_position as ordinal_position
      FROM _referential_constraints rc 
      INNER JOIN _key_column_usage kc2 ON (rc.ref_table_catalog=kc2.table_catalog AND rc.ref_table_schema=kc2.table_schema AND rc.ref_table_name=kc2.table_name AND rc.ref_constraint_name=kc2.constraint_name) 
      INNER JOIN _key_column_usage kc1 ON (rc.table_catalog=kc1.table_catalog AND rc.table_schema=kc1.table_schema AND rc.table_name=kc1.table_name AND rc.constraint_name=kc1.constraint_name) 
      WHERE kc1.ordinal_position = kc2.ordinal_position 
      ORDER BY rc.table_catalog, rc.table_schema, rc.table_name, kc1.ordinal_position
    </definition>
  </view>

</schema>
