Skip to content

Does SQLPage support running CTEs and storing their output for display? #109

Answered by lovasoa
shah asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a fixed version:

WITH TableInfo AS (
  SELECT
    m.tbl_name AS table_name,
    CASE WHEN c.pk THEN '*' ELSE '' END AS is_primary_key,
    c.name AS column_name,
    c."type" AS column_type,
    CASE WHEN c."notnull" THEN '*' ELSE '' END AS not_null,
    COALESCE(c.dflt_value, '') AS default_value,
    COALESCE((SELECT pfkl."table" || '.' || pfkl."to" FROM pragma_foreign_key_list(m.tbl_name) AS pfkl WHERE pfkl."from" = c.name), '') as fk_refs,
    ROW_NUMBER() OVER (PARTITION BY m.tbl_name ORDER BY c.cid) AS row_num
  FROM sqlite_master m JOIN pragma_table_info(m.tbl_name) c ON 1=1
  WHERE m.type = 'table'
  ORDER BY table_name, row_num
),
Views AS (
  SELECT '## Views ' AS markdo…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@lovasoa
Comment options

@lovasoa
Comment options

Answer selected by shah
Comment options

You must be logged in to vote
1 reply
@shah
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants