-- Test citext datatype
--
---
--- first, define the datatype. Turn off echoing so that expected file
--- does not depend on contents of citext.sql.
---
-SET client_min_messages = warning;
-\set ECHO none
-\i citext.sql
-RESET client_min_messages;
-\set ECHO all
+CREATE EXTENSION citext;
-- Test the operators and indexing functions
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) AS one;
+SELECT citext_cmp('B'::citext, 'a'::citext) > 0 AS true;
-- Do some tests using a table and index.
('ABC'),
('abd');
+CREATE INDEX srt_name ON srt (name);
+
-- Check the min() and max() aggregates, with and without index.
set enable_seqscan = off;
SELECT MIN(name) AS "AAA" FROM srt;
SELECT 'foo'::name::citext = 'foo' AS t;
SELECT 'foo'::citext::name = 'foo'::name AS t;
-SELECT 'foo'::bytea::citext = 'foo' AS t;
-SELECT 'foo'::citext::bytea = 'foo'::bytea AS t;
+SELECT 'f'::char::citext = 'f' AS t;
+SELECT 'f'::citext::char = 'f'::char AS t;
+
+SELECT 'f'::"char"::citext = 'f' AS t;
+SELECT 'f'::citext::"char" = 'f'::"char" AS t;
SELECT '100'::money::citext = '$100.00' AS t;
SELECT '100'::citext::money = '100'::money AS t;
SELECT '08:00:2b:01:02:03'::macaddr::citext = '08:00:2b:01:02:03' AS t;
SELECT '08:00:2b:01:02:03'::citext::macaddr = '08:00:2b:01:02:03'::macaddr AS t;
-SELECT '<p>foo</p>'::xml::citext = '<p>foo</p>' AS t;
-SELECT '<p>foo</p>'::citext::xml::text = '<p>foo</p>'::xml::text AS t;
-
SELECT '1999-01-08 04:05:06'::timestamp::citext = '1999-01-08 04:05:06'::timestamp::text AS t;
SELECT '1999-01-08 04:05:06'::citext::timestamp = '1999-01-08 04:05:06'::timestamp AS t;
SELECT '1999-01-08 04:05:06'::timestamptz::citext = '1999-01-08 04:05:06'::timestamptz::text AS t;
text text,
varchar varchar,
bpchar bpchar,
- name name,
+ char char,
+ chr "char",
+ name name,
bytea bytea,
boolean boolean,
float4 float4,
int8 int8,
int4 int4,
int2 int2,
- cidr cidr,
+ cidr cidr,
inet inet,
macaddr macaddr,
- xml xml,
money money,
timestamp timestamp,
timestamptz timestamptz,
INSERT INTO caster (bpchar) VALUES ('foo'::citext);
INSERT INTO caster (citext) VALUES ('foo'::bpchar);
+INSERT INTO caster (char) VALUES ('f'::text);
+INSERT INTO caster (text) VALUES ('f'::char);
+INSERT INTO caster (char) VALUES ('f'::citext);
+INSERT INTO caster (citext) VALUES ('f'::char);
+
+INSERT INTO caster (chr) VALUES ('f'::text);
+INSERT INTO caster (text) VALUES ('f'::"char");
+INSERT INTO caster (chr) VALUES ('f'::citext);
+INSERT INTO caster (citext) VALUES ('f'::"char");
+
INSERT INTO caster (name) VALUES ('foo'::text);
INSERT INTO caster (text) VALUES ('foo'::name);
INSERT INTO caster (name) VALUES ('foo'::citext);
INSERT INTO caster (macaddr) VALUES ('08:00:2b:01:02:03'::citext);
INSERT INTO caster (citext) VALUES ('08:00:2b:01:02:03'::macaddr);
--- Cannot cast to xml on assignment.
-INSERT INTO caster (xml) VALUES ('<p>foo</p>'::text);
-INSERT INTO caster (text) VALUES ('<p>foo</p>'::xml);
-INSERT INTO caster (xml) VALUES ('<p>foo</p>'::citext);
-INSERT INTO caster (citext) VALUES ('<p>foo</p>'::xml);
-
-- Cannot cast to money on assignment.
INSERT INTO caster (money) VALUES ('12'::text);
INSERT INTO caster (text) VALUES ('12'::money);
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.
+CREATE TABLE citext_table (
+ id serial primary key,
+ name citext
+);
+INSERT INTO citext_table (name)
+ VALUES ('one'), ('two'), ('three'), (NULL), (NULL);
+CREATE MATERIALIZED VIEW citext_matview AS
+ SELECT * FROM citext_table;
+CREATE UNIQUE INDEX 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 IS NULL OR m.id IS NULL;
+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 IS NULL OR m.id IS NULL;
+REFRESH MATERIALIZED VIEW CONCURRENTLY citext_matview;
+SELECT * FROM citext_matview ORDER BY id;