Skip to content

Commit 42c89b6

Browse files
committed
Update Metadata DB Derived.md
1 parent b83bd85 commit 42c89b6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Metadata DB Derived.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permalink: /meta/db-derived-cte
88

99
Extended parsed and structured metadata is available for table columns ([table_xinfo][]), foreign keys ([foreign_key_list][]), and indices ([index_list][] and [index_xinfo][]) via respective pragma functions. However, none of these PRAGMAs provide database-wide information. *index_xinfo* returns index-specific metadata. The three other PRAGMAs return a list of columns (all columns or columns participating in foreign keys or indices, respectively) for a particular table. Retrieval of database-wide metadata tables requires a combination of base queries.
1010

11-
### Table Columns
11+
### Table columns
1212

1313
Consider the *pragma_table_xinfo* table-valued function, which takes either the target table name as a string (not an identifier!) or a column identifier. In the latter case, each column value should contain a table name, and this option permits the construction of a query collecting database-wide column information. The first query retrieves the list of database tables (*tables*), and the second query (*columns*) uses *pragma_table_xinfo* with the retrieved table list in its JOIN clause to produce a database-wide column set. A combination of the two via either the subquery construct or common table expressions (CTEs) results in a relatively simple query, but it is instructive to follow the CTEs route. [Fig. 1](#TableColumnsCTE) shows a schematic structure of the CTEs query (left panel), which includes two subqueries discussed above. The right panel shows the corresponding CTEs code blocks.
1414

@@ -35,7 +35,7 @@ The combined query below consists of the two CTEs blocks and the following main
3535
| classes_groups | 2 | super_group | TEXT | 1 | | 0 |
3636

3737

38-
### Debugging CTE queries
38+
### Debugging CTEs queries
3939

4040
Well-structured CTEs queries provide several advantages for designing complex queries, particularly in SQLite. On the one hand, individual WITH members are convenient building blocks, as illustrated later. On the other hand, CTEs enable several debugging options, such as the ability of the main query after the WITH clause to interrogate any WITH clause member. For instance, in the example above, the last line `SELECT * FROM tables` verifies the output of the *tables* query.
4141

@@ -50,7 +50,7 @@ The names of the WITH clause member query and its returned columns form the sign
5050

5151
Additionally, given the output signature of the *tables* query and its semantics, it can now be reused as a code snippet.
5252

53-
### Foreign Keys
53+
### Foreign keys
5454

5555
Both *pragma_foreign_key_list* and *pragma_index_list* return tables containing a row for each unique (column, index/FK) combination. The Foreign Keys query starts with a copy of the *table* block. The *columns* block, however, needs adjustments to take into account the signature and semantics of the returned table (*fkey_columns*). Furthermore, for composite indices/FKs, one row is returned for each participating column. Often, it is more convenient to have one row per index/FK, meaning that an additional WITH block is necessary to collapse rows corresponding to the same composite index/FK, as shown in [Fig. 2](#ForeignKeys).
5656

0 commit comments

Comments
 (0)