Commit f54668d6 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Match results with format from new psql.

All of these tests have been completely inspected and give correct results.
parent 3ec826f9
QUERY: SELECT 1 AS one;
one
---
1
--
-- BOOLEAN
--
--
-- sanity check - if this fails go insane!
--
SELECT 1 AS one;
one
-----
1
(1 row)
QUERY: SELECT 't'::bool AS true;
true
----
t
-- ******************testing built-in type bool********************
-- check bool type-casting as well as and, or, not in qualifications--
SELECT bool 't' AS true;
true
------
t
(1 row)
QUERY: SELECT 'f'::bool AS false;
false
-----
f
SELECT bool 'f' AS false;
false
-------
f
(1 row)
QUERY: SELECT 't'::bool or 'f'::bool AS true;
true
----
t
SELECT bool 't' or bool 'f' AS true;
true
------
t
(1 row)
QUERY: SELECT 't'::bool and 'f'::bool AS false;
false
-----
f
SELECT bool 't' and bool 'f' AS false;
false
-------
f
(1 row)
QUERY: SELECT not 'f'::bool AS true;
true
----
t
SELECT not bool 'f' AS true;
true
------
t
(1 row)
QUERY: SELECT 't'::bool = 'f'::bool AS false;
false
-----
f
SELECT bool 't' = bool 'f' AS false;
false
-------
f
(1 row)
QUERY: SELECT 't'::bool <> 'f'::bool AS true;
true
----
t
SELECT bool 't' <> bool 'f' AS true;
true
------
t
(1 row)
QUERY: CREATE TABLE BOOLTBL1 (f1 bool);
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('t'::bool);
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('True'::bool);
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('true'::bool);
QUERY: SELECT '' AS t_3, BOOLTBL1.*;
t_3|f1
---+--
|t
|t
|t
CREATE TABLE BOOLTBL1 (f1 bool);
INSERT INTO BOOLTBL1 (f1) VALUES (bool 't');
INSERT INTO BOOLTBL1 (f1) VALUES (bool 'True');
INSERT INTO BOOLTBL1 (f1) VALUES (bool 'true');
-- BOOLTBL1 should be full of true's at this point
SELECT '' AS t_3, BOOLTBL1.*;
t_3 | f1
-----+----
| t
| t
| t
(3 rows)
QUERY: SELECT '' AS t_3, BOOLTBL1.*
SELECT '' AS t_3, BOOLTBL1.*
FROM BOOLTBL1
WHERE f1 = 'true'::bool;
t_3|f1
---+--
|t
|t
|t
WHERE f1 = bool 'true';
t_3 | f1
-----+----
| t
| t
| t
(3 rows)
QUERY: SELECT '' AS t_3, BOOLTBL1.*
SELECT '' AS t_3, BOOLTBL1.*
FROM BOOLTBL1
WHERE f1 <> 'false'::bool;
t_3|f1
---+--
|t
|t
|t
WHERE f1 <> bool 'false';
t_3 | f1
-----+----
| t
| t
| t
(3 rows)
QUERY: SELECT '' AS zero, BOOLTBL1.*
SELECT '' AS zero, BOOLTBL1.*
FROM BOOLTBL1
WHERE booleq('false'::bool, f1);
zero|f1
----+--
WHERE booleq(bool 'false', f1);
zero | f1
------+----
(0 rows)
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('f'::bool);
QUERY: SELECT '' AS f_1, BOOLTBL1.*
INSERT INTO BOOLTBL1 (f1) VALUES (bool 'f');
SELECT '' AS f_1, BOOLTBL1.*
FROM BOOLTBL1
WHERE f1 = 'false'::bool;
f_1|f1
---+--
|f
WHERE f1 = bool 'false';
f_1 | f1
-----+----
| f
(1 row)
QUERY: CREATE TABLE BOOLTBL2 (f1 bool);
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('f'::bool);
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('false'::bool);
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('False'::bool);
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('FALSE'::bool);
QUERY: INSERT INTO BOOLTBL2 (f1)
VALUES ('XXX'::bool);
CREATE TABLE BOOLTBL2 (f1 bool);
INSERT INTO BOOLTBL2 (f1) VALUES (bool 'f');
INSERT INTO BOOLTBL2 (f1) VALUES (bool 'false');
INSERT INTO BOOLTBL2 (f1) VALUES (bool 'False');
INSERT INTO BOOLTBL2 (f1) VALUES (bool 'FALSE');
-- This is now an invalid expression
-- For pre-v6.3 this evaluated to false - thomas 1997-10-23
INSERT INTO BOOLTBL2 (f1)
VALUES (bool 'XXX');
ERROR: Bad boolean external representation 'XXX'
QUERY: SELECT '' AS f_4, BOOLTBL2.*;
f_4|f1
---+--
|f
|f
|f
|f
-- BOOLTBL2 should be full of false's at this point
SELECT '' AS f_4, BOOLTBL2.*;
f_4 | f1
-----+----
| f
| f
| f
| f
(4 rows)
QUERY: SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 <> BOOLTBL1.f1;
tf_12|f1|f1
-----+--+--
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
tf_12 | f1 | f1
-------+----+----
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
(12 rows)
QUERY: SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
WHERE boolne(BOOLTBL2.f1,BOOLTBL1.f1);
tf_12|f1|f1
-----+--+--
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
tf_12 | f1 | f1
-------+----+----
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
(12 rows)
QUERY: SELECT '' AS ff_4, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 = BOOLTBL1.f1 and BOOLTBL1.f1 = 'false'::bool;
ff_4|f1|f1
----+--+--
|f |f
|f |f
|f |f
|f |f
SELECT '' AS ff_4, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 = BOOLTBL1.f1 and BOOLTBL1.f1 = bool 'false';
ff_4 | f1 | f1
------+----+----
| f | f
| f | f
| f | f
| f | f
(4 rows)
QUERY: SELECT '' AS tf_12_ff_4, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 = BOOLTBL1.f1 or BOOLTBL1.f1 = 'true'::bool
SELECT '' AS tf_12_ff_4, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 = BOOLTBL1.f1 or BOOLTBL1.f1 = bool 'true'
ORDER BY BOOLTBL1.f1, BOOLTBL2.f1;
tf_12_ff_4|f1|f1
----------+--+--
|f |f
|f |f
|f |f
|f |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
|t |f
tf_12_ff_4 | f1 | f1
------------+----+----
| f | f
| f | f
| f | f
| f | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
| t | f
(16 rows)
QUERY: SELECT '' AS "True", BOOLTBL1.*
--
-- SQL92 syntax
-- Try all combinations to ensure that we get nothing when we expect nothing
-- - thomas 2000-01-04
--
SELECT '' AS "True", f1
FROM BOOLTBL1
WHERE f1 IS TRUE;
True|f1
----+--
|t
|t
|t
True | f1
------+----
| t
| t
| t
(3 rows)
QUERY: SELECT '' AS "Not False", BOOLTBL1.*
SELECT '' AS "Not False", f1
FROM BOOLTBL1
WHERE f1 IS NOT FALSE;
Not False|f1
---------+--
|t
|t
|t
Not False | f1
-----------+----
| t
| t
| t
(3 rows)
QUERY: SELECT '' AS "False", BOOLTBL1.*
SELECT '' AS "False", f1
FROM BOOLTBL1
WHERE f1 IS FALSE;
False|f1
-----+--
|f
False | f1
-------+----
| f
(1 row)
QUERY: SELECT '' AS "Not True", BOOLTBL1.*
SELECT '' AS "Not True", f1
FROM BOOLTBL1
WHERE f1 IS NOT TRUE;
Not True|f1
--------+--
|f
Not True | f1
----------+----
| f
(1 row)
QUERY: DROP TABLE BOOLTBL1;
QUERY: DROP TABLE BOOLTBL2;
SELECT '' AS "True", f1
FROM BOOLTBL2
WHERE f1 IS TRUE;
True | f1
------+----
(0 rows)
SELECT '' AS "Not False", f1
FROM BOOLTBL2
WHERE f1 IS NOT FALSE;
Not False | f1
-----------+----
(0 rows)
SELECT '' AS "False", f1
FROM BOOLTBL2
WHERE f1 IS FALSE;
False | f1
-------+----
| f
| f
| f
| f
(4 rows)
SELECT '' AS "Not True", f1
FROM BOOLTBL2
WHERE f1 IS NOT TRUE;
Not True | f1
----------+----
| f
| f
| f
| f
(4 rows)
--
-- Clean up
-- Many tables are retained by the regression test, but these do not seem
-- particularly useful so just get rid of them for now.
-- - thomas 1997-11-30
--
DROP TABLE BOOLTBL1;
DROP TABLE BOOLTBL2;
QUERY: SELECT 'c'::char = 'c'::char AS true;
true
----
t
--
-- CHAR
-- all inputs are SILENTLY truncated at 1 character
--
-- fixed-length by value
-- internally passed by value if <= 4 bytes in storage
SELECT char 'c' = char 'c' AS true;
true
------
t
(1 row)
QUERY: CREATE TABLE CHAR_TBL(f1 char);
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('a');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('A');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('1');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES (2);
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('3');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('cd');
QUERY: SELECT '' AS seven, CHAR_TBL.*;
seven|f1
-----+--
|a
|A
|1
|2
|3
|
|c
--
-- Build a table for testing
--
CREATE TABLE CHAR_TBL(f1 char);
INSERT INTO CHAR_TBL (f1) VALUES ('a');
INSERT INTO CHAR_TBL (f1) VALUES ('A');
-- any of the following three input formats are acceptable
INSERT INTO CHAR_TBL (f1) VALUES ('1');
INSERT INTO CHAR_TBL (f1) VALUES (2);
INSERT INTO CHAR_TBL (f1) VALUES ('3');
-- zero-length char
INSERT INTO CHAR_TBL (f1) VALUES ('');
-- try char's of greater than 1 length
INSERT INTO CHAR_TBL (f1) VALUES ('cd');
SELECT '' AS seven, CHAR_TBL.*;
seven | f1
-------+----
| a
| A
| 1
| 2
| 3
|
| c
(7 rows)
QUERY: SELECT '' AS six, c.*
SELECT '' AS six, c.*
FROM CHAR_TBL c
WHERE c.f1 <> 'a';
six|f1
---+--
|A
|1
|2
|3
|
|c
six | f1
-----+----
| A
| 1
| 2
| 3
|
| c
(6 rows)
QUERY: SELECT '' AS one, c.*
SELECT '' AS one, c.*
FROM CHAR_TBL c
WHERE c.f1 = 'a';
one|f1
---+--
|a
one | f1
-----+----
| a
(1 row)
QUERY: SELECT '' AS five, c.*
SELECT '' AS five, c.*
FROM CHAR_TBL c
WHERE c.f1 < 'a';
five|f1
----+--
|A
|1
|2
|3
|
five | f1
------+----
| A
| 1
| 2
| 3
|
(5 rows)
QUERY: SELECT '' AS six, c.*
SELECT '' AS six, c.*
FROM CHAR_TBL c
WHERE c.f1 <= 'a';
six|f1
---+--
|a
|A
|1
|2
|3
|
six | f1
-----+----
| a
| A
| 1
| 2
| 3
|
(6 rows)
QUERY: SELECT '' AS one, c.*
SELECT '' AS one, c.*
FROM CHAR_TBL c
WHERE c.f1 > 'a';
one|f1
---+--
|c
one | f1
-----+----
| c
(1 row)
QUERY: SELECT '' AS two, c.*
SELECT '' AS two, c.*
FROM CHAR_TBL c
WHERE c.f1 >= 'a';
two|f1
---+--
|a
|c
two | f1
-----+----
| a
| c
(2 rows)
QUERY: DROP TABLE CHAR_TBL;
QUERY: CREATE TABLE CHAR_TBL(f1 char(4));
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('a');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('ab');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('abcd');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('abcde');
QUERY: SELECT '' AS four, CHAR_TBL.*;
four|f1
----+----
|a
|ab
|abcd
|abcd
DROP TABLE CHAR_TBL;
--
-- Now test longer arrays of char
--
CREATE TABLE CHAR_TBL(f1 char(4));
INSERT INTO CHAR_TBL (f1) VALUES ('a');
INSERT INTO CHAR_TBL (f1) VALUES ('ab');
INSERT INTO CHAR_TBL (f1) VALUES ('abcd');
INSERT INTO CHAR_TBL (f1) VALUES ('abcde');
SELECT '' AS four, CHAR_TBL.*;
four | f1
------+------
| a
| ab
| abcd
| abcd
(4 rows)
QUERY: CREATE TABLE FLOAT4_TBL (f1 float4);
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('0.0');
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('1004.30');
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('-34.84');
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40');
--
-- FLOAT4
--
CREATE TABLE FLOAT4_TBL (f1 float4);
INSERT INTO FLOAT4_TBL(f1) VALUES ('0.0');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1004.30');
INSERT INTO FLOAT4_TBL(f1) VALUES ('-34.84');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40');
ERROR: Bad float4 input format -- overflow
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40');
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40');
ERROR: Bad float4 input format -- overflow
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
ERROR: Bad float4 input format -- underflow
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
ERROR: Bad float4 input format -- underflow
QUERY: SELECT '' AS five, FLOAT4_TBL.*;
five|f1
----+-----------
|0
|1004.3
|-34.84
|1.23457e+20
|1.23457e-20
SELECT '' AS five, FLOAT4_TBL.*;
five | f1
------+-------------
| 0
| 1004.3
| -34.84
| 1.23457e+20
| 1.23457e-20
(5 rows)
QUERY: SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <> '1004.3';
four|f1
----+-----------
|0
|-34.84
|1.23457e+20
|1.23457e-20
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <> '1004.3';
four | f1
------+-------------
| 0
| -34.84
| 1.23457e+20
| 1.23457e-20
(4 rows)
QUERY: SELECT '' AS one, f.* FROM FLOAT4_TBL f WHERE f.f1 = '1004.3';
one| f1
---+------
|1004.3
SELECT '' AS one, f.* FROM FLOAT4_TBL f WHERE f.f1 = '1004.3';
one | f1
-----+--------
| 1004.3
(1 row)
QUERY: SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE '1004.3' > f.f1;
three| f1
-----+-----------
| 0
| -34.84
|1.23457e-20
SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE '1004.3' > f.f1;
three | f1
-------+-------------
| 0
| -34.84
| 1.23457e-20
(3 rows)
QUERY: SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE f.f1 < '1004.3';
three| f1
-----+-----------
| 0
| -34.84
|1.23457e-20
SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE f.f1 < '1004.3';
three | f1
-------+-------------
| 0
| -34.84
| 1.23457e-20
(3 rows)
QUERY: SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1;
four| f1
----+-----------
| 0
| 1004.3
| -34.84
|1.23457e-20
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1;
four | f1
------+-------------
| 0
| 1004.3
| -34.84
| 1.23457e-20
(4 rows)
QUERY: SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <= '1004.3';
four| f1
----+-----------
| 0
| 1004.3
| -34.84
|1.23457e-20
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <= '1004.3';
four | f1
------+-------------
| 0
| 1004.3
| -34.84
| 1.23457e-20
(4 rows)
QUERY: SELECT '' AS three, f.f1, f.f1 * '-10' AS x FROM FLOAT4_TBL f
SELECT '' AS three, f.f1, f.f1 * '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three|f1 |x
-----+-----------+------------
|1004.3 |-10043
|1.23457e+20|-1.23457e+21
|1.23457e-20|-1.23457e-19
three | f1 | x
-------+-------------+--------------
| 1004.3 | -10043
| 1.23457e+20 | -1.23457e+21
| 1.23457e-20 | -1.23457e-19
(3 rows)
QUERY: SELECT '' AS three, f.f1, f.f1 + '-10' AS x FROM FLOAT4_TBL f
SELECT '' AS three, f.f1, f.f1 + '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three|f1 |x
-----+-----------+-----------
|1004.3 |994.3
|1.23457e+20|1.23457e+20
|1.23457e-20|-10
three | f1 | x
-------+-------------+-------------
| 1004.3 | 994.3
| 1.23457e+20 | 1.23457e+20
| 1.23457e-20 | -10
(3 rows)
QUERY: SELECT '' AS three, f.f1, f.f1 / '-10' AS x FROM FLOAT4_TBL f
SELECT '' AS three, f.f1, f.f1 / '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three|f1 |x
-----+-----------+------------
|1004.3 |-100.43
|1.23457e+20|-1.23457e+19
|1.23457e-20|-1.23457e-21
three | f1 | x
-------+-------------+--------------
| 1004.3 | -100.43
| 1.23457e+20 | -1.23457e+19
| 1.23457e-20 | -1.23457e-21
(3 rows)
QUERY: SELECT '' AS three, f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f
SELECT '' AS three, f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three|f1 |x
-----+-----------+-----------
|1004.3 |1014.3
|1.23457e+20|1.23457e+20
|1.23457e-20|10
three | f1 | x
-------+-------------+-------------
| 1004.3 | 1014.3
| 1.23457e+20 | 1.23457e+20
| 1.23457e-20 | 10
(3 rows)
QUERY: SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f;
-- test divide by zero
SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f;
ERROR: float4div: divide by zero error
QUERY: SELECT '' AS five, FLOAT4_TBL.*;
five|f1
----+-----------
|0
|1004.3
|-34.84
|1.23457e+20
|1.23457e-20
SELECT '' AS five, FLOAT4_TBL.*;
five | f1
------+-------------
| 0
| 1004.3
| -34.84
| 1.23457e+20
| 1.23457e-20
(5 rows)
QUERY: SELECT '' AS five, f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
five|f1 |abs_f1
----+-----------+-----------
|0 |0
|1004.3 |1004.3
|-34.84 |34.84
|1.23457e+20|1.23457e+20
|1.23457e-20|1.23457e-20
-- test the unary float4abs operator
SELECT '' AS five, f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
five | f1 | abs_f1
------+-------------+-------------
| 0 | 0
| 1004.3 | 1004.3
| -34.84 | 34.84
| 1.23457e+20 | 1.23457e+20
| 1.23457e-20 | 1.23457e-20
(5 rows)
QUERY: UPDATE FLOAT4_TBL
UPDATE FLOAT4_TBL
SET f1 = FLOAT4_TBL.f1 * '-1'
WHERE FLOAT4_TBL.f1 > '0.0';
QUERY: SELECT '' AS five, FLOAT4_TBL.*;
five|f1
----+------------
|0
|-34.84
|-1004.3
|-1.23457e+20
|-1.23457e-20
SELECT '' AS five, FLOAT4_TBL.*;
five | f1
------+--------------
| 0
| -34.84
| -1004.3
| -1.23457e+20
| -1.23457e-20
(5 rows)
This diff is collapsed.
QUERY: CREATE TABLE INT2_TBL(f1 int2);
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('0');
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('1234');
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('-1234');
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('34.5');
--
-- INT2
-- NOTE: int2 operators never check for over/underflow!
-- Some of these answers are consequently numerically incorrect.
--
CREATE TABLE INT2_TBL(f1 int2);
INSERT INTO INT2_TBL(f1) VALUES ('0');
INSERT INTO INT2_TBL(f1) VALUES ('1234');
INSERT INTO INT2_TBL(f1) VALUES ('-1234');
INSERT INTO INT2_TBL(f1) VALUES ('34.5');
ERROR: pg_atoi: error in "34.5": can't parse ".5"
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('32767');
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('-32767');
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('100000');
-- largest and smallest values
INSERT INTO INT2_TBL(f1) VALUES ('32767');
INSERT INTO INT2_TBL(f1) VALUES ('-32767');
-- bad input values -- should give warnings
INSERT INTO INT2_TBL(f1) VALUES ('100000');
ERROR: pg_atoi: error reading "100000": Numerical result out of range
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('asdf');
INSERT INTO INT2_TBL(f1) VALUES ('asdf');
ERROR: pg_atoi: error in "asdf": can't parse "asdf"
QUERY: SELECT '' AS five, INT2_TBL.*;
five| f1
----+------
| 0
| 1234
| -1234
| 32767
|-32767
SELECT '' AS five, INT2_TBL.*;
five | f1
------+--------
| 0
| 1234
| -1234
| 32767
| -32767
(5 rows)
QUERY: SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> '0'::int2;
four| f1
----+------
| 1234
| -1234
| 32767
|-32767
SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int2 '0';
four | f1
------+--------
| 1234
| -1234
| 32767
| -32767
(4 rows)
QUERY: SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> '0'::int4;
four| f1
----+------
| 1234
| -1234
| 32767
|-32767
SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int4 '0';
four | f1
------+--------
| 1234
| -1234
| 32767
| -32767
(4 rows)
QUERY: SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = '0'::int2;
one|f1
---+--
| 0
SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int2 '0';
one | f1
-----+----
| 0
(1 row)
QUERY: SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = '0'::int4;
one|f1
---+--
| 0
SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int4 '0';
one | f1
-----+----
| 0
(1 row)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < '0'::int2;
two| f1
---+------
| -1234
|-32767
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int2 '0';
two | f1
-----+--------
| -1234
| -32767
(2 rows)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < '0'::int4;
two| f1
---+------
| -1234
|-32767
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int4 '0';
two | f1
-----+--------
| -1234
| -32767
(2 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= '0'::int2;
three| f1
-----+------
| 0
| -1234
|-32767
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int2 '0';
three | f1
-------+--------
| 0
| -1234
| -32767
(3 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= '0'::int4;
three| f1
-----+------
| 0
| -1234
|-32767
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int4 '0';
three | f1
-------+--------
| 0
| -1234
| -32767
(3 rows)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > '0'::int2;
two| f1
---+-----
| 1234
|32767
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int2 '0';
two | f1
-----+-------
| 1234
| 32767
(2 rows)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > '0'::int4;
two| f1
---+-----
| 1234
|32767
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int4 '0';
two | f1
-----+-------
| 1234
| 32767
(2 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= '0'::int2;
three| f1
-----+-----
| 0
| 1234
|32767
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int2 '0';
three | f1
-------+-------
| 0
| 1234
| 32767
(3 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= '0'::int4;
three| f1
-----+-----
| 0
| 1234
|32767
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int4 '0';
three | f1
-------+-------
| 0
| 1234
| 32767
(3 rows)
QUERY: SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % '2'::int2) = '1'::int2;
one| f1
---+-----
|32767
-- positive odds
SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
one | f1
-----+-------
| 32767
(1 row)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % '2'::int4) = '0'::int2;
three| f1
-----+-----
| 0
| 1234
|-1234
-- any evens
SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
three | f1
-------+-------
| 0
| 1234
| -1234
(3 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 * '2'::int2 AS x FROM INT2_TBL i;
five| f1| x
----+------+-----
| 0| 0
| 1234| 2468
| -1234|-2468
| 32767| -2
|-32767| 2
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+-------
| 0 | 0
| 1234 | 2468
| -1234 | -2468
| 32767 | -2
| -32767 | 2
(5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 * '2'::int4 AS x FROM INT2_TBL i;
five| f1| x
----+------+------
| 0| 0
| 1234| 2468
| -1234| -2468
| 32767| 65534
|-32767|-65534
SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+--------
| 0 | 0
| 1234 | 2468
| -1234 | -2468
| 32767 | 65534
| -32767 | -65534
(5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 + '2'::int2 AS x FROM INT2_TBL i;
five| f1| x
----+------+------
| 0| 2
| 1234| 1236
| -1234| -1232
| 32767|-32767
|-32767|-32765
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+--------
| 0 | 2
| 1234 | 1236
| -1234 | -1232
| 32767 | -32767
| -32767 | -32765
(5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 + '2'::int4 AS x FROM INT2_TBL i;
five| f1| x
----+------+------
| 0| 2
| 1234| 1236
| -1234| -1232
| 32767| 32769
|-32767|-32765
SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+--------
| 0 | 2
| 1234 | 1236
| -1234 | -1232
| 32767 | 32769
| -32767 | -32765
(5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 - '2'::int2 AS x FROM INT2_TBL i;
five| f1| x
----+------+-----
| 0| -2
| 1234| 1232
| -1234|-1236
| 32767|32765
|-32767|32767
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+-------
| 0 | -2
| 1234 | 1232
| -1234 | -1236
| 32767 | 32765
| -32767 | 32767
(5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 - '2'::int4 AS x FROM INT2_TBL i;
five| f1| x
----+------+------
| 0| -2
| 1234| 1232
| -1234| -1236
| 32767| 32765
|-32767|-32769
SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+--------
| 0 | -2
| 1234 | 1232
| -1234 | -1236
| 32767 | 32765
| -32767 | -32769
(5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 / '2'::int2 AS x FROM INT2_TBL i;
five| f1| x
----+------+------
| 0| 0
| 1234| 617
| -1234| -617
| 32767| 16383
|-32767|-16383
SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+--------
| 0 | 0
| 1234 | 617
| -1234 | -617
| 32767 | 16383
| -32767 | -16383
(5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 / '2'::int4 AS x FROM INT2_TBL i;
five| f1| x
----+------+------
| 0| 0
| 1234| 617
| -1234| -617
| 32767| 16383
|-32767|-16383
SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
five | f1 | x
------+--------+--------
| 0 | 0
| 1234 | 617
| -1234 | -617
| 32767 | 16383
| -32767 | -16383
(5 rows)
This diff is collapsed.
QUERY: CREATE TABLE INT8_TBL(q1 int8, q2 int8);
QUERY: INSERT INTO INT8_TBL VALUES('123','456');
QUERY: INSERT INTO INT8_TBL VALUES('123','4567890123456789');
QUERY: INSERT INTO INT8_TBL VALUES('4567890123456789','123');
QUERY: INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789');
QUERY: INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789');
QUERY: SELECT * FROM INT8_TBL;
q1| q2
----------------+-----------------
123| 456
123| 4567890123456789
4567890123456789| 123
4567890123456789| 4567890123456789
4567890123456789|-4567890123456789
--
-- INT8
-- Test int8 64-bit integers.
--
CREATE TABLE INT8_TBL(q1 int8, q2 int8);
INSERT INTO INT8_TBL VALUES('123','456');
INSERT INTO INT8_TBL VALUES('123','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','123');
INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789');
SELECT * FROM INT8_TBL;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
QUERY: SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
five| plus| minus
----+----------------+-----------------
| 123| -123
| 123| -123
|4567890123456789|-4567890123456789
|4567890123456789|-4567890123456789
|4567890123456789|-4567890123456789
SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
five | plus | minus
------+------------------+-------------------
| 123 | -123
| 123 | -123
| 4567890123456789 | -4567890123456789
| 4567890123456789 | -4567890123456789
| 4567890123456789 | -4567890123456789
(5 rows)
QUERY: SELECT '' AS five, q1, q2, q1 + q2 AS plus FROM INT8_TBL;
five| q1| q2| plus
----+----------------+-----------------+----------------
| 123| 456| 579
| 123| 4567890123456789|4567890123456912
|4567890123456789| 123|4567890123456912
|4567890123456789| 4567890123456789|9135780246913578
|4567890123456789|-4567890123456789| 0
SELECT '' AS five, q1, q2, q1 + q2 AS plus FROM INT8_TBL;
five | q1 | q2 | plus
------+------------------+-------------------+------------------
| 123 | 456 | 579
| 123 | 4567890123456789 | 4567890123456912
| 4567890123456789 | 123 | 4567890123456912
| 4567890123456789 | 4567890123456789 | 9135780246913578
| 4567890123456789 | -4567890123456789 | 0
(5 rows)
QUERY: SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
five| q1| q2| minus
----+----------------+-----------------+-----------------
| 123| 456| -333
| 123| 4567890123456789|-4567890123456666
|4567890123456789| 123| 4567890123456666
|4567890123456789| 4567890123456789| 0
|4567890123456789|-4567890123456789| 9135780246913578
SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
five | q1 | q2 | minus
------+------------------+-------------------+-------------------
| 123 | 456 | -333
| 123 | 4567890123456789 | -4567890123456666
| 4567890123456789 | 123 | 4567890123456666
| 4567890123456789 | 4567890123456789 | 0
| 4567890123456789 | -4567890123456789 | 9135780246913578
(5 rows)
QUERY: SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
WHERE q1 < 1000 or (q2 > 0 and q2 < 1000);
three| q1| q2| multiply
-----+----------------+----------------+------------------
| 123| 456| 56088
| 123|4567890123456789|561850485185185047
|4567890123456789| 123|561850485185185047
three | q1 | q2 | multiply
-------+------------------+------------------+--------------------
| 123 | 456 | 56088
| 123 | 4567890123456789 | 561850485185185047
| 4567890123456789 | 123 | 561850485185185047
(3 rows)
QUERY: SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL;
five| q1| q2| divide
----+----------------+-----------------+--------------
| 123| 456| 0
| 123| 4567890123456789| 0
|4567890123456789| 123|37137318076884
|4567890123456789| 4567890123456789| 1
|4567890123456789|-4567890123456789| -1
SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL;
five | q1 | q2 | divide
------+------------------+-------------------+----------------
| 123 | 456 | 0
| 123 | 4567890123456789 | 0
| 4567890123456789 | 123 | 37137318076884
| 4567890123456789 | 4567890123456789 | 1
| 4567890123456789 | -4567890123456789 | -1
(5 rows)
QUERY: SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
five| q1|float8
----+----------------+--------------------
| 123|123
| 123|123
|4567890123456789|4.56789012345679e+15
|4567890123456789|4.56789012345679e+15
|4567890123456789|4.56789012345679e+15
SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
five | q1 | float8
------+------------------+----------------------
| 123 | 123
| 123 | 123
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+15
| 4567890123456789 | 4.56789012345679e+15
(5 rows)
QUERY: SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
five| q2|float8
----+-----------------+---------------------
| 456|456
| 4567890123456789|4.56789012345679e+15
| 123|123
| 4567890123456789|4.56789012345679e+15
|-4567890123456789|-4.56789012345679e+15
SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
five | q2 | float8
------+-------------------+-----------------------
| 456 | 456
| 4567890123456789 | 4.56789012345679e+15
| 123 | 123
| 4567890123456789 | 4.56789012345679e+15
| -4567890123456789 | -4.56789012345679e+15
(5 rows)
QUERY: SELECT '' AS five, q1, int8(float8(q1)) AS "two coercions" FROM INT8_TBL;
five| q1| two coercions
----+----------------+----------------
| 123| 123
| 123| 123
|4567890123456789|4567890123456789
|4567890123456789|4567890123456789
|4567890123456789|4567890123456789
SELECT '' AS five, q1, int8(float8(q1)) AS "two coercions" FROM INT8_TBL;
five | q1 | two coercions
------+------------------+------------------
| 123 | 123
| 123 | 123
| 4567890123456789 | 4567890123456789
| 4567890123456789 | 4567890123456789
| 4567890123456789 | 4567890123456789
(5 rows)
QUERY: SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
five| twice int4
----+----------------
| 246
| 246
|9135780246913578
|9135780246913578
|9135780246913578
SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
five | twice int4
------+------------------
| 246
| 246
| 9135780246913578
| 9135780246913578
| 9135780246913578
(5 rows)
QUERY: SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
five| twice int4
----+----------------
| 246
| 246
|9135780246913578
|9135780246913578
|9135780246913578
SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
five | twice int4
------+------------------
| 246
| 246
| 9135780246913578
| 9135780246913578
| 9135780246913578
(5 rows)
QUERY: SELECT 'name string'::name = 'name string'::name AS "True";
True
----
t
--
-- NAME
-- all inputs are silently truncated at NAMEDATALEN (32) characters
--
-- fixed-length by reference
SELECT name 'name string' = name 'name string' AS "True";
True
------
t
(1 row)
QUERY: SELECT 'name string'::name = 'name string '::name AS "False";
False
-----
f
SELECT name 'name string' = name 'name string ' AS "False";
False
-------
f
(1 row)
QUERY: CREATE TABLE NAME_TBL(f1 name);
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('ABCDEFGHIJKLMNOP');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('abcdefghijklmnop');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('asdfghjkl;');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('343f%2a');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('d34aaasdf');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ');
QUERY: SELECT '' AS seven, NAME_TBL.*;
seven|f1
-----+-------------------------------
|ABCDEFGHIJKLMNOP
|abcdefghijklmnop
|asdfghjkl;
|343f%2a
|d34aaasdf
|
|1234567890ABCDEFGHIJKLMNOPQRSTU
--
--
--
CREATE TABLE NAME_TBL(f1 name);
INSERT INTO NAME_TBL(f1) VALUES ('ABCDEFGHIJKLMNOP');
INSERT INTO NAME_TBL(f1) VALUES ('abcdefghijklmnop');
INSERT INTO NAME_TBL(f1) VALUES ('asdfghjkl;');
INSERT INTO NAME_TBL(f1) VALUES ('343f%2a');
INSERT INTO NAME_TBL(f1) VALUES ('d34aaasdf');
INSERT INTO NAME_TBL(f1) VALUES ('');
INSERT INTO NAME_TBL(f1) VALUES ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ');
SELECT '' AS seven, NAME_TBL.*;
seven | f1
-------+---------------------------------
| ABCDEFGHIJKLMNOP
| abcdefghijklmnop
| asdfghjkl;
| 343f%2a
| d34aaasdf
|
| 1234567890ABCDEFGHIJKLMNOPQRSTU
(7 rows)
QUERY: SELECT '' AS six, c.f1 FROM NAME_TBL c WHERE c.f1 <> 'ABCDEFGHIJKLMNOP';
six|f1
---+-------------------------------
|abcdefghijklmnop
|asdfghjkl;
|343f%2a
|d34aaasdf
|
|1234567890ABCDEFGHIJKLMNOPQRSTU
SELECT '' AS six, c.f1 FROM NAME_TBL c WHERE c.f1 <> 'ABCDEFGHIJKLMNOP';
six | f1
-----+---------------------------------
| abcdefghijklmnop
| asdfghjkl;
| 343f%2a
| d34aaasdf
|
| 1234567890ABCDEFGHIJKLMNOPQRSTU
(6 rows)
QUERY: SELECT '' AS one, c.f1 FROM NAME_TBL c WHERE c.f1 = 'ABCDEFGHIJKLMNOP';
one|f1
---+----------------
|ABCDEFGHIJKLMNOP
SELECT '' AS one, c.f1 FROM NAME_TBL c WHERE c.f1 = 'ABCDEFGHIJKLMNOP';
one | f1
-----+------------------
| ABCDEFGHIJKLMNOP
(1 row)
QUERY: SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 < 'ABCDEFGHIJKLMNOP';
three|f1
-----+-------------------------------
|343f%2a
|
|1234567890ABCDEFGHIJKLMNOPQRSTU
SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 < 'ABCDEFGHIJKLMNOP';
three | f1
-------+---------------------------------
| 343f%2a
|
| 1234567890ABCDEFGHIJKLMNOPQRSTU
(3 rows)
QUERY: SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 <= 'ABCDEFGHIJKLMNOP';
four|f1
----+-------------------------------
|ABCDEFGHIJKLMNOP
|343f%2a
|
|1234567890ABCDEFGHIJKLMNOPQRSTU
SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 <= 'ABCDEFGHIJKLMNOP';
four | f1
------+---------------------------------
| ABCDEFGHIJKLMNOP
| 343f%2a
|
| 1234567890ABCDEFGHIJKLMNOPQRSTU
(4 rows)
QUERY: SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 > 'ABCDEFGHIJKLMNOP';
three|f1
-----+----------------
|abcdefghijklmnop
|asdfghjkl;
|d34aaasdf
SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 > 'ABCDEFGHIJKLMNOP';
three | f1
-------+------------------
| abcdefghijklmnop
| asdfghjkl;
| d34aaasdf
(3 rows)
QUERY: SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 >= 'ABCDEFGHIJKLMNOP';
four|f1
----+----------------
|ABCDEFGHIJKLMNOP
|abcdefghijklmnop
|asdfghjkl;
|d34aaasdf
SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 >= 'ABCDEFGHIJKLMNOP';
four | f1
------+------------------
| ABCDEFGHIJKLMNOP
| abcdefghijklmnop
| asdfghjkl;
| d34aaasdf
(4 rows)
QUERY: SELECT '' AS seven, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*';
seven|f1
-----+-------------------------------
|ABCDEFGHIJKLMNOP
|abcdefghijklmnop
|asdfghjkl;
|343f%2a
|d34aaasdf
|
|1234567890ABCDEFGHIJKLMNOPQRSTU
SELECT '' AS seven, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*';
seven | f1
-------+---------------------------------
| ABCDEFGHIJKLMNOP
| abcdefghijklmnop
| asdfghjkl;
| 343f%2a
| d34aaasdf
|
| 1234567890ABCDEFGHIJKLMNOPQRSTU
(7 rows)
QUERY: SELECT '' AS zero, c.f1 FROM NAME_TBL c WHERE c.f1 !~ '.*';
zero|f1
----+--
SELECT '' AS zero, c.f1 FROM NAME_TBL c WHERE c.f1 !~ '.*';
zero | f1
------+----
(0 rows)
QUERY: SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '[0-9]';
three|f1
-----+-------------------------------
|343f%2a
|d34aaasdf
|1234567890ABCDEFGHIJKLMNOPQRSTU
SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '[0-9]';
three | f1
-------+---------------------------------
| 343f%2a
| d34aaasdf
| 1234567890ABCDEFGHIJKLMNOPQRSTU
(3 rows)
QUERY: SELECT '' AS two, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*asdf.*';
two|f1
---+----------
|asdfghjkl;
|d34aaasdf
SELECT '' AS two, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*asdf.*';
two | f1
-----+------------
| asdfghjkl;
| d34aaasdf
(2 rows)
QUERY: DROP TABLE NAME_TBL;
DROP TABLE NAME_TBL;
QUERY: CREATE TABLE OID_TBL(f1 oid);
QUERY: INSERT INTO OID_TBL(f1) VALUES ('1234');
QUERY: INSERT INTO OID_TBL(f1) VALUES ('1235');
QUERY: INSERT INTO OID_TBL(f1) VALUES ('987');
QUERY: INSERT INTO OID_TBL(f1) VALUES ('-1040');
QUERY: INSERT INTO OID_TBL(f1) VALUES ('');
QUERY: INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
--
-- OID
--
CREATE TABLE OID_TBL(f1 oid);
INSERT INTO OID_TBL(f1) VALUES ('1234');
INSERT INTO OID_TBL(f1) VALUES ('1235');
INSERT INTO OID_TBL(f1) VALUES ('987');
INSERT INTO OID_TBL(f1) VALUES ('-1040');
INSERT INTO OID_TBL(f1) VALUES ('');
-- bad inputs
INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
ERROR: pg_atoi: error in "asdfasd": can't parse "asdfasd"
QUERY: SELECT '' AS five, OID_TBL.*;
five| f1
----+-----
| 1234
| 1235
| 987
|-1040
| 0
SELECT '' AS five, OID_TBL.*;
five | f1
------+-------
| 1234
| 1235
| 987
| -1040
| 0
(5 rows)
QUERY: SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 = '1234'::oid;
one| f1
---+----
|1234
SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 = oid '1234';
one | f1
-----+------
| 1234
(1 row)
QUERY: SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <> '1234';
four| f1
----+-----
| 1235
| 987
|-1040
| 0
SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <> '1234';
four | f1
------+-------
| 1235
| 987
| -1040
| 0
(4 rows)
QUERY: SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <= '1234';
four| f1
----+-----
| 1234
| 987
|-1040
| 0
SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <= '1234';
four | f1
------+-------
| 1234
| 987
| -1040
| 0
(4 rows)
QUERY: SELECT '' AS three, o.* FROM OID_TBL o WHERE o.f1 < '1234';
three| f1
-----+-----
| 987
|-1040
| 0
SELECT '' AS three, o.* FROM OID_TBL o WHERE o.f1 < '1234';
three | f1
-------+-------
| 987
| -1040
| 0
(3 rows)
QUERY: SELECT '' AS two, o.* FROM OID_TBL o WHERE o.f1 >= '1234';
two| f1
---+----
|1234
|1235
SELECT '' AS two, o.* FROM OID_TBL o WHERE o.f1 >= '1234';
two | f1
-----+------
| 1234
| 1235
(2 rows)
QUERY: SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 > '1234';
one| f1
---+----
|1235
SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 > '1234';
one | f1
-----+------
| 1235
(1 row)
QUERY: DROP TABLE OID_TBL;
DROP TABLE OID_TBL;
QUERY: SELECT 'this is a text string'::text = 'this is a text string'::text AS true;
true
----
t
--
-- TEXT
--
SELECT text 'this is a text string' = text 'this is a text string' AS true;
true
------
t
(1 row)
QUERY: SELECT 'this is a text string'::text = 'this is a text strin'::text AS false;
false
-----
f
SELECT text 'this is a text string' = text 'this is a text strin' AS false;
false
-------
f
(1 row)
QUERY: CREATE TABLE TEXT_TBL (f1 text);
QUERY: INSERT INTO TEXT_TBL VALUES ('doh!');
QUERY: INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor');
QUERY: SELECT '' AS two, * FROM TEXT_TBL;
two|f1
---+-----------------
|doh!
|hi de ho neighbor
CREATE TABLE TEXT_TBL (f1 text);
INSERT INTO TEXT_TBL VALUES ('doh!');
INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor');
SELECT '' AS two, * FROM TEXT_TBL;
two | f1
-----+-------------------
| doh!
| hi de ho neighbor
(2 rows)
QUERY: CREATE TABLE VARCHAR_TBL(f1 varchar(1));
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('A');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('1');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES (2);
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('3');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('cd');
QUERY: SELECT '' AS seven, VARCHAR_TBL.*;
seven|f1
-----+--
|a
|A
|1
|2
|3
|
|c
--
-- VARCHAR
--
CREATE TABLE VARCHAR_TBL(f1 varchar(1));
INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
INSERT INTO VARCHAR_TBL (f1) VALUES ('A');
-- any of the following three input formats are acceptable
INSERT INTO VARCHAR_TBL (f1) VALUES ('1');
INSERT INTO VARCHAR_TBL (f1) VALUES (2);
INSERT INTO VARCHAR_TBL (f1) VALUES ('3');
-- zero-length char
INSERT INTO VARCHAR_TBL (f1) VALUES ('');
-- try varchar's of greater than 1 length
INSERT INTO VARCHAR_TBL (f1) VALUES ('cd');
SELECT '' AS seven, VARCHAR_TBL.*;
seven | f1
-------+----
| a
| A
| 1
| 2
| 3
|
| c
(7 rows)
QUERY: SELECT '' AS six, c.*
SELECT '' AS six, c.*
FROM VARCHAR_TBL c
WHERE c.f1 <> 'a';
six|f1
---+--
|A
|1
|2
|3
|
|c
six | f1
-----+----
| A
| 1
| 2
| 3
|
| c
(6 rows)
QUERY: SELECT '' AS one, c.*
SELECT '' AS one, c.*
FROM VARCHAR_TBL c
WHERE c.f1 = 'a';
one|f1
---+--
|a
one | f1
-----+----
| a
(1 row)
QUERY: SELECT '' AS five, c.*
SELECT '' AS five, c.*
FROM VARCHAR_TBL c
WHERE c.f1 < 'a';
five|f1
----+--
|A
|1
|2
|3
|
five | f1
------+----
| A
| 1
| 2
| 3
|
(5 rows)
QUERY: SELECT '' AS six, c.*
SELECT '' AS six, c.*
FROM VARCHAR_TBL c
WHERE c.f1 <= 'a';
six|f1
---+--
|a
|A
|1
|2
|3
|
six | f1
-----+----
| a
| A
| 1
| 2
| 3
|
(6 rows)
QUERY: SELECT '' AS one, c.*
SELECT '' AS one, c.*
FROM VARCHAR_TBL c
WHERE c.f1 > 'a';
one|f1
---+--
|c
one | f1
-----+----
| c
(1 row)
QUERY: SELECT '' AS two, c.*
SELECT '' AS two, c.*
FROM VARCHAR_TBL c
WHERE c.f1 >= 'a';
two|f1
---+--
|a
|c
two | f1
-----+----
| a
| c
(2 rows)
QUERY: DROP TABLE VARCHAR_TBL;
QUERY: CREATE TABLE VARCHAR_TBL(f1 varchar(4));
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('ab');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
QUERY: SELECT '' AS four, VARCHAR_TBL.*;
four|f1
----+----
|a
|ab
|abcd
|abcd
DROP TABLE VARCHAR_TBL;
--
-- Now test longer arrays of char
--
CREATE TABLE VARCHAR_TBL(f1 varchar(4));
INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
INSERT INTO VARCHAR_TBL (f1) VALUES ('ab');
INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd');
INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
SELECT '' AS four, VARCHAR_TBL.*;
four | f1
------+------
| a
| ab
| abcd
| abcd
(4 rows)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment