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 -- BOOLEAN
--- --
1 --
-- sanity check - if this fails go insane!
--
SELECT 1 AS one;
one
-----
1
(1 row) (1 row)
QUERY: SELECT 't'::bool AS true; -- ******************testing built-in type bool********************
true -- check bool type-casting as well as and, or, not in qualifications--
---- SELECT bool 't' AS true;
t true
------
t
(1 row) (1 row)
QUERY: SELECT 'f'::bool AS false; SELECT bool 'f' AS false;
false false
----- -------
f f
(1 row) (1 row)
QUERY: SELECT 't'::bool or 'f'::bool AS true; SELECT bool 't' or bool 'f' AS true;
true true
---- ------
t t
(1 row) (1 row)
QUERY: SELECT 't'::bool and 'f'::bool AS false; SELECT bool 't' and bool 'f' AS false;
false false
----- -------
f f
(1 row) (1 row)
QUERY: SELECT not 'f'::bool AS true; SELECT not bool 'f' AS true;
true true
---- ------
t t
(1 row) (1 row)
QUERY: SELECT 't'::bool = 'f'::bool AS false; SELECT bool 't' = bool 'f' AS false;
false false
----- -------
f f
(1 row) (1 row)
QUERY: SELECT 't'::bool <> 'f'::bool AS true; SELECT bool 't' <> bool 'f' AS true;
true true
---- ------
t t
(1 row) (1 row)
QUERY: CREATE TABLE BOOLTBL1 (f1 bool); CREATE TABLE BOOLTBL1 (f1 bool);
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('t'::bool); INSERT INTO BOOLTBL1 (f1) VALUES (bool 't');
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('True'::bool); INSERT INTO BOOLTBL1 (f1) VALUES (bool 'True');
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('true'::bool); INSERT INTO BOOLTBL1 (f1) VALUES (bool 'true');
QUERY: SELECT '' AS t_3, BOOLTBL1.*; -- BOOLTBL1 should be full of true's at this point
t_3|f1 SELECT '' AS t_3, BOOLTBL1.*;
---+-- t_3 | f1
|t -----+----
|t | t
|t | t
| t
(3 rows) (3 rows)
QUERY: SELECT '' AS t_3, BOOLTBL1.* SELECT '' AS t_3, BOOLTBL1.*
FROM BOOLTBL1 FROM BOOLTBL1
WHERE f1 = 'true'::bool; WHERE f1 = bool 'true';
t_3|f1 t_3 | f1
---+-- -----+----
|t | t
|t | t
|t | t
(3 rows) (3 rows)
QUERY: SELECT '' AS t_3, BOOLTBL1.* SELECT '' AS t_3, BOOLTBL1.*
FROM BOOLTBL1 FROM BOOLTBL1
WHERE f1 <> 'false'::bool; WHERE f1 <> bool 'false';
t_3|f1 t_3 | f1
---+-- -----+----
|t | t
|t | t
|t | t
(3 rows) (3 rows)
QUERY: SELECT '' AS zero, BOOLTBL1.* SELECT '' AS zero, BOOLTBL1.*
FROM BOOLTBL1 FROM BOOLTBL1
WHERE booleq('false'::bool, f1); WHERE booleq(bool 'false', f1);
zero|f1 zero | f1
----+-- ------+----
(0 rows) (0 rows)
QUERY: INSERT INTO BOOLTBL1 (f1) VALUES ('f'::bool); INSERT INTO BOOLTBL1 (f1) VALUES (bool 'f');
QUERY: SELECT '' AS f_1, BOOLTBL1.* SELECT '' AS f_1, BOOLTBL1.*
FROM BOOLTBL1 FROM BOOLTBL1
WHERE f1 = 'false'::bool; WHERE f1 = bool 'false';
f_1|f1 f_1 | f1
---+-- -----+----
|f | f
(1 row) (1 row)
QUERY: CREATE TABLE BOOLTBL2 (f1 bool); CREATE TABLE BOOLTBL2 (f1 bool);
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('f'::bool); INSERT INTO BOOLTBL2 (f1) VALUES (bool 'f');
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('false'::bool); INSERT INTO BOOLTBL2 (f1) VALUES (bool 'false');
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('False'::bool); INSERT INTO BOOLTBL2 (f1) VALUES (bool 'False');
QUERY: INSERT INTO BOOLTBL2 (f1) VALUES ('FALSE'::bool); INSERT INTO BOOLTBL2 (f1) VALUES (bool 'FALSE');
QUERY: INSERT INTO BOOLTBL2 (f1) -- This is now an invalid expression
VALUES ('XXX'::bool); -- 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' ERROR: Bad boolean external representation 'XXX'
QUERY: SELECT '' AS f_4, BOOLTBL2.*; -- BOOLTBL2 should be full of false's at this point
f_4|f1 SELECT '' AS f_4, BOOLTBL2.*;
---+-- f_4 | f1
|f -----+----
|f | f
|f | f
|f | f
| f
(4 rows) (4 rows)
QUERY: SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.* SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 <> BOOLTBL1.f1; WHERE BOOLTBL2.f1 <> BOOLTBL1.f1;
tf_12|f1|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
|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) (12 rows)
QUERY: SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.* SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
WHERE boolne(BOOLTBL2.f1,BOOLTBL1.f1); WHERE boolne(BOOLTBL2.f1,BOOLTBL1.f1);
tf_12|f1|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
|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) (12 rows)
QUERY: SELECT '' AS ff_4, BOOLTBL1.*, BOOLTBL2.* SELECT '' AS ff_4, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 = BOOLTBL1.f1 and BOOLTBL1.f1 = 'false'::bool; WHERE BOOLTBL2.f1 = BOOLTBL1.f1 and BOOLTBL1.f1 = bool 'false';
ff_4|f1|f1 ff_4 | f1 | f1
----+--+-- ------+----+----
|f |f | f | f
|f |f | f | f
|f |f | f | f
|f |f | f | f
(4 rows) (4 rows)
QUERY: SELECT '' AS tf_12_ff_4, BOOLTBL1.*, BOOLTBL2.* SELECT '' AS tf_12_ff_4, BOOLTBL1.*, BOOLTBL2.*
WHERE BOOLTBL2.f1 = BOOLTBL1.f1 or BOOLTBL1.f1 = 'true'::bool WHERE BOOLTBL2.f1 = BOOLTBL1.f1 or BOOLTBL1.f1 = bool 'true'
ORDER BY BOOLTBL1.f1, BOOLTBL2.f1; ORDER BY BOOLTBL1.f1, BOOLTBL2.f1;
tf_12_ff_4|f1|f1 tf_12_ff_4 | f1 | f1
----------+--+-- ------------+----+----
|f |f | f | f
|f |f | f | f
|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
|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) (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 FROM BOOLTBL1
WHERE f1 IS TRUE; WHERE f1 IS TRUE;
True|f1 True | f1
----+-- ------+----
|t | t
|t | t
|t | t
(3 rows) (3 rows)
QUERY: SELECT '' AS "Not False", BOOLTBL1.* SELECT '' AS "Not False", f1
FROM BOOLTBL1 FROM BOOLTBL1
WHERE f1 IS NOT FALSE; WHERE f1 IS NOT FALSE;
Not False|f1 Not False | f1
---------+-- -----------+----
|t | t
|t | t
|t | t
(3 rows) (3 rows)
QUERY: SELECT '' AS "False", BOOLTBL1.* SELECT '' AS "False", f1
FROM BOOLTBL1 FROM BOOLTBL1
WHERE f1 IS FALSE; WHERE f1 IS FALSE;
False|f1 False | f1
-----+-- -------+----
|f | f
(1 row) (1 row)
QUERY: SELECT '' AS "Not True", BOOLTBL1.* SELECT '' AS "Not True", f1
FROM BOOLTBL1 FROM BOOLTBL1
WHERE f1 IS NOT TRUE; WHERE f1 IS NOT TRUE;
Not True|f1 Not True | f1
--------+-- ----------+----
|f | f
(1 row) (1 row)
QUERY: DROP TABLE BOOLTBL1; SELECT '' AS "True", f1
QUERY: DROP TABLE BOOLTBL2; 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 -- CHAR
---- -- all inputs are SILENTLY truncated at 1 character
t --
-- fixed-length by value
-- internally passed by value if <= 4 bytes in storage
SELECT char 'c' = char 'c' AS true;
true
------
t
(1 row) (1 row)
QUERY: CREATE TABLE CHAR_TBL(f1 char); --
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('a'); -- Build a table for testing
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('A'); --
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('1'); CREATE TABLE CHAR_TBL(f1 char);
QUERY: INSERT INTO CHAR_TBL (f1) VALUES (2); INSERT INTO CHAR_TBL (f1) VALUES ('a');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('3'); INSERT INTO CHAR_TBL (f1) VALUES ('A');
QUERY: INSERT INTO CHAR_TBL (f1) VALUES (''); -- any of the following three input formats are acceptable
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('cd'); INSERT INTO CHAR_TBL (f1) VALUES ('1');
QUERY: SELECT '' AS seven, CHAR_TBL.*; INSERT INTO CHAR_TBL (f1) VALUES (2);
seven|f1 INSERT INTO CHAR_TBL (f1) VALUES ('3');
-----+-- -- zero-length char
|a INSERT INTO CHAR_TBL (f1) VALUES ('');
|A -- try char's of greater than 1 length
|1 INSERT INTO CHAR_TBL (f1) VALUES ('cd');
|2 SELECT '' AS seven, CHAR_TBL.*;
|3 seven | f1
| -------+----
|c | a
| A
| 1
| 2
| 3
|
| c
(7 rows) (7 rows)
QUERY: SELECT '' AS six, c.* SELECT '' AS six, c.*
FROM CHAR_TBL c FROM CHAR_TBL c
WHERE c.f1 <> 'a'; WHERE c.f1 <> 'a';
six|f1 six | f1
---+-- -----+----
|A | A
|1 | 1
|2 | 2
|3 | 3
| |
|c | c
(6 rows) (6 rows)
QUERY: SELECT '' AS one, c.* SELECT '' AS one, c.*
FROM CHAR_TBL c FROM CHAR_TBL c
WHERE c.f1 = 'a'; WHERE c.f1 = 'a';
one|f1 one | f1
---+-- -----+----
|a | a
(1 row) (1 row)
QUERY: SELECT '' AS five, c.* SELECT '' AS five, c.*
FROM CHAR_TBL c FROM CHAR_TBL c
WHERE c.f1 < 'a'; WHERE c.f1 < 'a';
five|f1 five | f1
----+-- ------+----
|A | A
|1 | 1
|2 | 2
|3 | 3
| |
(5 rows) (5 rows)
QUERY: SELECT '' AS six, c.* SELECT '' AS six, c.*
FROM CHAR_TBL c FROM CHAR_TBL c
WHERE c.f1 <= 'a'; WHERE c.f1 <= 'a';
six|f1 six | f1
---+-- -----+----
|a | a
|A | A
|1 | 1
|2 | 2
|3 | 3
| |
(6 rows) (6 rows)
QUERY: SELECT '' AS one, c.* SELECT '' AS one, c.*
FROM CHAR_TBL c FROM CHAR_TBL c
WHERE c.f1 > 'a'; WHERE c.f1 > 'a';
one|f1 one | f1
---+-- -----+----
|c | c
(1 row) (1 row)
QUERY: SELECT '' AS two, c.* SELECT '' AS two, c.*
FROM CHAR_TBL c FROM CHAR_TBL c
WHERE c.f1 >= 'a'; WHERE c.f1 >= 'a';
two|f1 two | f1
---+-- -----+----
|a | a
|c | c
(2 rows) (2 rows)
QUERY: DROP TABLE CHAR_TBL; DROP TABLE CHAR_TBL;
QUERY: CREATE TABLE CHAR_TBL(f1 char(4)); --
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('a'); -- Now test longer arrays of char
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('ab'); --
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('abcd'); CREATE TABLE CHAR_TBL(f1 char(4));
QUERY: INSERT INTO CHAR_TBL (f1) VALUES ('abcde'); INSERT INTO CHAR_TBL (f1) VALUES ('a');
QUERY: SELECT '' AS four, CHAR_TBL.*; INSERT INTO CHAR_TBL (f1) VALUES ('ab');
four|f1 INSERT INTO CHAR_TBL (f1) VALUES ('abcd');
----+---- INSERT INTO CHAR_TBL (f1) VALUES ('abcde');
|a SELECT '' AS four, CHAR_TBL.*;
|ab four | f1
|abcd ------+------
|abcd | a
| ab
| abcd
| abcd
(4 rows) (4 rows)
QUERY: CREATE TABLE FLOAT4_TBL (f1 float4); --
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('0.0'); -- FLOAT4
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('1004.30'); --
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('-34.84'); CREATE TABLE FLOAT4_TBL (f1 float4);
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20'); INSERT INTO FLOAT4_TBL(f1) VALUES ('0.0');
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20'); INSERT INTO FLOAT4_TBL(f1) VALUES ('1004.30');
QUERY: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40'); 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 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 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 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 ERROR: Bad float4 input format -- underflow
QUERY: SELECT '' AS five, FLOAT4_TBL.*; SELECT '' AS five, FLOAT4_TBL.*;
five|f1 five | 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) (5 rows)
QUERY: SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <> '1004.3'; SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <> '1004.3';
four|f1 four | f1
----+----------- ------+-------------
|0 | 0
|-34.84 | -34.84
|1.23457e+20 | 1.23457e+20
|1.23457e-20 | 1.23457e-20
(4 rows) (4 rows)
QUERY: SELECT '' AS one, f.* FROM FLOAT4_TBL f WHERE f.f1 = '1004.3'; SELECT '' AS one, f.* FROM FLOAT4_TBL f WHERE f.f1 = '1004.3';
one| f1 one | f1
---+------ -----+--------
|1004.3 | 1004.3
(1 row) (1 row)
QUERY: SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE '1004.3' > f.f1; SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE '1004.3' > f.f1;
three| f1 three | f1
-----+----------- -------+-------------
| 0 | 0
| -34.84 | -34.84
|1.23457e-20 | 1.23457e-20
(3 rows) (3 rows)
QUERY: SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE f.f1 < '1004.3'; SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE f.f1 < '1004.3';
three| f1 three | f1
-----+----------- -------+-------------
| 0 | 0
| -34.84 | -34.84
|1.23457e-20 | 1.23457e-20
(3 rows) (3 rows)
QUERY: SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1; SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1;
four| f1 four | f1
----+----------- ------+-------------
| 0 | 0
| 1004.3 | 1004.3
| -34.84 | -34.84
|1.23457e-20 | 1.23457e-20
(4 rows) (4 rows)
QUERY: SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <= '1004.3'; SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <= '1004.3';
four| f1 four | f1
----+----------- ------+-------------
| 0 | 0
| 1004.3 | 1004.3
| -34.84 | -34.84
|1.23457e-20 | 1.23457e-20
(4 rows) (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'; WHERE f.f1 > '0.0';
three|f1 |x three | f1 | x
-----+-----------+------------ -------+-------------+--------------
|1004.3 |-10043 | 1004.3 | -10043
|1.23457e+20|-1.23457e+21 | 1.23457e+20 | -1.23457e+21
|1.23457e-20|-1.23457e-19 | 1.23457e-20 | -1.23457e-19
(3 rows) (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'; WHERE f.f1 > '0.0';
three|f1 |x three | f1 | x
-----+-----------+----------- -------+-------------+-------------
|1004.3 |994.3 | 1004.3 | 994.3
|1.23457e+20|1.23457e+20 | 1.23457e+20 | 1.23457e+20
|1.23457e-20|-10 | 1.23457e-20 | -10
(3 rows) (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'; WHERE f.f1 > '0.0';
three|f1 |x three | f1 | x
-----+-----------+------------ -------+-------------+--------------
|1004.3 |-100.43 | 1004.3 | -100.43
|1.23457e+20|-1.23457e+19 | 1.23457e+20 | -1.23457e+19
|1.23457e-20|-1.23457e-21 | 1.23457e-20 | -1.23457e-21
(3 rows) (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'; WHERE f.f1 > '0.0';
three|f1 |x three | f1 | x
-----+-----------+----------- -------+-------------+-------------
|1004.3 |1014.3 | 1004.3 | 1014.3
|1.23457e+20|1.23457e+20 | 1.23457e+20 | 1.23457e+20
|1.23457e-20|10 | 1.23457e-20 | 10
(3 rows) (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 ERROR: float4div: divide by zero error
QUERY: SELECT '' AS five, FLOAT4_TBL.*; SELECT '' AS five, FLOAT4_TBL.*;
five|f1 five | 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) (5 rows)
QUERY: SELECT '' AS five, f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f; -- test the unary float4abs operator
five|f1 |abs_f1 SELECT '' AS five, f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
----+-----------+----------- five | f1 | abs_f1
|0 |0 ------+-------------+-------------
|1004.3 |1004.3 | 0 | 0
|-34.84 |34.84 | 1004.3 | 1004.3
|1.23457e+20|1.23457e+20 | -34.84 | 34.84
|1.23457e-20|1.23457e-20 | 1.23457e+20 | 1.23457e+20
| 1.23457e-20 | 1.23457e-20
(5 rows) (5 rows)
QUERY: UPDATE FLOAT4_TBL UPDATE FLOAT4_TBL
SET f1 = FLOAT4_TBL.f1 * '-1' SET f1 = FLOAT4_TBL.f1 * '-1'
WHERE FLOAT4_TBL.f1 > '0.0'; WHERE FLOAT4_TBL.f1 > '0.0';
QUERY: SELECT '' AS five, FLOAT4_TBL.*; SELECT '' AS five, FLOAT4_TBL.*;
five|f1 five | f1
----+------------ ------+--------------
|0 | 0
|-34.84 | -34.84
|-1004.3 | -1004.3
|-1.23457e+20 | -1.23457e+20
|-1.23457e-20 | -1.23457e-20
(5 rows) (5 rows)
This diff is collapsed.
QUERY: CREATE TABLE INT2_TBL(f1 int2); --
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('0'); -- INT2
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('1234'); -- NOTE: int2 operators never check for over/underflow!
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('-1234'); -- Some of these answers are consequently numerically incorrect.
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('34.5'); --
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" ERROR: pg_atoi: error in "34.5": can't parse ".5"
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('32767'); -- largest and smallest values
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('-32767'); INSERT INTO INT2_TBL(f1) VALUES ('32767');
QUERY: INSERT INTO INT2_TBL(f1) VALUES ('100000'); 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 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" ERROR: pg_atoi: error in "asdf": can't parse "asdf"
QUERY: SELECT '' AS five, INT2_TBL.*; SELECT '' AS five, INT2_TBL.*;
five| f1 five | f1
----+------ ------+--------
| 0 | 0
| 1234 | 1234
| -1234 | -1234
| 32767 | 32767
|-32767 | -32767
(5 rows) (5 rows)
QUERY: SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> '0'::int2; SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int2 '0';
four| f1 four | f1
----+------ ------+--------
| 1234 | 1234
| -1234 | -1234
| 32767 | 32767
|-32767 | -32767
(4 rows) (4 rows)
QUERY: SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> '0'::int4; SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int4 '0';
four| f1 four | f1
----+------ ------+--------
| 1234 | 1234
| -1234 | -1234
| 32767 | 32767
|-32767 | -32767
(4 rows) (4 rows)
QUERY: SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = '0'::int2; SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int2 '0';
one|f1 one | f1
---+-- -----+----
| 0 | 0
(1 row) (1 row)
QUERY: SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = '0'::int4; SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int4 '0';
one|f1 one | f1
---+-- -----+----
| 0 | 0
(1 row) (1 row)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < '0'::int2; SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int2 '0';
two| f1 two | f1
---+------ -----+--------
| -1234 | -1234
|-32767 | -32767
(2 rows) (2 rows)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < '0'::int4; SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int4 '0';
two| f1 two | f1
---+------ -----+--------
| -1234 | -1234
|-32767 | -32767
(2 rows) (2 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= '0'::int2; SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int2 '0';
three| f1 three | f1
-----+------ -------+--------
| 0 | 0
| -1234 | -1234
|-32767 | -32767
(3 rows) (3 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= '0'::int4; SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int4 '0';
three| f1 three | f1
-----+------ -------+--------
| 0 | 0
| -1234 | -1234
|-32767 | -32767
(3 rows) (3 rows)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > '0'::int2; SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int2 '0';
two| f1 two | f1
---+----- -----+-------
| 1234 | 1234
|32767 | 32767
(2 rows) (2 rows)
QUERY: SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > '0'::int4; SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int4 '0';
two| f1 two | f1
---+----- -----+-------
| 1234 | 1234
|32767 | 32767
(2 rows) (2 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= '0'::int2; SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int2 '0';
three| f1 three | f1
-----+----- -------+-------
| 0 | 0
| 1234 | 1234
|32767 | 32767
(3 rows) (3 rows)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= '0'::int4; SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int4 '0';
three| f1 three | f1
-----+----- -------+-------
| 0 | 0
| 1234 | 1234
|32767 | 32767
(3 rows) (3 rows)
QUERY: SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % '2'::int2) = '1'::int2; -- positive odds
one| f1 SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
---+----- one | f1
|32767 -----+-------
| 32767
(1 row) (1 row)
QUERY: SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % '2'::int4) = '0'::int2; -- any evens
three| f1 SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
-----+----- three | f1
| 0 -------+-------
| 1234 | 0
|-1234 | 1234
| -1234
(3 rows) (3 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 * '2'::int2 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+----- ------+--------+-------
| 0| 0 | 0 | 0
| 1234| 2468 | 1234 | 2468
| -1234|-2468 | -1234 | -2468
| 32767| -2 | 32767 | -2
|-32767| 2 | -32767 | 2
(5 rows) (5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 * '2'::int4 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+------ ------+--------+--------
| 0| 0 | 0 | 0
| 1234| 2468 | 1234 | 2468
| -1234| -2468 | -1234 | -2468
| 32767| 65534 | 32767 | 65534
|-32767|-65534 | -32767 | -65534
(5 rows) (5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 + '2'::int2 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+------ ------+--------+--------
| 0| 2 | 0 | 2
| 1234| 1236 | 1234 | 1236
| -1234| -1232 | -1234 | -1232
| 32767|-32767 | 32767 | -32767
|-32767|-32765 | -32767 | -32765
(5 rows) (5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 + '2'::int4 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+------ ------+--------+--------
| 0| 2 | 0 | 2
| 1234| 1236 | 1234 | 1236
| -1234| -1232 | -1234 | -1232
| 32767| 32769 | 32767 | 32769
|-32767|-32765 | -32767 | -32765
(5 rows) (5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 - '2'::int2 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+----- ------+--------+-------
| 0| -2 | 0 | -2
| 1234| 1232 | 1234 | 1232
| -1234|-1236 | -1234 | -1236
| 32767|32765 | 32767 | 32765
|-32767|32767 | -32767 | 32767
(5 rows) (5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 - '2'::int4 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+------ ------+--------+--------
| 0| -2 | 0 | -2
| 1234| 1232 | 1234 | 1232
| -1234| -1236 | -1234 | -1236
| 32767| 32765 | 32767 | 32765
|-32767|-32769 | -32767 | -32769
(5 rows) (5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 / '2'::int2 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+------ ------+--------+--------
| 0| 0 | 0 | 0
| 1234| 617 | 1234 | 617
| -1234| -617 | -1234 | -617
| 32767| 16383 | 32767 | 16383
|-32767|-16383 | -32767 | -16383
(5 rows) (5 rows)
QUERY: SELECT '' AS five, i.f1, i.f1 / '2'::int4 AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
five| f1| x five | f1 | x
----+------+------ ------+--------+--------
| 0| 0 | 0 | 0
| 1234| 617 | 1234 | 617
| -1234| -617 | -1234 | -617
| 32767| 16383 | 32767 | 16383
|-32767|-16383 | -32767 | -16383
(5 rows) (5 rows)
This diff is collapsed.
QUERY: CREATE TABLE INT8_TBL(q1 int8, q2 int8); --
QUERY: INSERT INTO INT8_TBL VALUES('123','456'); -- INT8
QUERY: INSERT INTO INT8_TBL VALUES('123','4567890123456789'); -- Test int8 64-bit integers.
QUERY: INSERT INTO INT8_TBL VALUES('4567890123456789','123'); --
QUERY: INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789'); CREATE TABLE INT8_TBL(q1 int8, q2 int8);
QUERY: INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789'); INSERT INTO INT8_TBL VALUES('123','456');
QUERY: SELECT * FROM INT8_TBL; INSERT INTO INT8_TBL VALUES('123','4567890123456789');
q1| q2 INSERT INTO INT8_TBL VALUES('4567890123456789','123');
----------------+----------------- INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789');
123| 456 INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789');
123| 4567890123456789 SELECT * FROM INT8_TBL;
4567890123456789| 123 q1 | q2
4567890123456789| 4567890123456789 ------------------+-------------------
4567890123456789|-4567890123456789 123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows) (5 rows)
QUERY: SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL; SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
five| plus| minus five | plus | minus
----+----------------+----------------- ------+------------------+-------------------
| 123| -123 | 123 | -123
| 123| -123 | 123 | -123
|4567890123456789|-4567890123456789 | 4567890123456789 | -4567890123456789
|4567890123456789|-4567890123456789 | 4567890123456789 | -4567890123456789
|4567890123456789|-4567890123456789 | 4567890123456789 | -4567890123456789
(5 rows) (5 rows)
QUERY: SELECT '' AS five, q1, q2, q1 + q2 AS plus FROM INT8_TBL; SELECT '' AS five, q1, q2, q1 + q2 AS plus FROM INT8_TBL;
five| q1| q2| plus five | q1 | q2 | plus
----+----------------+-----------------+---------------- ------+------------------+-------------------+------------------
| 123| 456| 579 | 123 | 456 | 579
| 123| 4567890123456789|4567890123456912 | 123 | 4567890123456789 | 4567890123456912
|4567890123456789| 123|4567890123456912 | 4567890123456789 | 123 | 4567890123456912
|4567890123456789| 4567890123456789|9135780246913578 | 4567890123456789 | 4567890123456789 | 9135780246913578
|4567890123456789|-4567890123456789| 0 | 4567890123456789 | -4567890123456789 | 0
(5 rows) (5 rows)
QUERY: SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL; SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
five| q1| q2| minus five | q1 | q2 | minus
----+----------------+-----------------+----------------- ------+------------------+-------------------+-------------------
| 123| 456| -333 | 123 | 456 | -333
| 123| 4567890123456789|-4567890123456666 | 123 | 4567890123456789 | -4567890123456666
|4567890123456789| 123| 4567890123456666 | 4567890123456789 | 123 | 4567890123456666
|4567890123456789| 4567890123456789| 0 | 4567890123456789 | 4567890123456789 | 0
|4567890123456789|-4567890123456789| 9135780246913578 | 4567890123456789 | -4567890123456789 | 9135780246913578
(5 rows) (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); WHERE q1 < 1000 or (q2 > 0 and q2 < 1000);
three| q1| q2| multiply three | q1 | q2 | multiply
-----+----------------+----------------+------------------ -------+------------------+------------------+--------------------
| 123| 456| 56088 | 123 | 456 | 56088
| 123|4567890123456789|561850485185185047 | 123 | 4567890123456789 | 561850485185185047
|4567890123456789| 123|561850485185185047 | 4567890123456789 | 123 | 561850485185185047
(3 rows) (3 rows)
QUERY: SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL; SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL;
five| q1| q2| divide five | q1 | q2 | divide
----+----------------+-----------------+-------------- ------+------------------+-------------------+----------------
| 123| 456| 0 | 123 | 456 | 0
| 123| 4567890123456789| 0 | 123 | 4567890123456789 | 0
|4567890123456789| 123|37137318076884 | 4567890123456789 | 123 | 37137318076884
|4567890123456789| 4567890123456789| 1 | 4567890123456789 | 4567890123456789 | 1
|4567890123456789|-4567890123456789| -1 | 4567890123456789 | -4567890123456789 | -1
(5 rows) (5 rows)
QUERY: SELECT '' AS five, q1, float8(q1) FROM INT8_TBL; SELECT '' AS five, q1, float8(q1) FROM INT8_TBL;
five| q1|float8 five | q1 | float8
----+----------------+-------------------- ------+------------------+----------------------
| 123|123 | 123 | 123
| 123|123 | 123 | 123
|4567890123456789|4.56789012345679e+15 | 4567890123456789 | 4.56789012345679e+15
|4567890123456789|4.56789012345679e+15 | 4567890123456789 | 4.56789012345679e+15
|4567890123456789|4.56789012345679e+15 | 4567890123456789 | 4.56789012345679e+15
(5 rows) (5 rows)
QUERY: SELECT '' AS five, q2, float8(q2) FROM INT8_TBL; SELECT '' AS five, q2, float8(q2) FROM INT8_TBL;
five| q2|float8 five | q2 | float8
----+-----------------+--------------------- ------+-------------------+-----------------------
| 456|456 | 456 | 456
| 4567890123456789|4.56789012345679e+15 | 4567890123456789 | 4.56789012345679e+15
| 123|123 | 123 | 123
| 4567890123456789|4.56789012345679e+15 | 4567890123456789 | 4.56789012345679e+15
|-4567890123456789|-4.56789012345679e+15 | -4567890123456789 | -4.56789012345679e+15
(5 rows) (5 rows)
QUERY: SELECT '' AS five, q1, int8(float8(q1)) AS "two coercions" FROM INT8_TBL; SELECT '' AS five, q1, int8(float8(q1)) AS "two coercions" FROM INT8_TBL;
five| q1| two coercions five | q1 | two coercions
----+----------------+---------------- ------+------------------+------------------
| 123| 123 | 123 | 123
| 123| 123 | 123 | 123
|4567890123456789|4567890123456789 | 4567890123456789 | 4567890123456789
|4567890123456789|4567890123456789 | 4567890123456789 | 4567890123456789
|4567890123456789|4567890123456789 | 4567890123456789 | 4567890123456789
(5 rows) (5 rows)
QUERY: SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL; SELECT '' AS five, 2 * q1 AS "twice int4" FROM INT8_TBL;
five| twice int4 five | twice int4
----+---------------- ------+------------------
| 246 | 246
| 246 | 246
|9135780246913578 | 9135780246913578
|9135780246913578 | 9135780246913578
|9135780246913578 | 9135780246913578
(5 rows) (5 rows)
QUERY: SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL; SELECT '' AS five, q1 * 2 AS "twice int4" FROM INT8_TBL;
five| twice int4 five | twice int4
----+---------------- ------+------------------
| 246 | 246
| 246 | 246
|9135780246913578 | 9135780246913578
|9135780246913578 | 9135780246913578
|9135780246913578 | 9135780246913578
(5 rows) (5 rows)
QUERY: SELECT 'name string'::name = 'name string'::name AS "True"; --
True -- NAME
---- -- all inputs are silently truncated at NAMEDATALEN (32) characters
t --
-- fixed-length by reference
SELECT name 'name string' = name 'name string' AS "True";
True
------
t
(1 row) (1 row)
QUERY: SELECT 'name string'::name = 'name string '::name AS "False"; SELECT name 'name string' = name 'name string ' AS "False";
False False
----- -------
f f
(1 row) (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;'); CREATE TABLE NAME_TBL(f1 name);
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('343f%2a'); INSERT INTO NAME_TBL(f1) VALUES ('ABCDEFGHIJKLMNOP');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('d34aaasdf'); INSERT INTO NAME_TBL(f1) VALUES ('abcdefghijklmnop');
QUERY: INSERT INTO NAME_TBL(f1) VALUES (''); INSERT INTO NAME_TBL(f1) VALUES ('asdfghjkl;');
QUERY: INSERT INTO NAME_TBL(f1) VALUES ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'); INSERT INTO NAME_TBL(f1) VALUES ('343f%2a');
QUERY: SELECT '' AS seven, NAME_TBL.*; INSERT INTO NAME_TBL(f1) VALUES ('d34aaasdf');
seven|f1 INSERT INTO NAME_TBL(f1) VALUES ('');
-----+------------------------------- INSERT INTO NAME_TBL(f1) VALUES ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|ABCDEFGHIJKLMNOP SELECT '' AS seven, NAME_TBL.*;
|abcdefghijklmnop seven | f1
|asdfghjkl; -------+---------------------------------
|343f%2a | ABCDEFGHIJKLMNOP
|d34aaasdf | abcdefghijklmnop
| | asdfghjkl;
|1234567890ABCDEFGHIJKLMNOPQRSTU | 343f%2a
| d34aaasdf
|
| 1234567890ABCDEFGHIJKLMNOPQRSTU
(7 rows) (7 rows)
QUERY: SELECT '' AS six, c.f1 FROM NAME_TBL c WHERE c.f1 <> 'ABCDEFGHIJKLMNOP'; SELECT '' AS six, c.f1 FROM NAME_TBL c WHERE c.f1 <> 'ABCDEFGHIJKLMNOP';
six|f1 six | f1
---+------------------------------- -----+---------------------------------
|abcdefghijklmnop | abcdefghijklmnop
|asdfghjkl; | asdfghjkl;
|343f%2a | 343f%2a
|d34aaasdf | d34aaasdf
| |
|1234567890ABCDEFGHIJKLMNOPQRSTU | 1234567890ABCDEFGHIJKLMNOPQRSTU
(6 rows) (6 rows)
QUERY: SELECT '' AS one, c.f1 FROM NAME_TBL c WHERE c.f1 = 'ABCDEFGHIJKLMNOP'; SELECT '' AS one, c.f1 FROM NAME_TBL c WHERE c.f1 = 'ABCDEFGHIJKLMNOP';
one|f1 one | f1
---+---------------- -----+------------------
|ABCDEFGHIJKLMNOP | ABCDEFGHIJKLMNOP
(1 row) (1 row)
QUERY: SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 < 'ABCDEFGHIJKLMNOP'; SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 < 'ABCDEFGHIJKLMNOP';
three|f1 three | f1
-----+------------------------------- -------+---------------------------------
|343f%2a | 343f%2a
| |
|1234567890ABCDEFGHIJKLMNOPQRSTU | 1234567890ABCDEFGHIJKLMNOPQRSTU
(3 rows) (3 rows)
QUERY: SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 <= 'ABCDEFGHIJKLMNOP'; SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 <= 'ABCDEFGHIJKLMNOP';
four|f1 four | f1
----+------------------------------- ------+---------------------------------
|ABCDEFGHIJKLMNOP | ABCDEFGHIJKLMNOP
|343f%2a | 343f%2a
| |
|1234567890ABCDEFGHIJKLMNOPQRSTU | 1234567890ABCDEFGHIJKLMNOPQRSTU
(4 rows) (4 rows)
QUERY: SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 > 'ABCDEFGHIJKLMNOP'; SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 > 'ABCDEFGHIJKLMNOP';
three|f1 three | f1
-----+---------------- -------+------------------
|abcdefghijklmnop | abcdefghijklmnop
|asdfghjkl; | asdfghjkl;
|d34aaasdf | d34aaasdf
(3 rows) (3 rows)
QUERY: SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 >= 'ABCDEFGHIJKLMNOP'; SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 >= 'ABCDEFGHIJKLMNOP';
four|f1 four | f1
----+---------------- ------+------------------
|ABCDEFGHIJKLMNOP | ABCDEFGHIJKLMNOP
|abcdefghijklmnop | abcdefghijklmnop
|asdfghjkl; | asdfghjkl;
|d34aaasdf | d34aaasdf
(4 rows) (4 rows)
QUERY: SELECT '' AS seven, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*'; SELECT '' AS seven, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*';
seven|f1 seven | f1
-----+------------------------------- -------+---------------------------------
|ABCDEFGHIJKLMNOP | ABCDEFGHIJKLMNOP
|abcdefghijklmnop | abcdefghijklmnop
|asdfghjkl; | asdfghjkl;
|343f%2a | 343f%2a
|d34aaasdf | d34aaasdf
| |
|1234567890ABCDEFGHIJKLMNOPQRSTU | 1234567890ABCDEFGHIJKLMNOPQRSTU
(7 rows) (7 rows)
QUERY: SELECT '' AS zero, c.f1 FROM NAME_TBL c WHERE c.f1 !~ '.*'; SELECT '' AS zero, c.f1 FROM NAME_TBL c WHERE c.f1 !~ '.*';
zero|f1 zero | f1
----+-- ------+----
(0 rows) (0 rows)
QUERY: SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '[0-9]'; SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '[0-9]';
three|f1 three | f1
-----+------------------------------- -------+---------------------------------
|343f%2a | 343f%2a
|d34aaasdf | d34aaasdf
|1234567890ABCDEFGHIJKLMNOPQRSTU | 1234567890ABCDEFGHIJKLMNOPQRSTU
(3 rows) (3 rows)
QUERY: SELECT '' AS two, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*asdf.*'; SELECT '' AS two, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*asdf.*';
two|f1 two | f1
---+---------- -----+------------
|asdfghjkl; | asdfghjkl;
|d34aaasdf | d34aaasdf
(2 rows) (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'); -- OID
QUERY: INSERT INTO OID_TBL(f1) VALUES ('1235'); --
QUERY: INSERT INTO OID_TBL(f1) VALUES ('987'); CREATE TABLE OID_TBL(f1 oid);
QUERY: INSERT INTO OID_TBL(f1) VALUES ('-1040'); INSERT INTO OID_TBL(f1) VALUES ('1234');
QUERY: INSERT INTO OID_TBL(f1) VALUES (''); INSERT INTO OID_TBL(f1) VALUES ('1235');
QUERY: INSERT INTO OID_TBL(f1) VALUES ('asdfasd'); 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" ERROR: pg_atoi: error in "asdfasd": can't parse "asdfasd"
QUERY: SELECT '' AS five, OID_TBL.*; SELECT '' AS five, OID_TBL.*;
five| f1 five | f1
----+----- ------+-------
| 1234 | 1234
| 1235 | 1235
| 987 | 987
|-1040 | -1040
| 0 | 0
(5 rows) (5 rows)
QUERY: SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 = '1234'::oid; SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 = oid '1234';
one| f1 one | f1
---+---- -----+------
|1234 | 1234
(1 row) (1 row)
QUERY: SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <> '1234'; SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <> '1234';
four| f1 four | f1
----+----- ------+-------
| 1235 | 1235
| 987 | 987
|-1040 | -1040
| 0 | 0
(4 rows) (4 rows)
QUERY: SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <= '1234'; SELECT '' AS four, o.* FROM OID_TBL o WHERE o.f1 <= '1234';
four| f1 four | f1
----+----- ------+-------
| 1234 | 1234
| 987 | 987
|-1040 | -1040
| 0 | 0
(4 rows) (4 rows)
QUERY: SELECT '' AS three, o.* FROM OID_TBL o WHERE o.f1 < '1234'; SELECT '' AS three, o.* FROM OID_TBL o WHERE o.f1 < '1234';
three| f1 three | f1
-----+----- -------+-------
| 987 | 987
|-1040 | -1040
| 0 | 0
(3 rows) (3 rows)
QUERY: SELECT '' AS two, o.* FROM OID_TBL o WHERE o.f1 >= '1234'; SELECT '' AS two, o.* FROM OID_TBL o WHERE o.f1 >= '1234';
two| f1 two | f1
---+---- -----+------
|1234 | 1234
|1235 | 1235
(2 rows) (2 rows)
QUERY: SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 > '1234'; SELECT '' AS one, o.* FROM OID_TBL o WHERE o.f1 > '1234';
one| f1 one | f1
---+---- -----+------
|1235 | 1235
(1 row) (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 -- TEXT
---- --
t SELECT text 'this is a text string' = text 'this is a text string' AS true;
true
------
t
(1 row) (1 row)
QUERY: SELECT 'this is a text string'::text = 'this is a text strin'::text AS false; SELECT text 'this is a text string' = text 'this is a text strin' AS false;
false false
----- -------
f f
(1 row) (1 row)
QUERY: CREATE TABLE TEXT_TBL (f1 text); CREATE TABLE TEXT_TBL (f1 text);
QUERY: INSERT INTO TEXT_TBL VALUES ('doh!'); INSERT INTO TEXT_TBL VALUES ('doh!');
QUERY: INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor'); INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor');
QUERY: SELECT '' AS two, * FROM TEXT_TBL; SELECT '' AS two, * FROM TEXT_TBL;
two|f1 two | f1
---+----------------- -----+-------------------
|doh! | doh!
|hi de ho neighbor | hi de ho neighbor
(2 rows) (2 rows)
QUERY: CREATE TABLE VARCHAR_TBL(f1 varchar(1)); --
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('a'); -- VARCHAR
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('A'); --
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('1'); CREATE TABLE VARCHAR_TBL(f1 varchar(1));
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES (2); INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('3'); INSERT INTO VARCHAR_TBL (f1) VALUES ('A');
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES (''); -- any of the following three input formats are acceptable
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('cd'); INSERT INTO VARCHAR_TBL (f1) VALUES ('1');
QUERY: SELECT '' AS seven, VARCHAR_TBL.*; INSERT INTO VARCHAR_TBL (f1) VALUES (2);
seven|f1 INSERT INTO VARCHAR_TBL (f1) VALUES ('3');
-----+-- -- zero-length char
|a INSERT INTO VARCHAR_TBL (f1) VALUES ('');
|A -- try varchar's of greater than 1 length
|1 INSERT INTO VARCHAR_TBL (f1) VALUES ('cd');
|2 SELECT '' AS seven, VARCHAR_TBL.*;
|3 seven | f1
| -------+----
|c | a
| A
| 1
| 2
| 3
|
| c
(7 rows) (7 rows)
QUERY: SELECT '' AS six, c.* SELECT '' AS six, c.*
FROM VARCHAR_TBL c FROM VARCHAR_TBL c
WHERE c.f1 <> 'a'; WHERE c.f1 <> 'a';
six|f1 six | f1
---+-- -----+----
|A | A
|1 | 1
|2 | 2
|3 | 3
| |
|c | c
(6 rows) (6 rows)
QUERY: SELECT '' AS one, c.* SELECT '' AS one, c.*
FROM VARCHAR_TBL c FROM VARCHAR_TBL c
WHERE c.f1 = 'a'; WHERE c.f1 = 'a';
one|f1 one | f1
---+-- -----+----
|a | a
(1 row) (1 row)
QUERY: SELECT '' AS five, c.* SELECT '' AS five, c.*
FROM VARCHAR_TBL c FROM VARCHAR_TBL c
WHERE c.f1 < 'a'; WHERE c.f1 < 'a';
five|f1 five | f1
----+-- ------+----
|A | A
|1 | 1
|2 | 2
|3 | 3
| |
(5 rows) (5 rows)
QUERY: SELECT '' AS six, c.* SELECT '' AS six, c.*
FROM VARCHAR_TBL c FROM VARCHAR_TBL c
WHERE c.f1 <= 'a'; WHERE c.f1 <= 'a';
six|f1 six | f1
---+-- -----+----
|a | a
|A | A
|1 | 1
|2 | 2
|3 | 3
| |
(6 rows) (6 rows)
QUERY: SELECT '' AS one, c.* SELECT '' AS one, c.*
FROM VARCHAR_TBL c FROM VARCHAR_TBL c
WHERE c.f1 > 'a'; WHERE c.f1 > 'a';
one|f1 one | f1
---+-- -----+----
|c | c
(1 row) (1 row)
QUERY: SELECT '' AS two, c.* SELECT '' AS two, c.*
FROM VARCHAR_TBL c FROM VARCHAR_TBL c
WHERE c.f1 >= 'a'; WHERE c.f1 >= 'a';
two|f1 two | f1
---+-- -----+----
|a | a
|c | c
(2 rows) (2 rows)
QUERY: DROP TABLE VARCHAR_TBL; DROP TABLE VARCHAR_TBL;
QUERY: CREATE TABLE VARCHAR_TBL(f1 varchar(4)); --
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('a'); -- Now test longer arrays of char
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('ab'); --
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd'); CREATE TABLE VARCHAR_TBL(f1 varchar(4));
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde'); INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
QUERY: SELECT '' AS four, VARCHAR_TBL.*; INSERT INTO VARCHAR_TBL (f1) VALUES ('ab');
four|f1 INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd');
----+---- INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
|a SELECT '' AS four, VARCHAR_TBL.*;
|ab four | f1
|abcd ------+------
|abcd | a
| ab
| abcd
| abcd
(4 rows) (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