<!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title>PGWeb | API - 5=5@8@>20=85 A;CG09=KE :;NG59</title> <style> body { font-size: 14px; font-family: sans-serif; padding: 0; margin: 0; } .root_title { padding: 10px; background: #326690; color: #fff; } .root_title b { font-size: 47px; } .lible { padding: 10px; border: solid 1px #cbf5ff; border-radius: 4px; color: #0c6080; } @media screen and (max-width: 800px) { .root_title span { display: none; } } .ctx { padding: 10px; } .lnk_root_title { color: #fff; text-decoration: none; } </style> <script src="/src/jquery-3.3.1.min.js"></script> </head> <body> <div class="root_title"><b><a class="lnk_root_title" href="/">PGWeb</a></b> <span>&minus; =51>;LH0O SQL-181;8>B5:0 4;O A>740=8O web-?@8;>65=89</span></div> <div class="ctx"> <style> pre { padding: 10px; background: #eee; overflow: auto; font-size: 14px; font-family: sans-serif; } .in[data-req=""] { font-style: italic; opacity: 0.4; } body, table { font-size: 14px; font-family: sans-serif; } .out, .in { display: inline-block; border-bottom: solid 1px; cursor: pointer; font-weight: bold; } .out { color: red; } .in { color: #47e647; } .in.active_key { color: #008800; } .out.active_key { color: #750303; } .td_func span:last-child { display: none; } .td_func { width: 40%; } .table_functions { border-collapse: collapse; } .table_functions tr td { border: solid 1px #eee; vertical-align: top; padding: 4px; } .table_functions tr:first-child td { font-weight: bold; } .table_exceptions { border-collapse: collapse; position: absolute; background: #fff; padding: 4px; width: 400px; display: none; } .table_exceptions tr td { border-color: #aaa; } .title_exceptions { display: inline-block; border-bottom: dotted 1px; color: red; cursor: pointer; font-weight: bold; } .exceptions_tr { background: #eee; } .example_warning { display: inline-block; color: #fff; margin-top: 10px; margin-left: 10px; background: #709080; padding: 4px; margin-bottom: 4px; border-radius: 2px; } </style> <h1>5=5@8@>20=85 A;CG09=KE :;NG59</h1> <div class="out" data-req="">KE>4=>5 7=0G5=85</div><br/> <div class="in" data-req="1">1O70B5;L=K9 ?0@0<5B@</div><br/> <div class="in" data-req="">5>1O70B5;L=K9 ?0@0<5B@</div><br/> <br/> <table class="table_functions"> <tr> <td>$C=:F8O</td> <td>?8A0=85</td> <td>@8<5@</td> </tr> <tr> <td class="td_func"><div class="out" data-key="" title="">VOID</div> <a href="#add_name0" name="add_name0">add_name</a> ( <div class="in" data-req="1" title="<O" data-key="name">VARCHAR</div><span>,</span> )</td> <td> >102;O5B 8<O </td> <td style="width:35%">SELECT schema_keys.add_name( 'sessions_keys' );</td> </tr> <tr> <td class="td_func"><div class="out" data-key="" title="">VOID</div> <a href="#remove_name1" name="remove_name1">remove_name</a> ( <div class="in" data-req="1" title="<O" data-key="name">VARCHAR</div><span>,</span> )</td> <td> #40;O5B 8<O <div> <div class="title_exceptions">A:;NG5=8O</div> <table class="table_exceptions"> <tr> <td>;NG</td> <td>?8A0=85</td> </tr> <tr> <td><b>RESERVE NAME</b></td> <td><O 70@575@28@>20=></td> </tr> </table> </div> </td> <td style="width:35%">SELECT schema_keys.remove_name( 'sesisons_keys' );</td> </tr> <tr> <td class="td_func"><div class="out" data-key="" title="">VOID</div> <a href="#set_length2" name="set_length2">set_length</a> ( <div class="in" data-req="1" title=";8=0 C=8:0;L=>3> :;NG0" data-key="length">INT</div><span>,</span> )</td> <td> 0405B 4;8=C C=8:0;L=>3> :;NG0 4;O 45D>;B=>3> 8<5=8 </td> <td style="width:35%">SELECT schema_keys.set_length( 25 );</td> </tr> <tr> <td class="td_func"><div class="out" data-key="" title="">VOID</div> <a href="#set_length3" name="set_length3">set_length</a> ( <div class="in" data-req="1" title="<O" data-key="name">VARCHAR</div><span>,</span> <div class="in" data-req="1" title=";8=0 C=8:0;L=>3> :;NG0" data-key="length">INT</div><span>,</span> )</td> <td> 0405B 4;8=C C=8:0;L=>3> :;NG0 4;O :>=:@5B=>3> 8<5=8 </td> <td style="width:35%">SELECT schema_keys.set_length( 'sessions_keys', 25 );</td> </tr> <tr> <td class="td_func"><div class="out" data-key="" title="#=8:0;L=K9 :;NG">VARCHAR(255)</div> <a href="#generate4" name="generate4">generate</a> ( )</td> <td> 5=5@8@C5B C=8:0;L=K9 :;NG ?> 45D>;B=><C 8<5=8 </td> <td style="width:35%">SELECT schema_keys.generate();</td> </tr> <tr> <td class="td_func"><div class="out" data-key="" title="#=8:0;L=K9 :;NG">VARCHAR(255)</div> <a href="#generate5" name="generate5">generate</a> ( <div class="in" data-req="1" title="<O" data-key="name">VARCHAR</div><span>,</span> )</td> <td> 5=5@8@C5B C=8:0;L=K9 :;NG ?> :>=:@5B=><C 8<5=8 <div> <div class="title_exceptions">A:;NG5=8O</div> <table class="table_exceptions"> <tr> <td>;NG</td> <td>?8A0=85</td> </tr> <tr> <td><b>NOT FOUND</b></td> <td>5 =0945=></td> </tr> </table> </div> </td> <td style="width:35%">SELECT schema_keys.generate( 'sessions_keys' );</td> </tr> <tr> <td class="td_func"><div class="out" data-key="keys" title="#=8:0;L=K5 :;NG8">SETOF VARCHAR(255)</div> <a href="#generate_series6" name="generate_series6">generate_series</a> ( <div class="in" data-req="1" title=">;8G5AB2> :;NG59" data-key="count">INT</div><span>,</span> )</td> <td> 5=5@8@C5B A5@8N C=8:0;L=KE :;NG59 ?> 45D>;B=><C 8<5=8 <div> <div class="title_exceptions">A:;NG5=8O</div> <table class="table_exceptions"> <tr> <td>;NG</td> <td>?8A0=85</td> </tr> <tr> <td><b>NOT VALID COUNT</b></td> <td>5?@028;L=K9 @07<5@ A5@88</td> </tr> <tr> <td><b>NOT FOUND</b></td> <td>5 =0945=></td> </tr> </table> </div> </td> <td style="width:35%">SELECT schema_keys.generate_series( 50 );</td> </tr> <tr> <td class="td_func"><div class="out" data-key="keys" title="#=8:0;L=K5 :;NG8">SETOF VARCHAR(255)</div> <a href="#generate_series7" name="generate_series7">generate_series</a> ( <div class="in" data-req="1" title="<O" data-key="name">VARCHAR</div><span>,</span> <div class="in" data-req="1" title=">;8G5AB2> :;NG59" data-key="count">INT</div><span>,</span> )</td> <td> 5=5@8@C5B A5@8N C=8:0;L=KE :;NG59 ?> :>=:@5B=><C 8<5=8 <div> <div class="title_exceptions">A:;NG5=8O</div> <table class="table_exceptions"> <tr> <td>;NG</td> <td>?8A0=85</td> </tr> <tr> <td><b>NOT VALID COUNT</b></td> <td>5?@028;L=K9 @07<5@ A5@88</td> </tr> <tr> <td><b>NOT FOUND</b></td> <td>5 =0945=></td> </tr> </table> </div> </td> <td style="width:35%">SELECT schema_keys.generate_series( 'sessions_keys', 50 );</td> </tr> <tr> <td class="td_func"><div class="out" data-key="count_free" title=">;8G5AB2> A2>1>4=KE :;NG59">INT</div> <a href="#get_free_count8" name="get_free_count8">get_free_count</a> ( )</td> <td> A?><>30B5;L=0O DC=:F8O. >72@0I05B :>;8G5AB2> A2>1>4=KE :;NG59. A?>;L7C5BAO A>2<5AB=> A generate_series. </td> <td style="width:35%">SELECT schema_keys.get_free_count();</td> </tr> <tr> <td class="td_func"><div class="out" data-key="count_free" title=">;8G5AB2> A2>1>4=KE :;NG59">INT</div> <a href="#get_free_count9" name="get_free_count9">get_free_count</a> ( <div class="in" data-req="1" title="<O" data-key="name">VARCHAR</div><span>,</span> )</td> <td> A?><>30B5;L=0O DC=:F8O. >72@0I05B :>;8G5AB2> A2>1>4=KE :;NG59 4;O :>=:@5B=>3> 8<5=8. A?>;L7C5BAO A>2<5AB=> A generate_series. <div> <div class="title_exceptions">A:;NG5=8O</div> <table class="table_exceptions"> <tr> <td>;NG</td> <td>?8A0=85</td> </tr> <tr> <td><b>NOT FOUND</b></td> <td>5 =0945=></td> </tr> </table> </div> </td> <td style="width:35%">SELECT schema_keys.get_free_count( 'sessions_keys' );</td> </tr> </table> <h2 style="margin-top:50px">SQL</h2> <label><O AE5<K: <input value="schema_keys" class="schema_name" /> <pre> CREATE SCHEMA IF NOT EXISTS schema_keys; -- FUNCTIONS CREATE OR REPLACE FUNCTION schema_keys._get_array() RETURNS char[] AS $$ BEGIN RETURN ARRAY[ 'q', 'w', 'e', 'r', 't', 'y', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ]; END; $$ LANGUAGE plpgsql IMMUTABLE; CREATE OR REPLACE FUNCTION schema_keys._get_shuffle_array() RETURNS char[] AS $$ DECLARE str_arr char[] := schema_keys._get_array(); length_arr int := array_length( str_arr, 1 ); i int; random_position int; ret_str_arr char[]; BEGIN FOR i IN 1..length_arr LOOP random_position := (1 + (length_arr - 1) * random())::int; ret_str_arr := array_append( ret_str_arr, str_arr[random_position] ); str_arr := array_remove( str_arr, str_arr[random_position] ); length_arr := length_arr -1; END LOOP; RETURN ret_str_arr; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys._get_random_string( length int ) RETURNS varchar(255) AS $$ DECLARE ret_str varchar := ''; str_arr char[] := schema_keys._get_array(); length_arr int := array_length( str_arr, 1 ) - 1; i int; random_position int; BEGIN FOR i IN 1..length LOOP random_position := (1 + length_arr * random())::int; ret_str := ret_str || str_arr[random_position]; END LOOP; RETURN ret_str; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys._get_random_string( length int, str_arr char[], length_arr int ) RETURNS varchar(255) AS $$ DECLARE ret_str varchar := ''; i int; random_position int; BEGIN length_arr := length_arr - 1; FOR i IN 1..length LOOP random_position := (1 + length_arr * random())::int; ret_str := ret_str || str_arr[random_position]; END LOOP; RETURN ret_str; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys._generate_random_arr( prefix char, count int, length int ) RETURNS char[] AS $$ DECLARE ret_arr char[]; i int; random_str varchar(255); BEGIN FOR i in 1..count LOOP LOOP random_str := schema_keys._get_random_string( length ); random_str := prefix || random_str; IF array_position( ret_arr, random_str ) IS NULL THEN ret_arr := array_append( ret_arr, random_str ); EXIT; END IF; END LOOP; END LOOP; RETURN ret_arr; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys._gen_uniq_start_prefix() RETURNS varchar(5) AS $$ DECLARE ret_prefix varchar(5); search_row RECORD; BEGIN LOOP ret_prefix := schema_keys._get_random_string( 5 ); SELECT * INTO search_row FROM schema_keys._table_log WHERE start_prefix = ret_prefix; IF search_row IS NULL THEN EXIT; END IF; END LOOP; RETURN ret_prefix; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.add_name( name varchar ) RETURNS void AS $$ DECLARE start_prefix varchar(5) := schema_keys._gen_uniq_start_prefix(); arr_1 char[] := schema_keys._get_shuffle_array(); arr_2 char[] := schema_keys._get_shuffle_array(); arr_3 char[] := schema_keys._get_shuffle_array(); arr_4 char[] := schema_keys._get_shuffle_array(); arr_5 char[] := schema_keys._get_shuffle_array(); full_prefix varchar(10) := start_prefix || arr_1[1] || arr_2[1] || arr_3[1] || arr_4[1] || arr_5[1]; length_arr int := array_length( arr_1, 1 ); BEGIN INSERT INTO schema_keys._table_log( start_prefix, arr_1, arr_2, arr_3, arr_4, arr_5 ) VALUES ( start_prefix, arr_1, arr_2, arr_3, arr_4, arr_5 ); INSERT INTO schema_keys._table_settings( name, start_prefix, full_prefix ) VALUES ( name, start_prefix, full_prefix ); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.remove_name( p_name varchar ) RETURNS void AS $$ BEGIN IF p_name = 'default' THEN RAISE EXCEPTION 'RESERVE NAME'; END IF; DELETE FROM schema_keys._table_settings WHERE name = p_name; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.set_length( p_name varchar, p_length int ) RETURNS void AS $$ BEGIN UPDATE schema_keys._table_settings SET length = p_length WHERE name = p_name; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.set_length( p_length int ) RETURNS void AS $$ BEGIN PERFORM schema_keys.set_length( 'default', p_length ); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys._update_settings_prefix( p_name varchar(255), p_start_prefix varchar(5), p_c_1 int, p_c_2 int, p_c_3 int, p_c_4 int, p_c_5 int, p_c_max int ) RETURNS varchar(10) AS $$ DECLARE var_c_1 int := p_c_1; var_c_2 int := p_c_2; var_c_3 int := p_c_3; var_c_4 int := p_c_4; var_c_5 int := p_c_5; end_prefix varchar(5); new_prefix varchar(5); var_full_prefix varchar( 10 ); get_new_prefix boolean := false; search_log RECORD; BEGIN var_c_5 := var_c_5 + 1; IF var_c_5 &gt; p_c_max THEN var_c_5 := 1; var_c_4 := var_c_4 + 1; IF var_c_4 &gt; p_c_max THEN var_c_4 := 1; var_c_3 := var_c_3 + 1; IF var_c_3 &gt; p_c_max THEN var_c_3 := 1; var_c_2 := var_c_2 + 1; IF var_c_2 &gt; p_c_max THEN var_c_2 := 1; var_c_1 := var_c_1 + 1; IF var_c_1 &gt; p_c_max THEN var_c_1 := 1; get_new_prefix := true; END IF; END IF; END IF; END IF; END IF; SELECT * INTO search_log FROM schema_keys._table_log WHERE start_prefix = p_start_prefix; end_prefix = search_log.arr_1[var_c_1] || search_log.arr_2[var_c_2] || search_log.arr_3[var_c_3] || search_log.arr_4[var_c_4] || search_log.arr_5[var_c_5]; IF get_new_prefix THEN new_prefix := schema_keys._gen_uniq_start_prefix(); var_full_prefix := new_prefix || end_prefix; INSERT INTO schema_keys._table_log( start_prefix, arr_1, arr_2, arr_3, arr_4, arr_5 ) VALUES ( new_prefix, search_log.arr_1, search_log.arr_2, search_log.arr_3, search_log.arr_4, search_log.arr_5 ); ELSE var_full_prefix := p_start_prefix || end_prefix; END IF; UPDATE schema_keys._table_settings SET full_prefix = var_full_prefix, c_1 = var_c_1, c_2 = var_c_2, c_3 = var_c_3, c_4 = var_c_4, c_5 = var_c_5 WHERE name = p_name; RETURN var_full_prefix; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys._get_uniq_val( parent_id int, p_length int ) RETURNS varchar(255) AS $$ DECLARE ret_str varchar(255); search_row RECORD; BEGIN LOOP ret_str := schema_keys._get_random_string( p_length - 10 ); SELECT * INTO search_row FROM schema_keys._table_values WHERE value = ret_str AND pid = parent_id; IF search_row IS NULL THEN EXIT; END IF; END LOOP; RETURN ret_str; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.generate( p_name varchar ) RETURNS varchar(255) AS $$ DECLARE var_count int; search_row RECORD; full_prefix varchar(10); uniq_val varchar( 255 ); BEGIN SELECT * INTO search_row FROM schema_keys._table_settings WHERE name = p_name; IF search_row IS NULL THEN RAISE EXCEPTION 'NOT FOUND'; END IF; var_count := search_row.count + 1; IF var_count = 1000 THEN var_count := 0; full_prefix := schema_keys._update_settings_prefix( p_name, search_row.start_prefix, search_row.c_1, search_row.c_2, search_row.c_3, search_row.c_4, search_row.c_5, search_row.c_max ); DELETE FROM schema_keys._table_values WHERE pid = search_row.id; ELSE full_prefix := search_row.full_prefix; END IF; UPDATE schema_keys._table_settings SET count = var_count WHERE name = p_name; uniq_val = schema_keys._get_uniq_val( search_row.id, search_row.length ); INSERT INTO schema_keys._table_values( pid, value ) VALUES ( search_row.id, uniq_val ); RETURN full_prefix || uniq_val; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.generate_series( p_name varchar, p_count int ) RETURNS setof varchar(255) AS $$ DECLARE search_row RECORD; count_start int; full_prefix varchar; i int; i_string int; random_position int; start_record_i int; diff int; end_count int; length int; array_values varchar[]; random_string varchar; str_arr char[] := schema_keys._get_array(); length_arr int := array_length( str_arr, 1 ) - 1; BEGIN IF p_count &lt; 1 THEN RAISE EXCEPTION 'NOT VALID COUNT'; END IF; SELECT * INTO search_row FROM schema_keys._table_settings WHERE name = p_name; IF search_row IS NULL THEN RAISE EXCEPTION 'NOT FOUND'; END IF; SELECT array_agg( value ) INTO array_values FROM schema_keys._table_values WHERE pid = search_row.id; count_start := search_row.count; full_prefix := search_row.full_prefix; length := search_row.length - 10; IF search_row.count + p_count &lt; 1000 THEN start_record_i := 1; end_count := search_row.count; ELSE diff := 1000 - search_row.count; start_record_i := diff + floor((p_count-diff)/1000)*1000; end_count := p_count - start_record_i; DELETE FROM schema_keys._table_values WHERE pid = search_row.id; UPDATE schema_keys._table_settings SET count = end_count WHERE name = p_name; END IF; FOR i IN 1 .. p_count LOOP LOOP random_string := ''; FOR i_string IN 1..length LOOP random_position := (1 + length_arr * random())::int; random_string := random_string || str_arr[random_position]; END LOOP; IF array_position( array_values, random_string ) IS NULL THEN array_values := array_append( array_values, random_string ); EXIT; END IF; END LOOP; IF i &gt;= start_record_i THEN INSERT INTO schema_keys._table_values( pid, value ) VALUES ( search_row.id, random_string ); END IF; count_start := count_start + 1; IF count_start % 1000 = 0 THEN SELECT * INTO search_row FROM schema_keys._table_settings WHERE name = p_name; full_prefix := schema_keys._update_settings_prefix( p_name, search_row.start_prefix, search_row.c_1, search_row.c_2, search_row.c_3, search_row.c_4, search_row.c_5, search_row.c_max ); array_values := ARRAY[]::varchar[]; END IF; RETURN next full_prefix || random_string; END LOOP; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.generate_series( p_count int ) RETURNS setof varchar(255) AS $$ BEGIN RETURN QUERY SELECT schema_keys.generate_series( 'default', p_count ); END $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.get_free_count( p_name varchar ) RETURNS int AS $$ DECLARE search_row RECORD; BEGIN SELECT * INTO search_row FROM schema_keys._table_settings WHERE name = p_name; IF search_row IS NULL THEN RAISE EXCEPTION 'NOT FOUND'; END IF; RETURN 1000 - search_row.count; END $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.get_free_count() RETURNS int AS $$ BEGIN RETURN schema_keys.get_free_count( 'default' ); END $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION schema_keys.generate() RETURNS varchar(255) AS $$ BEGIN RETURN schema_keys.generate( 'default' ); END; $$ LANGUAGE plpgsql; -- TABLES CREATE TABLE schema_keys._table_settings ( id SERIAL PRIMARY KEY, name varchar(255) NOT NULL, start_prefix varchar(5) NOT NULL, full_prefix varchar(10) NOT NULL, c_1 INT NOT NULL DEFAULT 1, c_2 INT NOT NULL DEFAULT 1, c_3 INT NOT NULL DEFAULT 1, c_4 INT NOT NULL DEFAULT 1, c_5 INT NOT NULL DEFAULT 1, c_max INT NOT NULL DEFAULT array_length( schema_keys._get_array(), 1 ), length INT NOT NULL DEFAULT 15, count INT NOT NULL DEFAULT 0, CHECK ( c_1 &gt; 0 AND c_2 &gt; 0 AND c_2 &gt; 0 AND c_3 &gt; 0 AND c_4 &gt; 0 AND c_5 &gt; 0 ), CHECK ( c_1 &lt;= c_max AND c_2 &lt;= c_max AND c_2 &lt;= c_max AND c_3 &lt;= c_max AND c_4 &lt;= c_max AND c_5 &lt;= c_max ), CHECK( c_max &gt; 0 ), CHECK( count &gt;= 0 ), CHECK( length &gt;= 15 AND length &lt;= 255 ), CHECK( name ~ '^[a-zA-Z0-9_]{1,}$' AND start_prefix ~ '^[a-zA-Z0-9]{1,}$' AND full_prefix ~ '^[a-zA-Z0-9]{1,}$' ), UNIQUE( name ), UNIQUE( start_prefix ) ); CREATE TABLE schema_keys._table_log ( start_prefix varchar(5) NOT NULL, arr_1 char[] NOT NULL, arr_2 char[] NOT NULL, arr_3 char[] NOT NULL, arr_4 char[] NOT NULL, arr_5 char[] NOT NULL, CHECK( start_prefix ~ '^[a-zA-Z0-9]{1,}$' ), CHECK( arr_1 &amp;&amp; schema_keys._get_array() AND arr_2 &amp;&amp; arr_1 AND arr_3 &amp;&amp; arr_1 AND arr_4 &amp;&amp; arr_1 AND arr_5 &amp;&amp; arr_1 ), CHECK( array_length( arr_1, 1 ) = array_length( schema_keys._get_array(), 1 ) AND array_length( arr_2, 1 ) = array_length( arr_1, 1 ) AND array_length( arr_3, 1 ) = array_length( arr_1, 1 ) AND array_length( arr_4, 1 ) = array_length( arr_1, 1 ) AND array_length( arr_5, 1 ) = array_length( arr_1, 1 ) ), UNIQUE( start_prefix ) ); CREATE TABLE schema_keys._table_values ( pid INT REFERENCES schema_keys._table_settings( id ) ON DELETE CASCADE, value varchar( 245 ) NOT NULL, CHECK( value ~ '^[a-zA-Z0-9]{1,}$' ), UNIQUE ( pid, value ) ); SELECT schema_keys.add_name( 'default' ); </pre> <script defer> function init() { var name = $( '.schema_name' ).val(); var html = $( 'pre' ).text(); html = html.replace( new RegExp( name+'\\.', 'g' ), '<span>'+name+'</span>.' ); html = html.replace( new RegExp( name+';', 'g' ), '<span>'+name+'</span>;' ); $( 'pre' ).html( html ); $( '.schema_name' ).on( 'input', function() { if( $( this ).val() == '' ) { $( 'pre span' ).html( name ); } else { $( 'pre span' ).html( $( this ).val() ); } }); } init(); // http://jsfiddle.net/zAZyy/ ;-) jQuery.fn.selectText = function(){ var doc = document; var element = this[0]; if (doc.body.createTextRange) { var range = document.body.createTextRange(); range.moveToElementText(element); range.select(); } else if (window.getSelection) { var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(element); selection.removeAllRanges(); selection.addRange(range); } }; $( 'pre' ).on( 'click', function() { $( this ).selectText(); }); $( '[data-key]' ).on( 'mouseover', function() { var attr = $( this ).attr( 'data-key' ); if( attr != '' ) { $( '[data-key="'+attr+'"]' ).addClass( 'active_key' ); } }); $( '[data-key]' ).on( 'mouseout', function() { var attr = $( this ).attr( 'data-key' ); if( attr != '' ) { $( '[data-key="'+attr+'"]' ).removeClass( 'active_key' ); } }); $( '.title_exceptions' ).on( 'click', function() { if( $( this ).closest( 'tr' ).hasClass( 'exceptions_tr' ) ) { $( '.table_exceptions' ).hide(); $( '.exceptions_tr' ).removeClass( 'exceptions_tr' ); } else { $( '.table_exceptions' ).hide(); $( '.exceptions_tr' ).removeClass( 'exceptions_tr' ); $( this ).closest( 'td' ).find( '.table_exceptions' ).css( { display: 'table' } ); $( this ).closest( 'tr' ).addClass( 'exceptions_tr' ); } return false; }); $( '.table_exceptions' ).on( 'click', function() { return false; }); $( document ).on( 'click', function() { $( '.table_exceptions' ).hide(); $( '.exceptions_tr' ).removeClass( 'exceptions_tr' ); }); </script> </div> </body> </html>