--
-- NUMERIC
--
SELECT sqrt('-1'::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:5: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(53): ERROR:  cannot take square root of a negative number



SELECT sqrt('-inf'::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:6: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(53): ERROR:  cannot take square root of a negative number



SELECT ln('0'::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:8: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(38): ERROR:  cannot take logarithm of zero



SELECT ln('-1'::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:9: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(51): ERROR:  cannot take logarithm of a negative number



SELECT ln('-inf'::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:10: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(51): ERROR:  cannot take logarithm of a negative number



-- ******************************
-- * miscellaneous checks for things that have been broken in the past...
-- ******************************
-- Check conversion to integers
SELECT (-9223372036854775808.4)::int8; -- ok
       column0        
----------------------
 -9223372036854775808
(1 row)

SELECT 9223372036854775807.5::int8; -- should fail
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:17: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(28): ERROR:  bigint out of range



SELECT (-2147483648.4)::int4; -- ok
   column0   
-------------
 -2147483648
(1 row)

SELECT 2147483647.4::int4; -- ok
  column0   
------------
 2147483647
(1 row)

SELECT 2147483647.5::int4; -- should fail
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:20: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(29): ERROR:  integer out of range



SELECT (-32768.4)::int2; -- ok
 column0 
---------
  -32768
(1 row)

SELECT 32767.4::int2; -- ok
 column0 
---------
   32767
(1 row)

SELECT 32767.5::int2; -- should fail
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:23: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(30): ERROR:  smallint out of range



-- Check inf/nan conversion behavior
SELECT '42'::int2::numeric;
 column0 
---------
      42
(1 row)

SELECT 'NaN'::numeric::int2;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:27: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(39): ERROR:  cannot convert NaN to smallint



SELECT 'Infinity'::numeric::int2;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:28: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(44): ERROR:  cannot convert infinity to smallint



SELECT '-Infinity'::numeric::int2;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:29: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(44): ERROR:  cannot convert infinity to smallint



SELECT 'NaN'::numeric::int4;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:30: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(38): ERROR:  cannot convert NaN to integer



SELECT 'Infinity'::numeric::int4;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:31: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(43): ERROR:  cannot convert infinity to integer



SELECT '-Infinity'::numeric::int4;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:32: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(43): ERROR:  cannot convert infinity to integer



SELECT 'NaN'::numeric::int8;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:33: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(37): ERROR:  cannot convert NaN to bigint



SELECT 'Infinity'::numeric::int8;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:34: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(42): ERROR:  cannot convert infinity to bigint



SELECT '-Infinity'::numeric::int8;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:35: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(42): ERROR:  cannot convert infinity to bigint



-- Simple check that ceil(), floor(), and round() work correctly
-- Check rounding, it should round ties away from zero.
-- Testing for width_bucket(). For convenience, we test both the
-- numeric and float8 versions of the function in this file.
-- errors
SELECT width_bucket(5.0, 3.0, 4.0, 0);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:43: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(40): ERROR:  count must be greater than zero



SELECT width_bucket(5.0, 3.0, 4.0, -5);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:44: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(40): ERROR:  count must be greater than zero



SELECT width_bucket(3.5, 3.0, 3.0, 888);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:45: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(45): ERROR:  lower bound cannot equal upper bound



SELECT width_bucket(5.0::float8, 3.0::float8, 4.0::float8, 0);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:46: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(40): ERROR:  count must be greater than zero



SELECT width_bucket(5.0::float8, 3.0::float8, 4.0::float8, -5);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:47: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(40): ERROR:  count must be greater than zero



SELECT width_bucket(3.5::float8, 3.0::float8, 3.0::float8, 888);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:48: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(45): ERROR:  lower bound cannot equal upper bound



--
-- TO_CHAR()
--
SELECT to_char('100'::numeric, 'FM999.9');
 to_char 
---------
 100.
(1 row)

SELECT to_char('100'::numeric, 'FM999.');
 to_char 
---------
 100
(1 row)

SELECT to_char('100'::numeric, 'FM999');
 to_char 
---------
 100
(1 row)

-- Check parsing of literal text in a format string
SELECT to_char('100'::numeric, 'foo999');
 to_char 
---------
 foo 100
(1 row)

SELECT to_char('100'::numeric, 'f\oo999');
 to_char  
----------
 f\oo 100
(1 row)

SELECT to_char('100'::numeric, 'f\\oo999');
  to_char  
-----------
 f\\oo 100
(1 row)

SELECT to_char('100'::numeric, 'f\"oo999');
 to_char  
----------
 f"oo 100
(1 row)

SELECT to_char('100'::numeric, 'f\\"oo999');
  to_char  
-----------
 f\"oo 100
(1 row)

SELECT to_char('100'::numeric, 'f"ool"999');
 to_char  
----------
 fool 100
(1 row)

SELECT to_char('100'::numeric, 'f"\ool"999');
 to_char  
----------
 fool 100
(1 row)

SELECT to_char('100'::numeric, 'f"\\ool"999');
  to_char  
-----------
 f\ool 100
(1 row)

SELECT to_char('100'::numeric, 'f"ool\"999');
 to_char  
----------
 fool"999
(1 row)

SELECT to_char('100'::numeric, 'f"ool\\"999');
  to_char  
-----------
 fool\ 100
(1 row)

-- TO_NUMBER()
--
SELECT to_number('-34,338,492', '99G999G999');
 to_number 
-----------
 -34338492
(1 row)

SELECT to_number('-34,338,492.654,878', '99G999G999D999G999');
    to_number     
------------------
 -34338492.654878
(1 row)

SELECT to_number('<564646.654564>', '999999.999999PR');
   to_number    
----------------
 -564646.654564
(1 row)

SELECT to_number('0.00001-', '9.999999S');
 to_number 
-----------
  -0.00001
(1 row)

SELECT to_number('5.01-', 'FM9.999999S');
 to_number 
-----------
     -5.01
(1 row)

SELECT to_number('5.01-', 'FM9.999999MI');
 to_number 
-----------
     -5.01
(1 row)

SELECT to_number('5 4 4 4 4 8 . 7 8', '9 9 9 9 9 9 . 9 9');
 to_number 
-----------
 544448.78
(1 row)

SELECT to_number('.01', 'FM9.99');
 to_number 
-----------
      0.01
(1 row)

SELECT to_number('.0', '99999999.99999999');
 to_number 
-----------
       0.0
(1 row)

SELECT to_number('.-01', 'S99.99');
 to_number 
-----------
     -0.01
(1 row)

SELECT to_number('.01-', '99.99S');
 to_number 
-----------
     -0.01
(1 row)

SELECT to_number(' . 0 1-', ' 9 9 . 9 9 S');
 to_number 
-----------
     -0.01
(1 row)

SELECT to_number('34,50','999,99');
 to_number 
-----------
      3450
(1 row)

SELECT to_number('123,000','999G');
 to_number 
-----------
       123
(1 row)

SELECT to_number('123456','999G999');
 to_number 
-----------
    123456
(1 row)

SELECT to_number('$1234.56','L9,999.99');
 to_number 
-----------
   1234.56
(1 row)

SELECT to_number('$1234.56','L99,999.99');
 to_number 
-----------
   1234.56
(1 row)

SELECT to_number('$1,234.56','L99,999.99');
 to_number 
-----------
   1234.56
(1 row)

SELECT to_number('1234.56','L99,999.99');
 to_number 
-----------
   1234.56
(1 row)

SELECT to_number('1,234.56','L99,999.99');
 to_number 
-----------
   1234.56
(1 row)

SELECT to_number('42nd', '99th');
 to_number 
-----------
        42
(1 row)

--
-- Tests for raising to non-integer powers
--
-- invalid inputs
select 0.0 ^ (-12.34);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:96: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(53): ERROR:  zero raised to a negative power is undefined



select (-12.34) ^ 1.2;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:97: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(80): ERROR:  a negative number raised to a non-integer power yields a complex result



--
-- Tests for LN()
--
-- Invalid inputs
select ln(-12.34);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:104: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(51): ERROR:  cannot take logarithm of a negative number



select ln(0.0);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:105: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(38): ERROR:  cannot take logarithm of zero



--
-- Tests for LOG() (base 10)
--
-- invalid inputs
select log(-12.34);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:112: Status: GENERIC_ERROR
Issues: 
<main>: Error: Type annotation, code: 1030
    <main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At tuple, At tuple, At tuple, At function: PgSetItem, At tuple
        <main>: Error: At tuple
            <main>:1:1: Error: At tuple, At function: PgResultItem, At lambda
                <main>:1:8: Error: At function: PgCall
                    <main>:1:8: Error: Function log has no implementation

select log(0.0);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:113: Status: GENERIC_ERROR
Issues: 
<main>: Error: Type annotation, code: 1030
    <main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At tuple, At tuple, At tuple, At function: PgSetItem, At tuple
        <main>: Error: At tuple
            <main>:1:1: Error: At tuple, At function: PgResultItem, At lambda
                <main>:1:8: Error: At function: PgCall
                    <main>:1:8: Error: Function log has no implementation

--
-- Tests for pg_lsn()
--
SELECT pg_lsn(23783416::numeric);
  pg_lsn   
-----------
 0/16AE7F8
(1 row)

SELECT pg_lsn(0::numeric);
 pg_lsn 
--------
 0/0
(1 row)

SELECT pg_lsn(-1::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:120: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(28): ERROR:  pg_lsn out of range



SELECT pg_lsn(18446744073709551616::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:121: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(28): ERROR:  pg_lsn out of range



SELECT pg_lsn('NaN'::numeric);
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/numeric.sql:122: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(37): ERROR:  cannot convert NaN to pg_lsn



