LCOV - code coverage report
Current view: top level - export/scratch1/home/monet/testing/b50e8e2d6f02-1-1-1/build/sql/backends/monet5 - 52_describe.sql.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2021-10-13 02:24:04 Functions: 1 1 100.0 %

          Line data    Source code
       1             : unsigned char _52_describe_sql[17993] = {
       2             : "CREATE FUNCTION sys.describe_type(ctype string, digits integer, tscale integer)\n"
       3             : "  RETURNS string\n"
       4             : "BEGIN\n"
       5             : "  RETURN\n"
       6             : "    CASE ctype\n"
       7             : "      WHEN 'bigint' THEN 'BIGINT'\n"
       8             : "      WHEN 'blob' THEN\n"
       9             : "  CASE digits\n"
      10             : "    WHEN 0 THEN 'BINARY LARGE OBJECT'\n"
      11             : "    ELSE 'BINARY LARGE OBJECT(' || digits || ')'\n"
      12             : "  END\n"
      13             : "      WHEN 'boolean' THEN 'BOOLEAN'\n"
      14             : "      WHEN 'char' THEN\n"
      15             : "        CASE digits\n"
      16             : "          WHEN 1 THEN 'CHARACTER'\n"
      17             : "          ELSE 'CHARACTER(' || digits || ')'\n"
      18             : "        END\n"
      19             : "      WHEN 'clob' THEN\n"
      20             : "  CASE digits\n"
      21             : "    WHEN 0 THEN 'CHARACTER LARGE OBJECT'\n"
      22             : "    ELSE 'CHARACTER LARGE OBJECT(' || digits || ')'\n"
      23             : "  END\n"
      24             : "      WHEN 'date' THEN 'DATE'\n"
      25             : "      WHEN 'day_interval' THEN 'INTERVAL DAY'\n"
      26             : "      WHEN ctype = 'decimal' THEN\n"
      27             : "          CASE\n"
      28             : "    WHEN (digits = 1 AND tscale = 0) OR digits = 0 THEN 'DECIMAL'\n"
      29             : "    WHEN tscale = 0 THEN 'DECIMAL(' || digits || ')'\n"
      30             : "    WHEN digits = 39 THEN 'DECIMAL(' || 38 || ',' || tscale || ')'\n"
      31             : "    WHEN digits = 19 AND (SELECT COUNT(*) = 0 FROM sys.types WHERE sqlname = 'hugeint' ) THEN 'DECIMAL(' || 18 || ',' || tscale || ')'\n"
      32             : "    ELSE 'DECIMAL(' || digits || ',' || tscale || ')'\n"
      33             : "  END\n"
      34             : "      WHEN 'double' THEN\n"
      35             : "  CASE\n"
      36             : "    WHEN digits = 53 and tscale = 0 THEN 'DOUBLE'\n"
      37             : "    WHEN tscale = 0 THEN 'FLOAT(' || digits || ')'\n"
      38             : "    ELSE 'FLOAT(' || digits || ',' || tscale || ')'\n"
      39             : "  END\n"
      40             : "      WHEN 'geometry' THEN\n"
      41             : "  CASE digits\n"
      42             : "    WHEN 4 THEN 'GEOMETRY(POINT' ||\n"
      43             : "            CASE tscale\n"
      44             : "              WHEN 0 THEN ''\n"
      45             : "              ELSE ',' || tscale\n"
      46             : "            END || ')'\n"
      47             : "    WHEN 8 THEN 'GEOMETRY(LINESTRING' ||\n"
      48             : "            CASE tscale\n"
      49             : "              WHEN 0 THEN ''\n"
      50             : "              ELSE ',' || tscale\n"
      51             : "            END || ')'\n"
      52             : "    WHEN 16 THEN 'GEOMETRY(POLYGON' ||\n"
      53             : "            CASE tscale\n"
      54             : "              WHEN 0 THEN ''\n"
      55             : "              ELSE ',' || tscale\n"
      56             : "            END || ')'\n"
      57             : "    WHEN 20 THEN 'GEOMETRY(MULTIPOINT' ||\n"
      58             : "            CASE tscale\n"
      59             : "              WHEN 0 THEN ''\n"
      60             : "              ELSE ',' || tscale\n"
      61             : "            END || ')'\n"
      62             : "    WHEN 24 THEN 'GEOMETRY(MULTILINESTRING' ||\n"
      63             : "            CASE tscale\n"
      64             : "              WHEN 0 THEN ''\n"
      65             : "              ELSE ',' || tscale\n"
      66             : "            END || ')'\n"
      67             : "    WHEN 28 THEN 'GEOMETRY(MULTIPOLYGON' ||\n"
      68             : "            CASE tscale\n"
      69             : "              WHEN 0 THEN ''\n"
      70             : "              ELSE ',' || tscale\n"
      71             : "            END || ')'\n"
      72             : "    WHEN 32 THEN 'GEOMETRY(GEOMETRYCOLLECTION' ||\n"
      73             : "            CASE tscale\n"
      74             : "              WHEN 0 THEN ''\n"
      75             : "              ELSE ',' || tscale\n"
      76             : "            END || ')'\n"
      77             : "    ELSE 'GEOMETRY'\n"
      78             : "        END\n"
      79             : "      WHEN 'hugeint' THEN 'HUGEINT'\n"
      80             : "      WHEN 'int' THEN 'INTEGER'\n"
      81             : "      WHEN 'month_interval' THEN\n"
      82             : "  CASE digits\n"
      83             : "    WHEN 1 THEN 'INTERVAL YEAR'\n"
      84             : "    WHEN 2 THEN 'INTERVAL YEAR TO MONTH'\n"
      85             : "    WHEN 3 THEN 'INTERVAL MONTH'\n"
      86             : "  END\n"
      87             : "      WHEN 'real' THEN\n"
      88             : "  CASE\n"
      89             : "    WHEN digits = 24 and tscale = 0 THEN 'REAL'\n"
      90             : "    WHEN tscale = 0 THEN 'FLOAT(' || digits || ')'\n"
      91             : "    ELSE 'FLOAT(' || digits || ',' || tscale || ')'\n"
      92             : "  END\n"
      93             : "      WHEN 'sec_interval' THEN\n"
      94             : "  CASE digits\n"
      95             : "    WHEN 4 THEN 'INTERVAL DAY'\n"
      96             : "    WHEN 5 THEN 'INTERVAL DAY TO HOUR'\n"
      97             : "    WHEN 6 THEN 'INTERVAL DAY TO MINUTE'\n"
      98             : "    WHEN 7 THEN 'INTERVAL DAY TO SECOND'\n"
      99             : "    WHEN 8 THEN 'INTERVAL HOUR'\n"
     100             : "    WHEN 9 THEN 'INTERVAL HOUR TO MINUTE'\n"
     101             : "    WHEN 10 THEN 'INTERVAL HOUR TO SECOND'\n"
     102             : "    WHEN 11 THEN 'INTERVAL MINUTE'\n"
     103             : "    WHEN 12 THEN 'INTERVAL MINUTE TO SECOND'\n"
     104             : "    WHEN 13 THEN 'INTERVAL SECOND'\n"
     105             : "  END\n"
     106             : "      WHEN 'smallint' THEN 'SMALLINT'\n"
     107             : "      WHEN 'time' THEN\n"
     108             : "  CASE digits\n"
     109             : "    WHEN 1 THEN 'TIME'\n"
     110             : "    ELSE 'TIME(' || (digits - 1) || ')'\n"
     111             : "  END\n"
     112             : "      WHEN 'timestamp' THEN\n"
     113             : "  CASE digits\n"
     114             : "    WHEN 7 THEN 'TIMESTAMP'\n"
     115             : "    ELSE 'TIMESTAMP(' || (digits - 1) || ')'\n"
     116             : "  END\n"
     117             : "      WHEN 'timestamptz' THEN\n"
     118             : "  CASE digits\n"
     119             : "    WHEN 7 THEN 'TIMESTAMP'\n"
     120             : "    ELSE 'TIMESTAMP(' || (digits - 1) || ')'\n"
     121             : "  END || ' WITH TIME ZONE'\n"
     122             : "      WHEN 'timetz' THEN\n"
     123             : "  CASE digits\n"
     124             : "    WHEN 1 THEN 'TIME'\n"
     125             : "    ELSE 'TIME(' || (digits - 1) || ')'\n"
     126             : "  END || ' WITH TIME ZONE'\n"
     127             : "      WHEN 'tinyint' THEN 'TINYINT'\n"
     128             : "      WHEN 'varchar' THEN 'CHARACTER VARYING(' || digits || ')'\n"
     129             : "      ELSE\n"
     130             : "        CASE\n"
     131             : "          WHEN lower(ctype) = ctype THEN upper(ctype)\n"
     132             : "          ELSE '\"' || ctype || '\"'\n"
     133             : "        END || CASE digits\n"
     134             : "    WHEN 0 THEN ''\n"
     135             : "          ELSE '(' || digits || CASE tscale\n"
     136             : "      WHEN 0 THEN ''\n"
     137             : "            ELSE ',' || tscale\n"
     138             : "          END || ')'\n"
     139             : "  END\n"
     140             : "    END;\n"
     141             : "END;\n"
     142             : "CREATE FUNCTION sys.SQ (s STRING) RETURNS STRING BEGIN RETURN '''' || sys.replace(s,'''','''''') || ''''; END;\n"
     143             : "CREATE FUNCTION sys.DQ (s STRING) RETURNS STRING BEGIN RETURN '\"' || sys.replace(s,'\"','\"\"') || '\"'; END;\n"
     144             : "CREATE FUNCTION sys.FQN(s STRING, t STRING) RETURNS STRING BEGIN RETURN sys.DQ(s) || '.' || sys.DQ(t); END;\n"
     145             : "CREATE FUNCTION sys.ALTER_TABLE(s STRING, t STRING) RETURNS STRING BEGIN RETURN 'ALTER TABLE ' || sys.FQN(s, t); END;\n"
     146             : "CREATE FUNCTION sys.replace_first(ori STRING, pat STRING, rep STRING, flg STRING) RETURNS STRING EXTERNAL NAME \"pcre\".\"replace_first\";\n"
     147             : "CREATE FUNCTION sys.schema_guard(sch STRING, nme STRING, stmt STRING) RETURNS STRING BEGIN\n"
     148             : "RETURN\n"
     149             : "  SELECT sys.replace_first(stmt, '(\\\\s*\"?' || sch ||  '\"?\\\\s*\\\\.|)\\\\s*\"?' || nme || '\"?\\\\s*', ' ' || sys.FQN(sch, nme) || ' ', 'imsx');\n"
     150             : "END;\n"
     151             : "CREATE VIEW sys.describe_constraints AS\n"
     152             : "  SELECT\n"
     153             : "          s.name sch,\n"
     154             : "          t.name tbl,\n"
     155             : "          kc.name col,\n"
     156             : "          k.name con,\n"
     157             : "          CASE k.type WHEN 0 THEN 'PRIMARY KEY' WHEN 1 THEN 'UNIQUE' END tpe\n"
     158             : "  FROM sys.schemas s, sys._tables t, sys.objects kc, sys.keys k\n"
     159             : "  WHERE kc.id = k.id\n"
     160             : "          AND k.table_id = t.id\n"
     161             : "          AND s.id = t.schema_id\n"
     162             : "          AND t.system = FALSE\n"
     163             : "          AND k.type in (0, 1);\n"
     164             : "CREATE VIEW sys.describe_indices AS\n"
     165             : "  WITH it (id, idx) AS (VALUES (0, 'INDEX'), (4, 'IMPRINTS INDEX'), (5, 'ORDERED INDEX'))\n"
     166             : "  SELECT\n"
     167             : "          i.name ind,\n"
     168             : "          s.name sch,\n"
     169             : "          t.name tbl,\n"
     170             : "          c.name col,\n"
     171             : "          it.idx tpe\n"
     172             : "  FROM\n"
     173             : "          sys.idxs AS i LEFT JOIN sys.keys AS k ON i.name = k.name,\n"
     174             : "          sys.objects AS kc,\n"
     175             : "          sys._columns AS c,\n"
     176             : "          sys.schemas s,\n"
     177             : "          sys._tables AS t,\n"
     178             : "          it\n"
     179             : "  WHERE\n"
     180             : "          i.table_id = t.id\n"
     181             : "          AND i.id = kc.id\n"
     182             : "          AND kc.name = c.name\n"
     183             : "          AND t.id = c.table_id\n"
     184             : "          AND t.schema_id = s.id\n"
     185             : "          AND k.type IS NULL\n"
     186             : "          AND i.type = it.id\n"
     187             : "  ORDER BY i.name, kc.nr;\n"
     188             : "CREATE VIEW sys.describe_column_defaults AS\n"
     189             : "  SELECT\n"
     190             : "          s.name sch,\n"
     191             : "          t.name tbl,\n"
     192             : "          c.name col,\n"
     193             : "          c.\"default\" def\n"
     194             : "  FROM sys.schemas s, sys.tables t, sys.columns c\n"
     195             : "  WHERE\n"
     196             : "          s.id = t.schema_id AND\n"
     197             : "          t.id = c.table_id AND\n"
     198             : "          s.name <> 'tmp' AND\n"
     199             : "          NOT t.system AND\n"
     200             : "          c.\"default\" IS NOT NULL;\n"
     201             : "CREATE VIEW sys.describe_foreign_keys AS\n"
     202             : "          WITH action_type (id, act) AS (VALUES\n"
     203             : "                  (0, 'NO ACTION'),\n"
     204             : "                  (1, 'CASCADE'),\n"
     205             : "                  (2, 'RESTRICT'),\n"
     206             : "                  (3, 'SET NULL'),\n"
     207             : "                  (4, 'SET DEFAULT'))\n"
     208             : "          SELECT\n"
     209             : "                  fs.name fk_s,\n"
     210             : "                  fkt.name fk_t,\n"
     211             : "                  fkkc.name fk_c,\n"
     212             : "                  fkkc.nr o,\n"
     213             : "                  fkk.name fk,\n"
     214             : "                  ps.name pk_s,\n"
     215             : "                  pkt.name pk_t,\n"
     216             : "                  pkkc.name pk_c,\n"
     217             : "                  ou.act on_update,\n"
     218             : "                  od.act on_delete\n"
     219             : "          FROM sys._tables fkt,\n"
     220             : "                  sys.objects fkkc,\n"
     221             : "                  sys.keys fkk,\n"
     222             : "                  sys._tables pkt,\n"
     223             : "                  sys.objects pkkc,\n"
     224             : "                  sys.keys pkk,\n"
     225             : "                  sys.schemas ps,\n"
     226             : "                  sys.schemas fs,\n"
     227             : "                  action_type ou,\n"
     228             : "                  action_type od\n"
     229             : "          WHERE fkt.id = fkk.table_id\n"
     230             : "          AND pkt.id = pkk.table_id\n"
     231             : "          AND fkk.id = fkkc.id\n"
     232             : "          AND pkk.id = pkkc.id\n"
     233             : "          AND fkk.rkey = pkk.id\n"
     234             : "          AND fkkc.nr = pkkc.nr\n"
     235             : "          AND pkt.schema_id = ps.id\n"
     236             : "          AND fkt.schema_id = fs.id\n"
     237             : "          AND (fkk.\"action\" & 255)         = od.id\n"
     238             : "          AND ((fkk.\"action\" >> 8) & 255)  = ou.id\n"
     239             : "          ORDER BY fkk.name, fkkc.nr;\n"
     240             : "CREATE FUNCTION sys.get_merge_table_partition_expressions(tid INT) RETURNS STRING\n"
     241             : "BEGIN\n"
     242             : "  RETURN\n"
     243             : "          SELECT\n"
     244             : "                  CASE WHEN tp.table_id IS NOT NULL THEN\n"
     245             : "                          ' PARTITION BY ' ||\n"
     246             : "                          ifthenelse(bit_and(tp.type, 2) = 2, 'VALUES ', 'RANGE ') ||\n"
     247             : "                          CASE\n"
     248             : "                                  WHEN bit_and(tp.type, 4) = 4\n"
     249             : "                                  THEN 'ON ' || '(' || (SELECT sys.DQ(c.name) || ')' FROM sys.columns c WHERE c.id = tp.column_id)\n"
     250             : "                                  ELSE 'USING ' || '(' || tp.expression || ')'\n"
     251             : "                          END\n"
     252             : "                  ELSE\n"
     253             : "                          ''\n"
     254             : "                  END\n"
     255             : "          FROM (VALUES (tid)) t(id) LEFT JOIN sys.table_partitions tp ON t.id = tp.table_id;\n"
     256             : "END;\n"
     257             : "CREATE FUNCTION sys.get_remote_table_expressions(s STRING, t STRING) RETURNS STRING BEGIN\n"
     258             : "  RETURN SELECT ' ON ' || sys.SQ(uri) || ' WITH USER ' || sys.SQ(username) || ' ENCRYPTED PASSWORD ' || sys.SQ(\"hash\") FROM sys.remote_table_credentials(s ||'.' || t);\n"
     259             : "END;\n"
     260             : "CREATE VIEW sys.describe_tables AS\n"
     261             : "  SELECT\n"
     262             : "          t.id o,\n"
     263             : "          s.name sch,\n"
     264             : "          t.name tab,\n"
     265             : "          ts.table_type_name typ,\n"
     266             : "          (SELECT\n"
     267             : "                  ' (' ||\n"
     268             : "                  GROUP_CONCAT(\n"
     269             : "                          sys.DQ(c.name) || ' ' ||\n"
     270             : "                          sys.describe_type(c.type, c.type_digits, c.type_scale) ||\n"
     271             : "                          ifthenelse(c.\"null\" = 'false', ' NOT NULL', '')\n"
     272             : "                  , ', ') || ')'\n"
     273             : "          FROM sys._columns c\n"
     274             : "          WHERE c.table_id = t.id) col,\n"
     275             : "          CASE ts.table_type_name\n"
     276             : "                  WHEN 'REMOTE TABLE' THEN\n"
     277             : "                          sys.get_remote_table_expressions(s.name, t.name)\n"
     278             : "                  WHEN 'MERGE TABLE' THEN\n"
     279             : "                          sys.get_merge_table_partition_expressions(t.id)\n"
     280             : "                  WHEN 'VIEW' THEN\n"
     281             : "                          sys.schema_guard(s.name, t.name, t.query)\n"
     282             : "                  ELSE\n"
     283             : "                          ''\n"
     284             : "          END opt\n"
     285             : "  FROM sys.schemas s, sys.table_types ts, sys.tables t\n"
     286             : "  WHERE ts.table_type_name IN ('TABLE', 'VIEW', 'MERGE TABLE', 'REMOTE TABLE', 'REPLICA TABLE')\n"
     287             : "          AND t.system = FALSE\n"
     288             : "          AND s.id = t.schema_id\n"
     289             : "          AND ts.table_type_id = t.type\n"
     290             : "          AND s.name <> 'tmp';\n"
     291             : "CREATE VIEW sys.describe_triggers AS\n"
     292             : "          SELECT\n"
     293             : "                  s.name sch,\n"
     294             : "                  t.name tab,\n"
     295             : "                  tr.name tri,\n"
     296             : "                  tr.statement def\n"
     297             : "          FROM sys.schemas s, sys.tables t, sys.triggers tr\n"
     298             : "          WHERE s.id = t.schema_id AND t.id = tr.table_id AND NOT t.system;\n"
     299             : "CREATE VIEW sys.describe_comments AS\n"
     300             : "          SELECT\n"
     301             : "                  o.id id,\n"
     302             : "                  o.tpe tpe,\n"
     303             : "                  o.nme fqn,\n"
     304             : "                  c.remark rem\n"
     305             : "          FROM (\n"
     306             : "                  SELECT id, 'SCHEMA', sys.DQ(name) FROM sys.schemas\n"
     307             : "                  UNION ALL\n"
     308             : "                  SELECT t.id, ifthenelse(ts.table_type_name = 'VIEW', 'VIEW', 'TABLE'), sys.FQN(s.name, t.name)\n"
     309             : "                  FROM sys.schemas s JOIN sys.tables t ON s.id = t.schema_id JOIN sys.table_types ts ON t.type = ts.table_type_id\n"
     310             : "                  WHERE s.name <> 'tmp'\n"
     311             : "                  UNION ALL\n"
     312             : "                  SELECT c.id, 'COLUMN', sys.FQN(s.name, t.name) || '.' || sys.DQ(c.name) FROM sys.columns c, sys.tables t, sys.schemas s WHERE c.table_id = t.id AND t.schema_id = s.id\n"
     313             : "                  UNION ALL\n"
     314             : "                  SELECT idx.id, 'INDEX', sys.FQN(s.name, idx.name) FROM sys.idxs idx, sys._tables t, sys.schemas s WHERE idx.table_id = t.id AND t.schema_id = s.id\n"
     315             : "                  UNION ALL\n"
     316             : "                  SELECT seq.id, 'SEQUENCE', sys.FQN(s.name, seq.name) FROM sys.sequences seq, sys.schemas s WHERE seq.schema_id = s.id\n"
     317             : "                  UNION ALL\n"
     318             : "                  SELECT f.id, ft.function_type_keyword, sys.FQN(s.name, f.name) FROM sys.functions f, sys.function_types ft, sys.schemas s WHERE f.type = ft.function_type_id AND f.schema_id = s.id\n"
     319             : "                  ) AS o(id, tpe, nme)\n"
     320             : "                  JOIN sys.comments c ON c.id = o.id;\n"
     321             : "CREATE VIEW sys.fully_qualified_functions AS\n"
     322             : "  WITH fqn(id, tpe, sig, num) AS\n"
     323             : "  (\n"
     324             : "          SELECT\n"
     325             : "                  f.id,\n"
     326             : "                  ft.function_type_keyword,\n"
     327             : "                  CASE WHEN a.type IS NULL THEN\n"
     328             : "                          s.name || '.' || f.name || '()'\n"
     329             : "                  ELSE\n"
     330             : "                          s.name || '.' || f.name || '(' || group_concat(sys.describe_type(a.type, a.type_digits, a.type_scale), ',') OVER (PARTITION BY f.id ORDER BY a.number)  || ')'\n"
     331             : "                  END,\n"
     332             : "                  a.number\n"
     333             : "          FROM sys.schemas s, sys.function_types ft, sys.functions f LEFT JOIN sys.args a ON f.id = a.func_id\n"
     334             : "          WHERE s.id= f.schema_id AND f.type = ft.function_type_id\n"
     335             : "  )\n"
     336             : "  SELECT\n"
     337             : "          fqn1.id id,\n"
     338             : "          fqn1.tpe tpe,\n"
     339             : "          fqn1.sig nme\n"
     340             : "  FROM\n"
     341             : "          fqn fqn1 JOIN (SELECT id, max(num) FROM fqn GROUP BY id)  fqn2(id, num)\n"
     342             : "          ON fqn1.id = fqn2.id AND (fqn1.num = fqn2.num OR fqn1.num IS NULL AND fqn2.num is NULL);\n"
     343             : "CREATE VIEW sys.describe_privileges AS\n"
     344             : "  SELECT\n"
     345             : "          CASE\n"
     346             : "                  WHEN o.tpe IS NULL AND pc.privilege_code_name = 'SELECT' THEN\n"
     347             : "                          'COPY FROM'\n"
     348             : "                  WHEN o.tpe IS NULL AND pc.privilege_code_name = 'UPDATE' THEN\n"
     349             : "                          'COPY INTO'\n"
     350             : "                  ELSE\n"
     351             : "                          o.nme\n"
     352             : "          END o_nme,\n"
     353             : "          coalesce(o.tpe, 'GLOBAL') o_tpe,\n"
     354             : "          pc.privilege_code_name p_nme,\n"
     355             : "          a.name a_nme,\n"
     356             : "          g.name g_nme,\n"
     357             : "          p.grantable grantable\n"
     358             : "  FROM\n"
     359             : "          sys.privileges p LEFT JOIN\n"
     360             : "          (\n"
     361             : "          SELECT t.id, s.name || '.' || t.name , 'TABLE'\n"
     362             : "                  from sys.schemas s, sys.tables t where s.id = t.schema_id\n"
     363             : "          UNION ALL\n"
     364             : "                  SELECT c.id, s.name || '.' || t.name || '.' || c.name, 'COLUMN'\n"
     365             : "                  FROM sys.schemas s, sys.tables t, sys.columns c where s.id = t.schema_id AND t.id = c.table_id\n"
     366             : "          UNION ALL\n"
     367             : "                  SELECT f.id, f.nme, f.tpe\n"
     368             : "                  FROM sys.fully_qualified_functions f\n"
     369             : "          ) o(id, nme, tpe) ON o.id = p.obj_id,\n"
     370             : "          sys.privilege_codes pc,\n"
     371             : "          auths a, auths g\n"
     372             : "  WHERE\n"
     373             : "          p.privileges = pc.privilege_code_id AND\n"
     374             : "          p.auth_id = a.id AND\n"
     375             : "          p.grantor = g.id;\n"
     376             : "CREATE FUNCTION sys.describe_table(schemaName string, tableName string)\n"
     377             : "  RETURNS TABLE(name string, query string, type string, id integer, remark string)\n"
     378             : "BEGIN\n"
     379             : "  RETURN SELECT t.name, t.query, tt.table_type_name, t.id, c.remark\n"
     380             : "          FROM sys.schemas s, sys.table_types tt, sys._tables t\n"
     381             : "          LEFT OUTER JOIN sys.comments c ON t.id = c.id\n"
     382             : "                  WHERE s.name = schemaName\n"
     383             : "                  AND t.schema_id = s.id\n"
     384             : "                  AND t.name = tableName\n"
     385             : "                  AND t.type = tt.table_type_id;\n"
     386             : "END;\n"
     387             : "CREATE VIEW sys.describe_user_defined_types AS\n"
     388             : "  SELECT\n"
     389             : "          s.name sch,\n"
     390             : "          t.sqlname sql_tpe,\n"
     391             : "          t.systemname ext_tpe\n"
     392             : "  FROM sys.types t JOIN sys.schemas s ON t.schema_id = s.id\n"
     393             : "  WHERE\n"
     394             : "          t.eclass = 18 AND\n"
     395             : "          (\n"
     396             : "                  (s.name = 'sys' AND t.sqlname not in ('geometrya', 'mbr', 'url', 'inet', 'json', 'uuid', 'xml')) OR\n"
     397             : "                  (s.name <> 'sys')\n"
     398             : "          );\n"
     399             : "CREATE VIEW sys.describe_partition_tables AS\n"
     400             : "  SELECT\n"
     401             : "          m_sch,\n"
     402             : "          m_tbl,\n"
     403             : "          p_sch,\n"
     404             : "          p_tbl,\n"
     405             : "          CASE\n"
     406             : "                  WHEN p_raw_type IS NULL THEN 'READ ONLY'\n"
     407             : "                  WHEN (p_raw_type = 'VALUES' AND pvalues IS NULL) OR (p_raw_type = 'RANGE' AND minimum IS NULL AND maximum IS NULL AND with_nulls) THEN 'FOR NULLS'\n"
     408             : "                  ELSE p_raw_type\n"
     409             : "          END AS tpe,\n"
     410             : "          pvalues,\n"
     411             : "          minimum,\n"
     412             : "          maximum,\n"
     413             : "          with_nulls\n"
     414             : "  FROM\n"
     415             : "    (WITH\n"
     416             : "          tp(\"type\", table_id) AS\n"
     417             : "          (SELECT ifthenelse((table_partitions.\"type\" & 2) = 2, 'VALUES', 'RANGE'), table_partitions.table_id FROM sys.table_partitions),\n"
     418             : "          subq(m_tid, p_mid, \"type\", m_sch, m_tbl, p_sch, p_tbl) AS\n"
     419             : "          (SELECT m_t.id, p_m.id, m_t.\"type\", m_s.name, m_t.name, p_s.name, p_m.name\n"
     420             : "          FROM sys.schemas m_s, sys._tables m_t, sys.dependencies d, sys.schemas p_s, sys._tables p_m\n"
     421             : "          WHERE m_t.\"type\" IN (3, 6)\n"
     422             : "                  AND m_t.schema_id = m_s.id\n"
     423             : "                  AND m_s.name <> 'tmp'\n"
     424             : "                  AND m_t.system = FALSE\n"
     425             : "                  AND m_t.id = d.depend_id\n"
     426             : "                  AND d.id = p_m.id\n"
     427             : "                  AND p_m.schema_id = p_s.id\n"
     428             : "          ORDER BY m_t.id, p_m.id)\n"
     429             : "  SELECT\n"
     430             : "          subq.m_sch,\n"
     431             : "          subq.m_tbl,\n"
     432             : "          subq.p_sch,\n"
     433             : "          subq.p_tbl,\n"
     434             : "          tp.\"type\" AS p_raw_type,\n"
     435             : "          CASE WHEN tp.\"type\" = 'VALUES'\n"
     436             : "                  THEN (SELECT GROUP_CONCAT(vp.value, ',') FROM sys.value_partitions vp WHERE vp.table_id = subq.p_mid)\n"
     437             : "                  ELSE NULL\n"
     438             : "          END AS pvalues,\n"
     439             : "          CASE WHEN tp.\"type\" = 'RANGE'\n"
     440             : "                  THEN (SELECT minimum FROM sys.range_partitions rp WHERE rp.table_id = subq.p_mid)\n"
     441             : "                  ELSE NULL\n"
     442             : "          END AS minimum,\n"
     443             : "          CASE WHEN tp.\"type\" = 'RANGE'\n"
     444             : "                  THEN (SELECT maximum FROM sys.range_partitions rp WHERE rp.table_id = subq.p_mid)\n"
     445             : "                  ELSE NULL\n"
     446             : "          END AS maximum,\n"
     447             : "          CASE WHEN tp.\"type\" = 'VALUES'\n"
     448             : "                  THEN EXISTS(SELECT vp.value FROM sys.value_partitions vp WHERE vp.table_id = subq.p_mid AND vp.value IS NULL)\n"
     449             : "                  ELSE (SELECT rp.with_nulls FROM sys.range_partitions rp WHERE rp.table_id = subq.p_mid)\n"
     450             : "          END AS with_nulls\n"
     451             : "  FROM\n"
     452             : "          subq LEFT OUTER JOIN tp\n"
     453             : "          ON subq.m_tid = tp.table_id) AS tmp_pi;\n"
     454             : "CREATE VIEW sys.describe_sequences AS\n"
     455             : "  SELECT\n"
     456             : "          s.name as sch,\n"
     457             : "          seq.name as seq,\n"
     458             : "          seq.\"start\" s,\n"
     459             : "          get_value_for(s.name, seq.name) AS rs,\n"
     460             : "          seq.\"minvalue\" mi,\n"
     461             : "          seq.\"maxvalue\" ma,\n"
     462             : "          seq.\"increment\" inc,\n"
     463             : "          seq.\"cacheinc\" cache,\n"
     464             : "          seq.\"cycle\" cycle\n"
     465             : "  FROM sys.sequences seq, sys.schemas s\n"
     466             : "  WHERE s.id = seq.schema_id\n"
     467             : "  AND s.name <> 'tmp'\n"
     468             : "  ORDER BY s.name, seq.name;\n"
     469             : "CREATE VIEW sys.describe_functions AS\n"
     470             : "  WITH func_args_all(func_id, number, max_number, func_arg) AS\n"
     471             : "  (\n"
     472             : "          SELECT\n"
     473             : "                  func_id,\n"
     474             : "                  number,\n"
     475             : "                  max(number) OVER (PARTITION BY func_id ORDER BY number DESC),\n"
     476             : "                  group_concat(sys.dq(name) || ' ' || sys.describe_type(type, type_digits, type_scale),', ') OVER (PARTITION BY func_id ORDER BY number)\n"
     477             : "          FROM sys.args\n"
     478             : "          WHERE inout = 1\n"
     479             : "  ),\n"
     480             : "  func_args(func_id, func_arg) AS\n"
     481             : "  (\n"
     482             : "          SELECT func_id, func_arg\n"
     483             : "          FROM func_args_all\n"
     484             : "          WHERE number = max_number\n"
     485             : "  ),\n"
     486             : "  func_rets_all(func_id, number, max_number, func_ret, func_ret_type) AS\n"
     487             : "  (\n"
     488             : "          SELECT\n"
     489             : "                  func_id,\n"
     490             : "                  number,\n"
     491             : "                  max(number) OVER (PARTITION BY func_id ORDER BY number DESC),\n"
     492             : "                  group_concat(sys.dq(name) || ' ' || sys.describe_type(type, type_digits, type_scale),', ') OVER (PARTITION BY func_id ORDER BY number),\n"
     493             : "                  group_concat(sys.describe_type(type, type_digits, type_scale),', ') OVER (PARTITION BY func_id ORDER BY number)\n"
     494             : "          FROM sys.args\n"
     495             : "          WHERE inout = 0\n"
     496             : "  ),\n"
     497             : "  func_rets(func_id, func_ret, func_ret_type) AS\n"
     498             : "  (\n"
     499             : "          SELECT\n"
     500             : "                  func_id,\n"
     501             : "                  func_ret,\n"
     502             : "                  func_ret_type\n"
     503             : "          FROM func_rets_all\n"
     504             : "          WHERE number = max_number\n"
     505             : "  )\n"
     506             : "  SELECT\n"
     507             : "          f.id o,\n"
     508             : "          s.name sch,\n"
     509             : "          f.name fun,\n"
     510             : "          CASE WHEN f.language IN (1, 2) THEN f.func ELSE 'CREATE ' || ft.function_type_keyword || ' ' || sys.FQN(s.name, f.name) || '(' || coalesce(fa.func_arg, '') || ')' || CASE WHEN f.type = 5 THEN ' RETURNS TABLE (' || coalesce(fr.func_ret, '') || ')' WHEN f.type IN (1,3) THEN ' RETURNS ' || fr.func_ret_type ELSE '' END || CASE WHEN fl.language_keyword IS NULL THEN '' ELSE ' LANGUAGE ' || fl.language_keyword END || ' ' || f.func END def\n"
     511             : "  FROM sys.functions f\n"
     512             : "          LEFT OUTER JOIN func_args fa ON fa.func_id = f.id\n"
     513             : "          LEFT OUTER JOIN func_rets fr ON fr.func_id = f.id\n"
     514             : "          JOIN sys.schemas s ON f.schema_id = s.id\n"
     515             : "          JOIN sys.function_types ft ON f.type = ft.function_type_id\n"
     516             : "          LEFT OUTER JOIN sys.function_languages fl ON f.language = fl.language_id\n"
     517             : "  WHERE s.name <> 'tmp' AND NOT f.system;\n"
     518             : "CREATE FUNCTION sys.describe_columns(schemaName string, tableName string)\n"
     519             : "  RETURNS TABLE(name string, type string, digits integer, scale integer, Nulls boolean, cDefault string, number integer, sqltype string, remark string)\n"
     520             : "BEGIN\n"
     521             : "  RETURN SELECT c.name, c.\"type\", c.type_digits, c.type_scale, c.\"null\", c.\"default\", c.number, sys.describe_type(c.\"type\", c.type_digits, c.type_scale), com.remark\n"
     522             : "          FROM sys._tables t, sys.schemas s, sys._columns c\n"
     523             : "          LEFT OUTER JOIN sys.comments com ON c.id = com.id\n"
     524             : "                  WHERE c.table_id = t.id\n"
     525             : "                  AND t.name = tableName\n"
     526             : "                  AND t.schema_id = s.id\n"
     527             : "                  AND s.name = schemaName\n"
     528             : "          ORDER BY c.number;\n"
     529             : "END;\n"
     530             : "CREATE FUNCTION sys.describe_function(schemaName string, functionName string)\n"
     531             : "  RETURNS TABLE(id integer, name string, type string, language string, remark string)\n"
     532             : "BEGIN\n"
     533             : "  RETURN SELECT f.id, f.name, ft.function_type_keyword, fl.language_keyword, c.remark\n"
     534             : "          FROM sys.functions f\n"
     535             : "          JOIN sys.schemas s ON f.schema_id = s.id\n"
     536             : "          JOIN sys.function_types ft ON f.type = ft.function_type_id\n"
     537             : "          LEFT OUTER JOIN sys.function_languages fl ON f.language = fl.language_id\n"
     538             : "          LEFT OUTER JOIN sys.comments c ON f.id = c.id\n"
     539             : "          WHERE f.name=functionName AND s.name = schemaName;\n"
     540             : "END;\n"
     541             : };
     542             : #include "monetdb_config.h"
     543             : #include "sql_import.h"
     544             : #ifdef _MSC_VER
     545             : #undef read
     546             : #pragma section(".CRT$XCU",read)
     547             : #endif
     548         256 : LIB_STARTUP_FUNC(init_52_describe_sql)
     549         256 : { sql_register("52_describe", _52_describe_sql); }

Generated by: LCOV version 1.14