-- ODBC-pre7.sql
--
-- Use float8 rather than float(15) since pre-7.0 does not accept
-- SQL92 type names of this form in the CREATE FUNCTION command.
--

--
-- Character string manipulation
--

--
-- Compatibility functions for pre-v7.0.
-- These should be applied to pre-v7.0 databases
-- when using the v7.0 ODBC driver.
--

CREATE FUNCTION char_length(text)
    RETURNS integer
    AS 'SELECT length(CAST($1 AS text))'
    LANGUAGE 'SQL';

CREATE FUNCTION pow(float8)
    RETURNS float8
    AS 'SELECT dpow($1)'
    LANGUAGE 'SQL';

--
-- Extensions for ODBC compliance in v7.0.
-- In the current driver, ODBC functions must map directly into a
-- Postgres function. So in some cases we must create a compatible
-- function.
--

CREATE FUNCTION ascii(text)
    RETURNS integer
    AS '_OBJWD_/odbc_DLSUFFIX_', 'ascii'
    LANGUAGE 'C';

CREATE FUNCTION ichar(integer)
    RETURNS char(1)
    AS '_OBJWD_/odbc_DLSUFFIX_', 'ichar'
    LANGUAGE 'C';

CREATE FUNCTION insert(text, integer, integer, text)
    RETURNS text
    AS '_OBJWD_/odbc_DLSUFFIX_', 'insert'
    LANGUAGE 'C';

-- replace all occurences of $2 with $3
CREATE FUNCTION replace(text, text, text)
    RETURNS text
    AS '_OBJWD_/odbc_DLSUFFIX_', 'replace'
    LANGUAGE 'C';

-- return the string repeated n times
CREATE FUNCTION repeat(text, integer)
    RETURNS text
    AS '_OBJWD_/odbc_DLSUFFIX_', 'repeat'
    LANGUAGE 'C';

--
-- Mathematical functions for pre-v7.0
--

CREATE FUNCTION dround(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dround'
    LANGUAGE 'C';

CREATE FUNCTION round(float8)
    RETURNS float8
    AS 'SELECT dround($1)'
    LANGUAGE 'SQL';

--
-- Math functions present in backend, but not in catalog for v7.0
--

CREATE FUNCTION acos(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dacos'
    LANGUAGE 'C';

CREATE FUNCTION asin(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dasin'
    LANGUAGE 'C';

CREATE FUNCTION atan(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'datan'
    LANGUAGE 'C';

CREATE FUNCTION atan2(float8,float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'datan2'
    LANGUAGE 'C';

CREATE FUNCTION cos(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dcos'
    LANGUAGE 'C';

CREATE FUNCTION cot(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dcot'
    LANGUAGE 'C';

CREATE FUNCTION sin(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dsin'
    LANGUAGE 'C';

CREATE FUNCTION dtan(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dtan'
    LANGUAGE 'C';

CREATE FUNCTION degrees(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'degrees'
    LANGUAGE 'C';

CREATE FUNCTION pi()
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'dpi'
    LANGUAGE 'C';

CREATE FUNCTION radians(float8)
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'radians'
    LANGUAGE 'C';

-- random number generator currently requires RAND_MAX be available
CREATE FUNCTION random()
    RETURNS float8
    AS '_OBJWD_/odbc_DLSUFFIX_', 'drandom'
    LANGUAGE 'C';

CREATE FUNCTION truncate(numeric,integer)
    RETURNS numeric
    AS 'SELECT trunc($1, $2)'
    LANGUAGE 'SQL';

--
-- Date/time functions for v7.0
--

CREATE FUNCTION interval_mul(interval,float8)
    RETURNS interval
    AS '_OBJWD_/odbc_DLSUFFIX_'
    LANGUAGE 'C';

CREATE OPERATOR * (
    LEFTARG = interval,
    RIGHTARG = float8,
    PROCEDURE = interval_mul
);




