  *
  * Copyright (c) 1996-2007, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.40 2007/08/21 01:11:13 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.41 2007/08/25 17:47:44 tgl Exp $
  */
 
 CREATE VIEW pg_roles AS 

    "Lexized token" text
);

COMMENT ON TYPE ts_debug IS 'returned type from ts_debug() function';

CREATE FUNCTION ts_debug(regconfig, text)
RETURNS SETOF ts_debug AS
$$
SELECT 
    (
        SELECT 
            tt.alias
         FROM
            pg_catalog.ts_token_type(
                (SELECT cfgparser FROM pg_catalog.pg_ts_config WHERE oid = $1 )
            ) AS tt
         WHERE
            tt.tokid = parse.tokid
    ) AS "Alias",
    (
        SELECT 
            tt.description
         FROM
            pg_catalog.ts_token_type(
                (SELECT cfgparser FROM pg_catalog.pg_ts_config WHERE oid = $1 )
            ) AS tt
         WHERE
            tt.tokid = parse.tokid
    ) AS "Description",
    parse.token AS "Token",
    ARRAY ( SELECT m.mapdict::pg_catalog.regdictionary
            FROM pg_catalog.pg_ts_config_map AS m
            WHERE m.mapcfg = $1 AND m.maptokentype = parse.tokid
            ORDER BY m.mapcfg, m.maptokentype, m.mapseqno )
    AS "Dictionaries",
    (     
        SELECT

            ( SELECT mapdict, pg_catalog.ts_lexize(mapdict, parse.token) AS lex
              FROM pg_catalog.pg_ts_config_map AS m
              WHERE m.mapcfg = $1 AND m.maptokentype = parse.tokid
              ORDER BY m.mapseqno ) dl
        WHERE dl.lex IS NOT NULL
        LIMIT 1
    ) AS "Lexized token"
FROM pg_catalog.ts_parse(
        (SELECT cfgparser FROM pg_catalog.pg_ts_config WHERE oid = $1 ), $2 
    ) AS parse,
     pg_catalog.ts_token_type(
        (SELECT cfgparser FROM pg_catalog.pg_ts_config WHERE oid = $1 )
    ) AS tt
WHERE tt.tokid = parse.tokid
$$
LANGUAGE SQL STRICT STABLE;

COMMENT ON FUNCTION ts_debug(regconfig,text) IS
    'debug function for text search configuration';

CREATE FUNCTION ts_debug(text)
RETURNS SETOF ts_debug AS
$$
    SELECT * FROM pg_catalog.ts_debug( pg_catalog.get_current_ts_config(), $1);
$$
LANGUAGE SQL STRICT STABLE;

COMMENT ON FUNCTION ts_debug(text) IS
    'debug function for current text search configuration';
