-- Check whether any of our opclasses fail amvalidate SELECT amname, opcname FROM pg_opclass opc LEFTJOIN pg_am am ON am.oid = opcmethod WHERE opc.oid >= 16384ANDNOT amvalidate(opc.oid);
-- Test the operators and indexing functions
-- Test = and <>. SELECT'a'::citext = 'a'::citext AS t; SELECT'a'::citext = 'A'::citext AS t; SELECT'a'::citext = 'A'::text AS f; -- text wins the discussion SELECT'a'::citext = 'b'::citext AS f; SELECT'a'::citext = 'ab'::citext AS f; SELECT'a'::citext <> 'ab'::citext AS t;
-- Test > and >= SELECT'B'::citext > 'a'::citext AS t; SELECT'b'::citext > 'A'::citext AS t; SELECT'B'::citext > 'b'::citext AS f; SELECT'B'::citext >= 'b'::citext AS t;
-- Test < and <= SELECT'a'::citext < 'B'::citext AS t; SELECT'a'::citext <= 'B'::citext AS t;
-- Test implicit casting. citext casts to text, but not vice-versa. SELECT'a'::citext = 'a'::text AS t; SELECT'A'::text <> 'a'::citext AS t;
SELECT'B'::citext < 'a'::text AS t; -- text wins. SELECT'B'::citext <= 'a'::text AS t; -- text wins.
SELECT'a'::citext > 'B'::text AS t; -- text wins. SELECT'a'::citext >= 'B'::text AS t; -- text wins.
-- Test implicit casting. citext casts to varchar, but not vice-versa. SELECT'a'::citext = 'a'::varcharAS t; SELECT'A'::varchar <> 'a'::citext AS t;
-- A couple of longer examples to ensure that we don't get any issues with bad -- conversions to char[] in the c code. Yes, I did do this.
SELECT'aardvark'::citext = 'aardvark'::citext AS t; SELECT'aardvark'::citext = 'aardVark'::citext AS t;
-- Check the citext_cmp() function explicitly. SELECT citext_cmp('aardvark'::citext, 'aardvark'::citext) AS zero; SELECT citext_cmp('aardvark'::citext, 'aardVark'::citext) AS zero; SELECT citext_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero; SELECT citext_cmp('B'::citext, 'a'::citext) > 0AStrue;
-- Check the citext_hash() and citext_hash_extended() function explicitly. SELECT v as value, citext_hash(v)::bit(32) as standard,
citext_hash_extended(v, 0)::bit(32) as extended0,
citext_hash_extended(v, 1)::bit(32) as extended1 FROM (VALUES (NULL::citext), ('PostgreSQL'), ('eIpUEtqmY89'), ('AXKEJBTK'),
('muop28x03'), ('yi3nm0d73')) x(v) WHERE citext_hash(v)::bit(32) != citext_hash_extended(v, 0)::bit(32) OR citext_hash(v)::bit(32) = citext_hash_extended(v, 1)::bit(32);
SELECT name, 'a' = name AS eq_a FROM try WHERE name <> 'â'; SELECT name, 'a' = name AS t FROM try where name = 'a'; SELECT name, 'A' = name AS"eq_A"FROM try WHERE name <> 'â'; SELECT name, 'A' = name AS t FROM try where name = 'A'; SELECT name, 'A' = name AS t FROM try where name = 'A';
-- Check the min() and max() aggregates, with and without index. set enable_seqscan = off; SELECT MIN(name) AS"ABA"FROM srt; SELECT MAX(name) AS abd FROM srt;
reset enable_seqscan; set enable_indexscan = off; SELECT MIN(name) AS"ABA"FROM srt; SELECT MAX(name) AS abd FROM srt;
reset enable_indexscan;
-- Check sorting likewise set enable_seqscan = off; SELECT name FROM srt ORDERBY name;
reset enable_seqscan; set enable_indexscan = off; SELECT name FROM srt ORDERBY name;
reset enable_indexscan;
-- Test assignment casts. SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::text; SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::varchar; SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::bpchar; SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'; SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::citext;
-- LIKE should be case-insensitive SELECT name FROM srt WHERE name LIKE'%a%'ORDERBY name; SELECT name FROM srt WHERE name NOTLIKE'%b%'ORDERBY name; SELECT name FROM srt WHERE name LIKE'%A%'ORDERBY name; SELECT name FROM srt WHERE name NOTLIKE'%B%'ORDERBY name;
-- ~~ should be case-insensitive SELECT name FROM srt WHERE name ~~ '%a%'ORDERBY name; SELECT name FROM srt WHERE name !~~ '%b%'ORDERBY name; SELECT name FROM srt WHERE name ~~ '%A%'ORDERBY name; SELECT name FROM srt WHERE name !~~ '%B%'ORDERBY name;
-- ~ should be case-insensitive SELECT name FROM srt WHERE name ~ '^a'ORDERBY name; SELECT name FROM srt WHERE name !~ 'a$'ORDERBY name; SELECT name FROM srt WHERE name ~ '^A'ORDERBY name; SELECT name FROM srt WHERE name !~ 'A$'ORDERBY name;
-- SIMILAR TO should be case-insensitive. SELECT name FROM srt WHERE name SIMILAR TO'%a.*'; SELECT name FROM srt WHERE name SIMILAR TO'%A.*';
-- Table 9-5. SQL String Functions and Operators SELECT'D'::citext || 'avid'::citext = 'David'::citext AS citext_concat; SELECT'Value: '::citext || 42 = 'Value: 42'AS text_concat; SELECT42 || ': value'::citext ='42: value'AS int_concat; SELECT bit_length('jose'::citext) = 32AS t; SELECT bit_length( name ) = bit_length( name::text ) AS t FROM srt; SELECT textlen( name ) = textlen( name::text ) AS t FROM srt; SELECT char_length( name ) = char_length( name::text ) AS t FROM srt; SELECT lower( name ) = lower( name::text ) AS t FROM srt; SELECT octet_length( name ) = octet_length( name::text ) AS t FROM srt; SELECT overlay( name placing 'hom'from2for4) = overlay( name::text placing 'hom'from2for4) AS t FROM srt; SELECT position( 'a'IN name ) = position( 'a'IN name::text ) AS t FROM srt;
-- chr() takes an int and returns text. -- convert() and convert_from take bytea and return text.
SELECT convert_from( name::bytea, 'SQL_ASCII' ) = convert_from( name::text::bytea, 'SQL_ASCII' ) AS t FROM srt; SELECT decode('MTIzAAE='::citext, 'base64') = decode('MTIzAAE='::text, 'base64') AS t; -- encode() takes bytea and returns text. SELECT initcap('hi THOMAS'::citext) = initcap('hi THOMAS'::text) AS t; SELECT length( name ) = length( name::text ) AS t FROM srt;
-- pg_client_encoding() takes no args and returns name. SELECT quote_ident( name ) = quote_ident( name::text ) AS t FROM srt; SELECT quote_literal( name ) = quote_literal( name::text ) AS t FROM srt;
SELECT regexp_match('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t; SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t; SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t; SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t; SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t; SELECT regexp_match('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t; SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t; -- c forces case-sensitive SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS"no result"; -- g is not allowed SELECT regexp_match('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g') AS"error";
SELECT like_escape( name, '' ) = like_escape( name::text, '' ) AS t FROM srt; SELECT like_escape( name::text, ''::citext ) = like_escape( name::text, '' ) AS t FROM srt;
-- Ensure correct behavior for citext with materialized views. CREATETABLE citext_table (
id serial primarykey,
name citext
); INSERTINTO citext_table (name) VALUES ('one'), ('two'), ('three'), (NULL), (NULL); CREATE MATERIALIZED VIEW citext_matview AS SELECT * FROM citext_table; CREATEUNIQUEINDEX citext_matview_id ON citext_matview (id); SELECT * FROM citext_matview m
FULL JOIN citext_table t ON (t.id = m.id AND t *= m) WHERE t.id ISNULLOR m.id ISNULL; UPDATE citext_table SET name = 'Two'WHERE name = 'TWO'; SELECT * FROM citext_matview m
FULL JOIN citext_table t ON (t.id = m.id AND t *= m) WHERE t.id ISNULLOR m.id ISNULL;
REFRESH MATERIALIZED VIEW CONCURRENTLY citext_matview; SELECT * FROM citext_matview ORDERBY id;
-- test citext_pattern_cmp() function explicitly. SELECT citext_pattern_cmp('aardvark'::citext, 'aardvark'::citext) AS zero; SELECT citext_pattern_cmp('aardvark'::citext, 'aardVark'::citext) AS zero; SELECT citext_pattern_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero; SELECT citext_pattern_cmp('B'::citext, 'a'::citext) > 0AStrue; SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0AStrue; SELECT citext_pattern_cmp('A'::citext, 'b'::citext) < 0AStrue; SELECT citext_pattern_cmp('ABCD'::citext, 'abc'::citext) > 0AStrue; SELECT citext_pattern_cmp('ABC'::citext, 'abcd'::citext) < 0AStrue;
-- Test ~<~ and ~<=~ SELECT'a'::citext ~<~ 'B'::citext AS t; SELECT'b'::citext ~<~ 'A'::citext AS f; SELECT'a'::citext ~<=~ 'B'::citext AS t; SELECT'a'::citext ~<=~ 'A'::citext AS t;
-- Test ~>~ and ~>=~ SELECT'B'::citext ~>~ 'a'::citext AS t; SELECT'b'::citext ~>~ 'A'::citext AS t; SELECT'B'::citext ~>~ 'b'::citext AS f; SELECT'B'::citext ~>=~ 'b'::citext AS t;
-- Test implicit casting. citext casts to text, but not vice-versa. SELECT'B'::citext ~<~ 'a'::text AS t; -- text wins. SELECT'B'::citext ~<=~ 'a'::text AS t; -- text wins.
SELECT'a'::citext ~>~ 'B'::text AS t; -- text wins. SELECT'a'::citext ~>=~ 'B'::text AS t; -- text wins.
-- Test implicit casting. citext casts to varchar, but not vice-versa. SELECT'B'::citext ~<~ 'a'::varcharAS t; -- varchar wins. SELECT'B'::citext ~<=~ 'a'::varcharAS t; -- varchar wins.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.