From 72449875bf38faf25b616919d23cab820722e2f1 Mon Sep 17 00:00:00 2001 From: "centos7.8" Date: Mon, 26 Feb 2024 01:24:59 -0800 Subject: [PATCH] add char byte semantic support --- contrib/whale/Makefile | 3 + contrib/whale/expected/charbyte.out | 382 ++++++++ contrib/whale/include/plugin_funcs.h | 111 +++ contrib/whale/include/plugin_parser/kwlist.h | 1 + contrib/whale/parallel_schedule_whale | 4 +- contrib/whale/plugin_funcs.cpp | 922 +++++++++++++++++++ contrib/whale/plugin_parser/gram.y | 33 +- contrib/whale/sql/charbyte.sql | 122 +++ contrib/whale/sql_script/base.sql | 542 ++++++++++- 9 files changed, 2115 insertions(+), 5 deletions(-) create mode 100644 contrib/whale/expected/charbyte.out create mode 100644 contrib/whale/include/plugin_funcs.h create mode 100644 contrib/whale/plugin_funcs.cpp create mode 100644 contrib/whale/sql/charbyte.sql diff --git a/contrib/whale/Makefile b/contrib/whale/Makefile index e53a9b3f..5b2c6183 100644 --- a/contrib/whale/Makefile +++ b/contrib/whale/Makefile @@ -113,6 +113,9 @@ plugin_utility.o: plugin_utility.cpp OBJS += tablecmds.o tablecmds.o: tablecmds.cpp +OBJS += plugin_funcs.o +plugin_funcs.o: plugin_funcs.cpp + EXTENSION = whale #a dummy testcase to let 'make check' can run, currently I have no idea how to fix this... REGRESS:=dummy diff --git a/contrib/whale/expected/charbyte.out b/contrib/whale/expected/charbyte.out new file mode 100644 index 00000000..f8b84155 --- /dev/null +++ b/contrib/whale/expected/charbyte.out @@ -0,0 +1,382 @@ +-- test oracle compatibility char byte semantic +drop table if exists test_charbyte1; +NOTICE: table "test_charbyte1" does not exist, skipping +create table test_charbyte1 (id int, name char (4 char)); +insert into test_charbyte1 values(1, 'abcd'); +insert into test_charbyte1 values(2, '中国天津'); +insert into test_charbyte1 values(3, 'abcde'); +ERROR: value too long for type character(4) +CONTEXT: referenced column: name +insert into test_charbyte1 values(4, '中国ab'); +select * from test_charbyte1 order by id; + id | name +----+---------- + 1 | abcd + 2 | 中国天津 + 4 | 中国ab +(3 rows) + +drop table test_charbyte1; +drop table if exists test_charbyte2; +NOTICE: table "test_charbyte2" does not exist, skipping +create table test_charbyte2 (id int, name char (4 byte)); +insert into test_charbyte2 values(1, 'abcd'); +insert into test_charbyte2 values(2, '中国天津'); +ERROR: value too long for type character(4) +CONTEXT: referenced column: name +insert into test_charbyte2 values(3, 'abcde'); +ERROR: value too long for type character(4) +CONTEXT: referenced column: name +insert into test_charbyte2 values(4, '中国ab'); +ERROR: value too long for type character(4) +CONTEXT: referenced column: name +select * from test_charbyte2 order by id; + id | name +----+------ + 1 | abcd +(1 row) + +drop table test_charbyte2; +drop table if exists test_charbyte3; +NOTICE: table "test_charbyte3" does not exist, skipping +create table test_charbyte3 (id int, name varchar (4 char)); +insert into test_charbyte3 values(1, 'abcd'); +insert into test_charbyte3 values(2, '中国天津'); +insert into test_charbyte3 values(3, 'abcde'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +insert into test_charbyte3 values(4, '中国ab'); +select * from test_charbyte3 order by id; + id | name +----+---------- + 1 | abcd + 2 | 中国天津 + 4 | 中国ab +(3 rows) + +drop table test_charbyte3; +drop table if exists test_charbyte4; +NOTICE: table "test_charbyte4" does not exist, skipping +create table test_charbyte4 (id int, name varchar (4 byte)); +insert into test_charbyte4 values(1, 'abcd'); +insert into test_charbyte4 values(2, '中国天津'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +insert into test_charbyte4 values(3, 'abcde'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +insert into test_charbyte4 values(4, '中国ab'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +select * from test_charbyte4 order by id; + id | name +----+------ + 1 | abcd +(1 row) + +drop table test_charbyte4; +drop table if exists test_charbyte5; +NOTICE: table "test_charbyte5" does not exist, skipping +create table test_charbyte5 (id int, name varchar2 (4 char)); +insert into test_charbyte5 values(1, 'abcd'); +insert into test_charbyte5 values(2, '中国天津'); +insert into test_charbyte5 values(3, 'abcde'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +insert into test_charbyte5 values(4, '中国ab'); +select * from test_charbyte5 order by id; + id | name +----+---------- + 1 | abcd + 2 | 中国天津 + 4 | 中国ab +(3 rows) + +drop table test_charbyte5; +drop table if exists test_charbyte6; +NOTICE: table "test_charbyte6" does not exist, skipping +create table test_charbyte6 (id int, name varchar2 (4 byte)); +insert into test_charbyte6 values(1, 'abcd'); +insert into test_charbyte6 values(2, '中国天津'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +insert into test_charbyte6 values(3, 'abcde'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +insert into test_charbyte6 values(4, '中国ab'); +ERROR: value too long for type character varying(4) +CONTEXT: referenced column: name +select * from test_charbyte6 order by id; + id | name +----+------ + 1 | abcd +(1 row) + +drop table test_charbyte6; +drop table if exists my_table1; +NOTICE: table "my_table1" does not exist, skipping +create table my_table1 (id int, duration char(100 char)); +insert into my_table1 values(1, '1 day 2 hours'); +select duration::interval from my_table1 where id=1; + duration +----------------- + @ 1 day 2 hours +(1 row) + +insert into my_table1 values(2, '2003-05-08 12:35:29'); +select duration::smalldatetime from my_table1 where id=2; + duration +-------------------------- + Thu May 08 12:35:00 2003 +(1 row) + +select duration::text from my_table1; + duration +------------------------------------------------------------------------------------------------------ + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::clob from my_table1; + duration +------------------------------------------------------------------------------------------------------ + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::varchar from my_table1; + duration +------------------------------------------------------------------------------------------------------ + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::nvarchar2 from my_table1; + duration +------------------------------------------------------------------------------------------------------ + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::char from my_table1; + duration +---------- + 1 + 2 +(2 rows) + +select duration::name from my_table1; + duration +--------------------- + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +insert into my_table1 values(3, ''); +select duration::xml from my_table1 where id=3; + duration +------------------------------------------------------------------------------------------------------ + +(1 row) + +insert into my_table1 values(4, '123456789'); +select duration::int8 from my_table1 where id=4; + duration +----------- + 123456789 +(1 row) + +select duration::date from my_table1 where id=2; + duration +-------------------------- + Sat Jan 01 00:00:00 2000 +(1 row) + +select duration::numeric from my_table1 where id=4; + duration +----------- + 123456789 +(1 row) + +select duration::int4 from my_table1 where id=4; + duration +----------- + 123456789 +(1 row) + +select duration::timestamp from my_table1 where id=2; + duration +--------------------------------- + Sat Jan 01 00:00:00.001223 2000 +(1 row) + +select duration::float4 from my_table1 where id=4; + duration +------------- + 1.23457e+08 +(1 row) + +select duration::float8 from my_table1 where id=4; + duration +----------- + 123456789 +(1 row) + +drop table my_table1; +drop table if exists my_table2; +NOTICE: table "my_table2" does not exist, skipping +create table my_table2 (id int, duration varchar(100 char)); +insert into my_table2 values(1, '1 day 2 hours'); +select duration::interval from my_table2; + duration +----------------- + @ 1 day 2 hours +(1 row) + +insert into my_table2 values(2, '2003-05-08 12:35:29'); +select duration::smalldatetime from my_table2 where id=2; + duration +-------------------------- + Thu May 08 12:35:00 2003 +(1 row) + +select duration::text from my_table2; + duration +--------------------- + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::clob from my_table2; + duration +--------------------- + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::varchar from my_table2; + duration +--------------------- + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::nvarchar2 from my_table2; + duration +--------------------- + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +select duration::char from my_table2; + duration +---------- + 1 + 2 +(2 rows) + +select duration::name from my_table2; + duration +--------------------- + 1 day 2 hours + 2003-05-08 12:35:29 +(2 rows) + +insert into my_table2 values(3, ''); +select duration::xml from my_table2 where id=3; + duration +---------- + +(1 row) + +insert into my_table2 values(4, '123456789'); +select duration::int8 from my_table2 where id=4; + duration +----------- + 123456789 +(1 row) + +select duration::date from my_table2 where id=2; + duration +-------------------------- + Sat Jan 01 00:00:00 2000 +(1 row) + +select duration::numeric from my_table2 where id=4; + duration +----------- + 123456789 +(1 row) + +select duration::int4 from my_table2 where id=4; + duration +----------- + 123456789 +(1 row) + +select duration::timestamp from my_table2 where id=2; + duration +--------------------------------- + Sat Jan 01 00:00:00.001223 2000 +(1 row) + +select duration::float4 from my_table2 where id=4; + duration +------------- + 1.23457e+08 +(1 row) + +select duration::float8 from my_table2 where id=4; + duration +----------- + 123456789 +(1 row) + +drop table my_table2; +drop table if exists my_table3; +NOTICE: table "my_table3" does not exist, skipping +create table my_table3 (city char (10 char)); +insert into my_table3 values('beijing'); +insert into my_table3 values('tianjin'); +insert into my_table3 values('shanghai'); +select * from my_table3; + city +------------ + beijing + tianjin + shanghai +(3 rows) + +update my_table3 set city = 'guangzhou' where city = 'shanghai'; +select * from my_table3; + city +------------ + beijing + tianjin + guangzhou +(3 rows) + +delete from my_table3 where city = 'guangzhou'; +select * from my_table3; + city +------------ + beijing + tianjin +(2 rows) + +update my_table3 set city = 'xian' where city > 'beijing'; +select * from my_table3; + city +------------ + beijing + xian +(2 rows) + +delete from my_table3 where city ~ 'bei'; +select * from my_table3; + city +------------ + xian +(1 row) + +drop table my_table3; diff --git a/contrib/whale/include/plugin_funcs.h b/contrib/whale/include/plugin_funcs.h new file mode 100644 index 00000000..9065af17 --- /dev/null +++ b/contrib/whale/include/plugin_funcs.h @@ -0,0 +1,111 @@ +#ifndef PLUGIN_FUNCS_H +#define PLUGIN_FUNCS_H + +#if defined _WIN32 || defined __CYGWIN__ +#ifdef BUILDING_DLL + #ifdef __GNUC__ + #define DLL_PUBLIC __attribute__ ((dllexport)) + #else + #define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. + #endif + #else + #ifdef __GNUC__ + #define DLL_PUBLIC __attribute__ ((dllimport)) + #else + #define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. + #endif + #endif + #define DLL_LOCAL +#else +#if __GNUC__ >= 4 +#define DLL_PUBLIC __attribute__ ((visibility ("default"))) +#define DLL_LOCAL __attribute__ ((visibility ("hidden"))) +#else +#define DLL_PUBLIC + #define DLL_LOCAL +#endif +#endif + +#define PG_FUNCTION_INFO_V1_PUBLIC(funcname) \ + extern "C" PGDLLEXPORT DLL_PUBLIC const Pg_finfo_record* CppConcat(pg_finfo_, funcname)(void); \ + const Pg_finfo_record* CppConcat(pg_finfo_, funcname)(void) \ + { \ + static const Pg_finfo_record my_finfo = {1}; \ + return &my_finfo; \ + } \ + extern int no_such_variable + +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcin(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcout(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcrecv(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcsend(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharctypmodin(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharctypmodout(PG_FUNCTION_ARGS); + +extern "C" DLL_PUBLIC PGDLLEXPORT Datum rtrim1c(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum text_charc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_name(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum texttoxmlc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_int8(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_date(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_numeric(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_int4(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_timestamp(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharctoset(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_float4(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_float8(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int4_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum char_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum name_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum network_showc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum booltextc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum date_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int1_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int2_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int8_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum float4_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum float8_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum numeric_bpcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum settobpcharc(PG_FUNCTION_ARGS); + + +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharcin(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharcout(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharcrecv(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharcsend(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharctypmodin(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharctypmodout(PG_FUNCTION_ARGS); + +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharc_date(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharc_numeric(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharc_int4(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharc_int8(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharctoset(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharc_float4(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum varcharc_float8(PG_FUNCTION_ARGS); + +extern "C" DLL_PUBLIC PGDLLEXPORT Datum date_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum timestamp_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int2_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int4_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int8_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum numeric_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum float4_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum float8_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum int1_varcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum settovarcharc(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum name_textc(PG_FUNCTION_ARGS); + +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharceq(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcregexeq(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcregexne(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcne(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharclt(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcle(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcgt(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharcge(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharccmp(PG_FUNCTION_ARGS); +extern "C" DLL_PUBLIC PGDLLEXPORT Datum bpcharc_sortsupport(PG_FUNCTION_ARGS); +#endif diff --git a/contrib/whale/include/plugin_parser/kwlist.h b/contrib/whale/include/plugin_parser/kwlist.h index bad53b12..93b35910 100644 --- a/contrib/whale/include/plugin_parser/kwlist.h +++ b/contrib/whale/include/plugin_parser/kwlist.h @@ -87,6 +87,7 @@ PG_KEYWORD("both", BOTH, RESERVED_KEYWORD) PG_KEYWORD("bucketcnt", BUCKETCNT, COL_NAME_KEYWORD) PG_KEYWORD("buckets", BUCKETS, RESERVED_KEYWORD) PG_KEYWORD("by", BY, UNRESERVED_KEYWORD) +PG_KEYWORD("byte", BYTE_P, COL_NAME_KEYWORD) PG_KEYWORD("byteawithoutorder", BYTEAWITHOUTORDER, COL_NAME_KEYWORD) PG_KEYWORD("byteawithoutorderwithequal", BYTEAWITHOUTORDERWITHEQUAL, COL_NAME_KEYWORD) PG_KEYWORD("cache", CACHE, UNRESERVED_KEYWORD) diff --git a/contrib/whale/parallel_schedule_whale b/contrib/whale/parallel_schedule_whale index e31b1bf7..82b6f8aa 100644 --- a/contrib/whale/parallel_schedule_whale +++ b/contrib/whale/parallel_schedule_whale @@ -3,4 +3,6 @@ test: gms_alert_session_A gms_alert_session_B gms_alert_session_C test: gms_output gms_utility gms_random test: gms_pipe_session_A gms_pipe_session_B gms_pipe test: aggregates charlen nlssort nvarchar2 orafce orafce2 regexp_func to_date_with_timezone -test: varchar2 files plvdate_test plvstr_test \ No newline at end of file +test: varchar2 files plvdate_test plvstr_test +test: charbyte + diff --git a/contrib/whale/plugin_funcs.cpp b/contrib/whale/plugin_funcs.cpp new file mode 100644 index 00000000..6a84da6a --- /dev/null +++ b/contrib/whale/plugin_funcs.cpp @@ -0,0 +1,922 @@ + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/hash.h" +#include "access/tuptoaster.h" +#include "libpq/pqformat.h" +#include "nodes/nodeFuncs.h" +#include "utils/array.h" +#include "utils/builtins.h" +#include "plugin_mb/pg_wchar.h" +#include "utils/sortsupport.h" +#include "vecexecutor/vectorbatch.h" +#include "utils/pg_locale.h" + +#include "miscadmin.h" +#include "plugin_funcs.h" +#include "common/int.h" +#include "utils/numeric.h" +#include "catalog/pg_type.h" +#include "utils/biginteger.h" +#include "utils/int8.h" + + +/* + * The functions below are for bpcharc and varcharc type use + * + * In oracle, create table test (a char(4)) use byte semantic + * create table test (a char(4 char)) use char semantic. + * bpcharc type is for char type char semantic + * varcharc type is for varchar type char semantic + */ +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcin); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcout); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcrecv); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcsend); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharctypmodin); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharctypmodout); + +PG_FUNCTION_INFO_V1_PUBLIC(bpcharceq); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcregexeq); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcregexne); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcne); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharclt); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcle); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcgt); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharcge); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharccmp); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_sortsupport); + +PG_FUNCTION_INFO_V1_PUBLIC(rtrim1c); +PG_FUNCTION_INFO_V1_PUBLIC(text_charc); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_name); +PG_FUNCTION_INFO_V1_PUBLIC(texttoxmlc); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_int8); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_date); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_numeric); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_int4); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_timestamp); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharctoset); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_float4); +PG_FUNCTION_INFO_V1_PUBLIC(bpcharc_float8); +PG_FUNCTION_INFO_V1_PUBLIC(int4_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(char_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(name_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(network_showc); +PG_FUNCTION_INFO_V1_PUBLIC(booltextc); +PG_FUNCTION_INFO_V1_PUBLIC(date_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(int1_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(int2_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(int8_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(float4_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(float8_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(numeric_bpcharc); +PG_FUNCTION_INFO_V1_PUBLIC(settobpcharc); + +PG_FUNCTION_INFO_V1_PUBLIC(varcharcin); +PG_FUNCTION_INFO_V1_PUBLIC(varcharcout); +PG_FUNCTION_INFO_V1_PUBLIC(varcharcrecv); +PG_FUNCTION_INFO_V1_PUBLIC(varcharcsend); +PG_FUNCTION_INFO_V1_PUBLIC(varcharctypmodin); +PG_FUNCTION_INFO_V1_PUBLIC(varcharctypmodout); + +PG_FUNCTION_INFO_V1_PUBLIC(varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(varcharc_date); +PG_FUNCTION_INFO_V1_PUBLIC(varcharc_numeric); +PG_FUNCTION_INFO_V1_PUBLIC(varcharc_int4); +PG_FUNCTION_INFO_V1_PUBLIC(varcharc_int8); +PG_FUNCTION_INFO_V1_PUBLIC(varcharctoset); +PG_FUNCTION_INFO_V1_PUBLIC(varcharc_float4); +PG_FUNCTION_INFO_V1_PUBLIC(varcharc_float8); + +PG_FUNCTION_INFO_V1_PUBLIC(date_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(timestamp_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(int2_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(int4_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(int8_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(numeric_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(float4_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(float8_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(int1_varcharc); +PG_FUNCTION_INFO_V1_PUBLIC(settovarcharc); +PG_FUNCTION_INFO_V1_PUBLIC(name_textc); + +extern Datum rtrim1(PG_FUNCTION_ARGS); +extern Datum bpchar_int8(PG_FUNCTION_ARGS); +extern Datum bpchar_float4(PG_FUNCTION_ARGS); +extern Datum bpchar_float8(PG_FUNCTION_ARGS); +extern Datum texttoxml(PG_FUNCTION_ARGS); +extern Datum varchar_float4(PG_FUNCTION_ARGS); +extern Datum varchar_float8(PG_FUNCTION_ARGS); +extern Datum int8out(PG_FUNCTION_ARGS); + +static BpChar* bpcharc_input(const char* s, size_t len, int32 atttypmod) +{ + BpChar* result = NULL; + char* r = NULL; + size_t maxlen; + errno_t ss_rc = 0; + + /* If typmod is -1 (or invalid), use the actual string length */ + if (atttypmod < (int32)VARHDRSZ) + maxlen = len; + else { + + maxlen = atttypmod - VARHDRSZ; + if (len > maxlen) { + /* Verify that extra characters are spaces, and clip them off */ + size_t mbmaxlen = pg_mbcharcliplen_orig(s, len, maxlen); + size_t j; + + /* + * at this point, len is the actual BYTE length of the input + * string, maxlen is the max number of CHARACTERS allowed for this + * bpchar type, mbmaxlen is the length in BYTES of those chars. + */ + for (j = mbmaxlen; j < len; j++) { + if (s[j] != ' ') + ereport(ERROR, + (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), + errmsg("value too long for type character(%d)", (int)maxlen))); + } + + /* + * Now we set maxlen to the necessary byte length, not the number + * of CHARACTERS! + */ + maxlen = len = mbmaxlen; + } + } + + result = (BpChar*)palloc(maxlen + VARHDRSZ); + SET_VARSIZE(result, maxlen + VARHDRSZ); + r = VARDATA(result); + if (len > 0) { + ss_rc = memcpy_s(r, len, s, len); + securec_check(ss_rc, "\0", "\0"); + } + + /* blank pad the string if necessary */ + if (maxlen > len) { + ss_rc = memset_s(r + len, maxlen - len, ' ', maxlen - len); + securec_check(ss_rc, "\0", "\0"); + } + + return result; +} + +Datum +bpcharcin(PG_FUNCTION_ARGS) +{ + char* s = PG_GETARG_CSTRING(0); + +#ifdef NOT_USED + Oid typelem = PG_GETARG_OID(1); +#endif + int32 atttypmod = PG_GETARG_INT32(2); + BpChar* result = NULL; + + result = bpcharc_input(s, strlen(s), atttypmod); + PG_RETURN_BPCHAR_P(result); +} + +Datum +bpcharcout(PG_FUNCTION_ARGS) +{ + Datum txt = PG_GETARG_DATUM(0); + + PG_RETURN_CSTRING(TextDatumGetCString(txt)); +} + +Datum +bpcharcrecv(PG_FUNCTION_ARGS) +{ + StringInfo buf = (StringInfo)PG_GETARG_POINTER(0); + +#ifdef NOT_USED + Oid typelem = PG_GETARG_OID(1); +#endif + int32 atttypmod = PG_GETARG_INT32(2); + BpChar* result = NULL; + char* str = NULL; + int nbytes; + + str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); + result = bpcharc_input(str, nbytes, atttypmod); + pfree_ext(str); + PG_RETURN_BPCHAR_P(result); +} + +Datum +bpcharcsend(PG_FUNCTION_ARGS) +{ + /* Exactly the same as textsend, so share code */ + return textsend(fcinfo); +} + +Datum bpcharctypmodin(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchartypmodin, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharctypmodout(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchartypmodout, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc(PG_FUNCTION_ARGS) +{ + BpChar* source = PG_GETARG_BPCHAR_PP(0); + int32 maxlen = PG_GETARG_INT32(1); + bool isExplicit = PG_GETARG_BOOL(2); + BpChar* result = NULL; + int32 len; + char* r = NULL; + char* s = NULL; + int i; + errno_t ss_rc = 0; + + /* No work if typmod is invalid */ + if (maxlen < (int32)VARHDRSZ) + PG_RETURN_BPCHAR_P(source); + + maxlen -= VARHDRSZ; + + len = VARSIZE_ANY_EXHDR(source); + s = VARDATA_ANY(source); + + /* No work if supplied data matches typmod already */ + if (len == maxlen) + PG_RETURN_BPCHAR_P(source); + + if (len > maxlen) { + /* Verify that extra characters are spaces, and clip them off */ + size_t maxmblen; + + maxmblen = pg_mbcharcliplen_orig(s, len, maxlen); + + if (!isExplicit) { + for (i = maxmblen; i < len; i++) + if (s[i] != ' ') { + ereport(fcinfo->can_ignore ? WARNING : ERROR, + (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), + errmsg("value too long for type character(%d)", maxlen))); + break; + } + } + + len = maxmblen; + + /* + * At this point, maxlen is the necessary byte length, not the number + * of CHARACTERS! + * + * Now, only explicit cast char type data should pad blank space. + */ + if (!isExplicit) + maxlen = len; + } + + Assert(maxlen >= len); + + result = (BpChar*)palloc(maxlen + VARHDRSZ); + SET_VARSIZE(result, maxlen + VARHDRSZ); + r = VARDATA(result); + + if (len > 0) { + ss_rc = memcpy_s(r, len, s, len); + securec_check(ss_rc, "\0", "\0"); + } + + /* blank pad the string if necessary */ + if (maxlen > len) { + ss_rc = memset_s(r + len, maxlen - len, ' ', maxlen - len); + securec_check(ss_rc, "\0", "\0"); + } + + PG_RETURN_BPCHAR_P(result); +} + +Datum +bpcharceq(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpchareq(fcinfo)); +} + +Datum +bpcharcregexeq(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(textregexeq(fcinfo)); +} + +Datum +bpcharcregexne(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(textregexne(fcinfo)); +} + +Datum +bpcharcne(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpcharne(fcinfo)); +} + +Datum +bpcharclt(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpcharlt(fcinfo)); +} + +Datum +bpcharcle(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpcharle(fcinfo)); +} + +Datum +bpcharcgt(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpchargt(fcinfo)); +} + +Datum +bpcharcge(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpchareq(fcinfo)); +} + +Datum +bpcharccmp(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpcharcmp(fcinfo)); +} + +Datum +bpcharc_sortsupport(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(bpchar_sortsupport(fcinfo)); +} + +static VarChar* varcharc_input(const char* s, size_t len, int32 atttypmod) +{ + VarChar* result = NULL; + size_t maxlen; + + maxlen = atttypmod - VARHDRSZ; + + if (atttypmod >= (int32)VARHDRSZ && len > maxlen) { + /* Verify that extra characters are spaces, and clip them off */ + size_t mbmaxlen = pg_mbcharcliplen_orig(s, len, maxlen); + size_t j; + + for (j = mbmaxlen; j < len; j++) { + if (s[j] != ' ') + ereport(ERROR, + (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), + errmsg("value too long for type character varying(%d)", (int)maxlen))); + } + + len = mbmaxlen; + } + + result = (VarChar*)cstring_to_text_with_len(s, len); + return result; +} + +Datum varcharcin(PG_FUNCTION_ARGS) +{ + char* s = PG_GETARG_CSTRING(0); + +#ifdef NOT_USED + Oid typelem = PG_GETARG_OID(1); +#endif + int32 atttypmod = PG_GETARG_INT32(2); + VarChar* result = NULL; + + result = varcharc_input(s, strlen(s), atttypmod); + PG_RETURN_VARCHAR_P(result); +} + +Datum varcharcout(PG_FUNCTION_ARGS) +{ + Datum txt = PG_GETARG_DATUM(0); + + PG_RETURN_CSTRING(TextDatumGetCString(txt)); +} + +Datum varcharcrecv(PG_FUNCTION_ARGS) +{ + StringInfo buf = (StringInfo)PG_GETARG_POINTER(0); + +#ifdef NOT_USED + Oid typelem = PG_GETARG_OID(1); +#endif + int32 atttypmod = PG_GETARG_INT32(2); + VarChar* result = NULL; + char* str = NULL; + int nbytes; + + str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); + result = varcharc_input(str, nbytes, atttypmod); + pfree_ext(str); + PG_RETURN_VARCHAR_P(result); +} + +Datum varcharcsend(PG_FUNCTION_ARGS) +{ + /* Exactly the same as textsend, so share code */ + return textsend(fcinfo); +} + +Datum varcharctypmodin(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchartypmodin, arg1); + PG_RETURN_DATUM(result); +} + +Datum varcharctypmodout(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchartypmodout, arg1); + PG_RETURN_DATUM(result); +} + +Datum varcharc(PG_FUNCTION_ARGS) +{ + VarChar* source = PG_GETARG_VARCHAR_PP(0); + int32 typmod = PG_GETARG_INT32(1); + bool isExplicit = PG_GETARG_BOOL(2); + int32 len, maxlen; + size_t maxmblen; + int i; + char* s_data = NULL; + + len = VARSIZE_ANY_EXHDR(source); + s_data = VARDATA_ANY(source); + maxlen = typmod - VARHDRSZ; + + /* No work if typmod is invalid or supplied data fits it already */ + if (maxlen < 0 || len <= maxlen) + PG_RETURN_VARCHAR_P(source); + + /* truncate multibyte string preserving multibyte boundary */ + maxmblen = pg_mbcharcliplen_orig(s_data, len, maxlen); + + if (!isExplicit) { + for (i = maxmblen; i < len; i++) + if (s_data[i] != ' ') { + ereport(fcinfo->can_ignore ? WARNING : ERROR, + (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), + errmsg("value too long for type character varying(%d)", maxlen))); + break; + } + } + + PG_RETURN_VARCHAR_P((VarChar*)cstring_to_text_with_len(s_data, maxmblen)); +} + +Datum rtrim1c(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(rtrim1, arg1); + PG_RETURN_DATUM(result); +} + +Datum text_charc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(text_char, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_name(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_name, arg1); + PG_RETURN_DATUM(result); +} + +Datum texttoxmlc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(texttoxml, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_int8(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_int8, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_date(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_date, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_numeric(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_numeric, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_int4(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_int4, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_timestamp(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_timestamp, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharctoset(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum arg2 = PG_GETARG_DATUM(1); + Datum result; + + result = DirectFunctionCall2(bpchartoset, arg1, arg2); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_float4(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_float4, arg1); + PG_RETURN_DATUM(result); +} + +Datum bpcharc_float8(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(bpchar_float8, arg1); + PG_RETURN_DATUM(result); +} + +Datum int4_bpcharc(PG_FUNCTION_ARGS) +{ + int32 arg1 = PG_GETARG_INT32(0); + BpChar* result = NULL; + char* s = (char*)palloc(12); /* sign, 10 digits, '\0' */ + + pg_ltoa(arg1, s); + result = bpcharc_input(s, strlen(s), -1); + PG_RETURN_BPCHAR_P(result); +} + +Datum char_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(char_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum name_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(name_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum network_showc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(network_show, arg1); + PG_RETURN_DATUM(result); +} + +Datum booltextc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(booltext, arg1); + PG_RETURN_DATUM(result); +} + +Datum date_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(date_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum int1_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(int1_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum int2_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(int2_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum int8_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(int8_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum float4_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(float4_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum float8_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(float8_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum numeric_bpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(numeric_bpchar, arg1); + PG_RETURN_DATUM(result); +} + +Datum settobpcharc(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum arg2 = PG_GETARG_DATUM(1); + Datum result; + + result = DirectFunctionCall2(settobpchar, arg1, arg2); + PG_RETURN_DATUM(result); +} + +Datum varcharc_date(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchar_date, arg1); + PG_RETURN_DATUM(result); +} + +Datum varcharc_numeric(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchar_numeric, arg1); + PG_RETURN_DATUM(result); +} + +Datum varcharc_int4(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchar_int4, arg1); + PG_RETURN_DATUM(result); +} + +Datum varcharc_int8(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchar_int8, arg1); + PG_RETURN_DATUM(result); +} + +Datum varcharctoset(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum arg2 = PG_GETARG_DATUM(1); + Datum result; + + result = DirectFunctionCall2(varchartoset, arg1, arg2); + PG_RETURN_DATUM(result); +} + +Datum varcharc_float4(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchar_float4, arg1); + PG_RETURN_DATUM(result); +} + +Datum varcharc_float8(PG_FUNCTION_ARGS) +{ + Datum arg1 = PG_GETARG_DATUM(0); + Datum result; + + result = DirectFunctionCall1(varchar_float8, arg1); + PG_RETURN_DATUM(result); +} + +Datum date_varcharc(PG_FUNCTION_ARGS) +{ + DateADT dateVal = PG_GETARG_DATEADT(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(date_out, dateVal)); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), 0, -1); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum timestamp_varcharc(PG_FUNCTION_ARGS) +{ + Timestamp timestamp = PG_GETARG_TIMESTAMP(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(timestamp_out, timestamp)); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum int2_varcharc(PG_FUNCTION_ARGS) +{ + int16 arg1 = PG_GETARG_INT16(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(int2out, arg1)); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum int4_varcharc(PG_FUNCTION_ARGS) +{ + int32 arg1 = PG_GETARG_INT32(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(int4out, arg1)); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum int8_varcharc(PG_FUNCTION_ARGS) +{ + int64 val = PG_GETARG_INT64(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(int8out, val)); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum numeric_varcharc(PG_FUNCTION_ARGS) +{ + Numeric num = PG_GETARG_NUMERIC(0); + char* tmp = NULL; + Datum result; + + /* Handle Big Integer */ + if (NUMERIC_IS_BI(num)) { + num = makeNumericNormal(num); + } + + tmp = DatumGetCString(DirectFunctionCall1(numeric_out, NumericGetDatum(num))); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum float4_varcharc(PG_FUNCTION_ARGS) +{ + float4 num = PG_GETARG_FLOAT4(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(float4out, Float4GetDatum(num))); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum float8_varcharc(PG_FUNCTION_ARGS) +{ + float8 num = PG_GETARG_FLOAT8(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(float8out, Float8GetDatum(num))); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum int1_varcharc(PG_FUNCTION_ARGS) +{ + uint8 arg1 = PG_GETARG_UINT8(0); + char* tmp = NULL; + Datum result; + tmp = DatumGetCString(DirectFunctionCall1(int1out, arg1)); + + result = DirectFunctionCall3(varcharcin, CStringGetDatum(tmp), ObjectIdGetDatum(0), Int32GetDatum(-1)); + pfree_ext(tmp); + + PG_RETURN_DATUM(result); +} + +Datum settovarcharc(PG_FUNCTION_ARGS) +{ + Datum setlabels = DirectFunctionCall1(set_out, PG_GETARG_DATUM(0)); + int32 atttypmod = PG_GETARG_INT32(1); + return DirectFunctionCall3(varcharcin, PointerGetDatum(setlabels), + ObjectIdGetDatum(VARCHAROID), Int32GetDatum(atttypmod)); +} + +Datum name_textc(PG_FUNCTION_ARGS) +{ + Name s = PG_GETARG_NAME(0); + + PG_RETURN_TEXT_P(cstring_to_text(NameStr(*s))); +} diff --git a/contrib/whale/plugin_parser/gram.y b/contrib/whale/plugin_parser/gram.y index 0a58b020..b782dd44 100644 --- a/contrib/whale/plugin_parser/gram.y +++ b/contrib/whale/plugin_parser/gram.y @@ -538,6 +538,10 @@ static void setDelimiterName(core_yyscan_t yyscanner, char*input, VariableSetStm %type part_option /* b compatibility: comment end */ +/* O compatibility: comment start */ +%type opt_charbyte +/* O compatibility: comment end */ + %type key_usage_list index_hint_list opt_index_hint_list %type index_hint_definition %type group_by_list @@ -859,7 +863,7 @@ static void setDelimiterName(core_yyscan_t yyscanner, char*input, VariableSetStm ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUDIT AUTHID AUTHORIZATION AUTOEXTEND AUTOMAPPED AUTO_INCREMENT BACKWARD BARRIER BEFORE BEGIN_NON_ANOYBLOCK BEGIN_P BETWEEN BIGINT BINARY BINARY_DOUBLE BINARY_INTEGER BIT BLANKS - BLOB_P BLOCKCHAIN BODY_P BOGUS BOOLEAN_P BOTH BUCKETCNT BUCKETS BY BYTEAWITHOUTORDER BYTEAWITHOUTORDERWITHEQUAL + BLOB_P BLOCKCHAIN BODY_P BOGUS BOOLEAN_P BOTH BUCKETCNT BUCKETS BY BYTE_P BYTEAWITHOUTORDER BYTEAWITHOUTORDERWITHEQUAL CACHE CALL CALLED CANCELABLE CASCADE CASCADED CASE CAST CATALOG_P CATALOG_NAME CHAIN CHANGE CHAR_P CHARACTER CHARACTERISTICS CHARACTERSET CHARSET CHECK CHECKPOINT CLASS CLASS_ORIGIN CLEAN CLIENT CLIENT_MASTER_KEY CLIENT_MASTER_KEYS CLOB CLOSE @@ -25264,14 +25268,37 @@ ConstCharacter: CharacterWithLength } ; -CharacterWithLength: character '(' Iconst ')' +CharacterWithLength: character '(' Iconst opt_charbyte ')' { - $$ = SystemTypeName($1); + if ($4) + { + if (strncmp("bpchar", $1, 6) == 0) + { + $$ = SystemTypeName("bpcharc"); + } + else if (strncmp("varchar", $1, 7) == 0) + { + $$ = SystemTypeName("varcharc"); + } + else + { + $$ = SystemTypeName($1); + } + } + else + { + $$ = SystemTypeName($1); + } $$->typmods = list_make1(makeIntConst($3, @3)); $$->location = @1; } ; +opt_charbyte: CHAR_P { $$ = TRUE; } + | CHARACTER { $$ = TRUE; } + | BYTE_P { $$ = FALSE; } + | /* EMPTY */ { $$ = FALSE; } + CharacterWithoutLength: character { $$ = SystemTypeName($1); diff --git a/contrib/whale/sql/charbyte.sql b/contrib/whale/sql/charbyte.sql new file mode 100644 index 00000000..1ba70e30 --- /dev/null +++ b/contrib/whale/sql/charbyte.sql @@ -0,0 +1,122 @@ +-- test oracle compatibility char byte semantic + +drop table if exists test_charbyte1; +create table test_charbyte1 (id int, name char (4 char)); +insert into test_charbyte1 values(1, 'abcd'); +insert into test_charbyte1 values(2, '中国天津'); +insert into test_charbyte1 values(3, 'abcde'); +insert into test_charbyte1 values(4, '中国ab'); +select * from test_charbyte1 order by id; +drop table test_charbyte1; + +drop table if exists test_charbyte2; +create table test_charbyte2 (id int, name char (4 byte)); +insert into test_charbyte2 values(1, 'abcd'); +insert into test_charbyte2 values(2, '中国天津'); +insert into test_charbyte2 values(3, 'abcde'); +insert into test_charbyte2 values(4, '中国ab'); +select * from test_charbyte2 order by id; +drop table test_charbyte2; + +drop table if exists test_charbyte3; +create table test_charbyte3 (id int, name varchar (4 char)); +insert into test_charbyte3 values(1, 'abcd'); +insert into test_charbyte3 values(2, '中国天津'); +insert into test_charbyte3 values(3, 'abcde'); +insert into test_charbyte3 values(4, '中国ab'); +select * from test_charbyte3 order by id; +drop table test_charbyte3; + +drop table if exists test_charbyte4; +create table test_charbyte4 (id int, name varchar (4 byte)); +insert into test_charbyte4 values(1, 'abcd'); +insert into test_charbyte4 values(2, '中国天津'); +insert into test_charbyte4 values(3, 'abcde'); +insert into test_charbyte4 values(4, '中国ab'); +select * from test_charbyte4 order by id; +drop table test_charbyte4; + +drop table if exists test_charbyte5; +create table test_charbyte5 (id int, name varchar2 (4 char)); +insert into test_charbyte5 values(1, 'abcd'); +insert into test_charbyte5 values(2, '中国天津'); +insert into test_charbyte5 values(3, 'abcde'); +insert into test_charbyte5 values(4, '中国ab'); +select * from test_charbyte5 order by id; +drop table test_charbyte5; + +drop table if exists test_charbyte6; +create table test_charbyte6 (id int, name varchar2 (4 byte)); +insert into test_charbyte6 values(1, 'abcd'); +insert into test_charbyte6 values(2, '中国天津'); +insert into test_charbyte6 values(3, 'abcde'); +insert into test_charbyte6 values(4, '中国ab'); +select * from test_charbyte6 order by id; +drop table test_charbyte6; + +drop table if exists my_table1; +create table my_table1 (id int, duration char(100 char)); +insert into my_table1 values(1, '1 day 2 hours'); +select duration::interval from my_table1 where id=1; +insert into my_table1 values(2, '2003-05-08 12:35:29'); +select duration::smalldatetime from my_table1 where id=2; +select duration::text from my_table1; +select duration::clob from my_table1; +select duration::varchar from my_table1; +select duration::nvarchar2 from my_table1; +select duration::char from my_table1; +select duration::name from my_table1; +insert into my_table1 values(3, ''); +select duration::xml from my_table1 where id=3; +insert into my_table1 values(4, '123456789'); +select duration::int8 from my_table1 where id=4; +select duration::date from my_table1 where id=2; +select duration::numeric from my_table1 where id=4; +select duration::int4 from my_table1 where id=4; +select duration::timestamp from my_table1 where id=2; +select duration::float4 from my_table1 where id=4; +select duration::float8 from my_table1 where id=4; + +drop table my_table1; + +drop table if exists my_table2; +create table my_table2 (id int, duration varchar(100 char)); +insert into my_table2 values(1, '1 day 2 hours'); +select duration::interval from my_table2; +insert into my_table2 values(2, '2003-05-08 12:35:29'); +select duration::smalldatetime from my_table2 where id=2; +select duration::text from my_table2; +select duration::clob from my_table2; +select duration::varchar from my_table2; +select duration::nvarchar2 from my_table2; +select duration::char from my_table2; +select duration::name from my_table2; +insert into my_table2 values(3, ''); +select duration::xml from my_table2 where id=3; +insert into my_table2 values(4, '123456789'); +select duration::int8 from my_table2 where id=4; +select duration::date from my_table2 where id=2; +select duration::numeric from my_table2 where id=4; +select duration::int4 from my_table2 where id=4; +select duration::timestamp from my_table2 where id=2; +select duration::float4 from my_table2 where id=4; +select duration::float8 from my_table2 where id=4; + +drop table my_table2; + +drop table if exists my_table3; +create table my_table3 (city char (10 char)); +insert into my_table3 values('beijing'); +insert into my_table3 values('tianjin'); +insert into my_table3 values('shanghai'); +select * from my_table3; +update my_table3 set city = 'guangzhou' where city = 'shanghai'; +select * from my_table3; +delete from my_table3 where city = 'guangzhou'; +select * from my_table3; +update my_table3 set city = 'xian' where city > 'beijing'; +select * from my_table3; +delete from my_table3 where city ~ 'bei'; +select * from my_table3; + +drop table my_table3; diff --git a/contrib/whale/sql_script/base.sql b/contrib/whale/sql_script/base.sql index bea1811c..df4fdb09 100644 --- a/contrib/whale/sql_script/base.sql +++ b/contrib/whale/sql_script/base.sql @@ -1,3 +1,543 @@ \echo Use "CREATE EXTENSION whale" to load this file. \quit CREATE FUNCTION pg_catalog.whale_invoke() - RETURNS VOID AS '$libdir/whale','whale_invoke' LANGUAGE C STRICT; \ No newline at end of file + RETURNS VOID AS '$libdir/whale','whale_invoke' LANGUAGE C STRICT; + +-- bpcharc function and type +CREATE FUNCTION pg_catalog.bpcharcin(cstring,oid,integer) + RETURNS pg_catalog.bpcharc +AS 'MODULE_PATHNAME','bpcharcin' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcout(bpcharc) + RETURNS CSTRING +AS 'MODULE_PATHNAME','bpcharcout' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcrecv(internal,oid,integer) + RETURNS pg_catalog.bpcharc +AS 'MODULE_PATHNAME','bpcharcrecv' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcsend(bpcharc) + RETURNS bytea +AS 'MODULE_PATHNAME','bpcharcsend' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharctypmodin(cstring[]) + RETURNS integer +AS 'MODULE_PATHNAME','bpcharctypmodin' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharctypmodout(integer) + RETURNS CSTRING +AS 'MODULE_PATHNAME','bpcharctypmodout' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + + +CREATE FUNCTION pg_catalog.bpcharceq(bpcharc, bpcharc) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharceq' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcregexeq(bpcharc, text) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharcregexeq' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcregexne(bpcharc, text) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharcregexne' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcne(bpcharc, bpcharc) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharcne' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharclt(bpcharc, bpcharc) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharclt' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcle(bpcharc, bpcharc) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharcle' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcgt(bpcharc, bpcharc) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharcgt' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharcge(bpcharc, bpcharc) + RETURNS bool +AS 'MODULE_PATHNAME','bpcharcge' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharccmp(bpcharc, bpcharc) + RETURNS integer +AS 'MODULE_PATHNAME','bpcharccmp' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_sortsupport(internal) + RETURNS void +AS 'MODULE_PATHNAME','bpcharc_sortsupport' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE TYPE pg_catalog.bpcharc ( +internallength = VARIABLE, +input = bpcharcin, +output = bpcharcout, +receive = bpcharcrecv, +send = bpcharcsend, +typmod_in = bpcharctypmodin, +typmod_out = bpcharctypmodout, +category = 'S', +collatable = true, +storage = 'extended' +); + +CREATE FUNCTION pg_catalog.bpcharc(bpcharc, integer, bool) + RETURNS bpcharc +AS 'MODULE_PATHNAME','bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc(name) + RETURNS bpcharc +AS 'MODULE_PATHNAME','name_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc(char) + RETURNS bpcharc +AS 'MODULE_PATHNAME','char_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int4_bpcharc(int4) + RETURNS bpcharc +AS 'MODULE_PATHNAME','int4_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + + +CREATE FUNCTION pg_catalog.name(bpcharc) + RETURNS name +AS 'MODULE_PATHNAME','bpcharc_name' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + + +CREATE FUNCTION pg_catalog.xml(bpcharc) + RETURNS xml +AS 'MODULE_PATHNAME','texttoxmlc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_int8(bpcharc) + RETURNS int8 +AS 'MODULE_PATHNAME','bpcharc_int8' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_date(bpcharc) + RETURNS date +AS 'MODULE_PATHNAME','bpcharc_date' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_numeric(bpcharc) + RETURNS numeric +AS 'MODULE_PATHNAME','bpcharc_numeric' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_int4(bpcharc) + RETURNS int4 +AS 'MODULE_PATHNAME','bpcharc_int4' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_timestamp(bpcharc) + RETURNS timestamp +AS 'MODULE_PATHNAME','bpcharc_timestamp' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.set(bpcharc, integer) + RETURNS anyset +AS 'MODULE_PATHNAME','bpcharctoset' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_float4(bpcharc) + RETURNS float4 +AS 'MODULE_PATHNAME','bpcharc_float4' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.bpcharc_float8(bpcharc) + RETURNS float8 +AS 'MODULE_PATHNAME','bpcharc_float8' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.name_bpcharc(name) + RETURNS bpcharc +AS 'MODULE_PATHNAME','name_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.date_bpcharc(date) + RETURNS bpcharc +AS 'MODULE_PATHNAME','date_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int1_bpcharc(int1) + RETURNS bpcharc +AS 'MODULE_PATHNAME','int1_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int2_bpcharc(int2) + RETURNS bpcharc +AS 'MODULE_PATHNAME','int2_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int8_bpcharc(int8) + RETURNS bpcharc +AS 'MODULE_PATHNAME','int8_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.float4_bpcharc(float4) + RETURNS bpcharc +AS 'MODULE_PATHNAME','float4_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.float8_bpcharc(float8) + RETURNS bpcharc +AS 'MODULE_PATHNAME','float8_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.numeric_bpcharc(numeric) + RETURNS bpcharc +AS 'MODULE_PATHNAME','numeric_bpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.settobpcharc(anyset) + RETURNS bpcharc +AS 'MODULE_PATHNAME','settobpcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE CAST ( bpcharc AS bpcharc ) WITH FUNCTION bpcharc(bpcharc, integer, bool) AS IMPLICIT; +CREATE CAST ( name AS bpcharc ) WITH FUNCTION bpcharc(name) AS ASSIGNMENT; +CREATE CAST ( char AS bpcharc ) WITH FUNCTION bpcharc(char) AS ASSIGNMENT; +CREATE CAST ( int4 AS bpcharc ) WITH FUNCTION int4_bpcharc(int4) AS IMPLICIT; +CREATE CAST ( clob AS bpcharc ) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST ( varchar AS bpcharc ) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST ( nvarchar2 AS bpcharc ) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST ( bpcharc AS name ) WITH FUNCTION name(bpcharc) AS IMPLICIT; +CREATE CAST ( bpcharc AS xml ) WITH FUNCTION xml(bpcharc) ; +CREATE CAST ( bpcharc AS int8 ) WITH FUNCTION bpcharc_int8(bpcharc) AS IMPLICIT; +CREATE CAST ( bpcharc AS date ) WITH FUNCTION bpcharc_date(bpcharc) AS IMPLICIT; +CREATE CAST ( bpcharc AS numeric ) WITH FUNCTION bpcharc_numeric(bpcharc) AS IMPLICIT; +CREATE CAST ( bpcharc AS int4 ) WITH FUNCTION bpcharc_int4(bpcharc) AS IMPLICIT; +CREATE CAST ( bpcharc AS anyset ) WITH FUNCTION set(bpcharc, integer) AS IMPLICIT; +CREATE CAST ( bpcharc AS float4 ) WITH FUNCTION bpcharc_float4(bpcharc) AS IMPLICIT; +CREATE CAST ( bpcharc AS float8 ) WITH FUNCTION bpcharc_float8(bpcharc) AS IMPLICIT; +CREATE CAST ( text AS bpcharc ) WITHOUT FUNCTION AS IMPLICIT; + +CREATE CAST ( cidr AS bpcharc ) WITH FUNCTION text(inet) AS ASSIGNMENT ; +CREATE CAST ( inet AS bpcharc ) WITH FUNCTION text(inet) AS ASSIGNMENT ; +CREATE CAST ( bool AS bpcharc ) WITH FUNCTION text(bool) AS ASSIGNMENT ; +CREATE CAST ( xml AS bpcharc ) WITHOUT FUNCTION AS ASSIGNMENT ; +CREATE CAST ( date AS bpcharc ) WITH FUNCTION date_bpcharc(date) AS IMPLICIT ; +CREATE CAST ( int1 AS bpcharc ) WITH FUNCTION int1_bpcharc(int1) AS IMPLICIT ; +CREATE CAST ( int2 AS bpcharc ) WITH FUNCTION int2_bpcharc(int2) AS IMPLICIT ; +CREATE CAST ( int8 AS bpcharc ) WITH FUNCTION int8_bpcharc(int8) AS IMPLICIT ; +CREATE CAST ( float4 AS bpcharc ) WITH FUNCTION float4_bpcharc(float4) AS IMPLICIT ; +CREATE CAST ( float8 AS bpcharc ) WITH FUNCTION float8_bpcharc(float8) AS IMPLICIT ; +CREATE CAST ( numeric AS bpcharc ) WITH FUNCTION numeric_bpcharc(numeric) AS IMPLICIT ; +CREATE CAST ( anyset AS bpcharc ) WITH FUNCTION settobpcharc(anyset) AS IMPLICIT ; + +CREATE OPERATOR = ( + LEFTARG = bpcharc, + RIGHTARG = bpcharc, + PROCEDURE = bpcharceq, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES +); + +CREATE OPERATOR <> ( + LEFTARG = bpcharc, + RIGHTARG = bpcharc, + PROCEDURE = bpcharcne, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel +); + +CREATE OPERATOR < ( + LEFTARG = bpcharc, + RIGHTARG = bpcharc, + PROCEDURE = bpcharclt, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +CREATE OPERATOR <= ( + LEFTARG = bpcharc, + RIGHTARG = bpcharc, + PROCEDURE = bpcharcle, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +CREATE OPERATOR > ( + LEFTARG = bpcharc, + RIGHTARG = bpcharc, + PROCEDURE = bpcharcgt, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +CREATE OPERATOR >= ( + LEFTARG = bpcharc, + RIGHTARG = bpcharc, + PROCEDURE = bpcharcge, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +CREATE OPERATOR ~ ( + LEFTARG = bpcharc, + RIGHTARG = text, + PROCEDURE = bpcharcregexeq, + NEGATOR = !~, + RESTRICT = regexeqsel, + JOIN = regexeqjoinsel +); + +CREATE OPERATOR !~ ( + LEFTARG = bpcharc, + RIGHTARG = text, + PROCEDURE = bpcharcregexne, + NEGATOR = ~, + RESTRICT = regexnesel, + JOIN = regexnejoinsel +); + +CREATE OPERATOR FAMILY bpcharc_ops USING btree; + +CREATE OPERATOR CLASS bpcharc_ops DEFAULT FOR TYPE bpcharc USING btree +FAMILY bpcharc_ops AS operator 1 < , operator 3 =, operator 2 <=, operator 4 >=, operator 5 >, +function 1 pg_catalog.bpcharccmp(bpcharc, bpcharc), function 2 pg_catalog.bpcharc_sortsupport(internal); + +-- varcharc function and type +CREATE FUNCTION pg_catalog.varcharcin(cstring,oid,integer) + RETURNS pg_catalog.varcharc +AS 'MODULE_PATHNAME','varcharcin' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharcout(varcharc) + RETURNS CSTRING +AS 'MODULE_PATHNAME','varcharcout' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharcrecv(internal,oid,integer) + RETURNS pg_catalog.varcharc +AS 'MODULE_PATHNAME','varcharcrecv' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharcsend(varcharc) + RETURNS bytea +AS 'MODULE_PATHNAME','varcharcsend' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharctypmodin(cstring[]) + RETURNS integer +AS 'MODULE_PATHNAME','varcharctypmodin' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharctypmodout(integer) + RETURNS CSTRING +AS 'MODULE_PATHNAME','varcharctypmodout' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE TYPE pg_catalog.varcharc ( +internallength = VARIABLE, +input = varcharcin, +output = varcharcout, +receive = varcharcrecv, +send = varcharcsend, +typmod_in = varcharctypmodin, +typmod_out = varcharctypmodout +); + +CREATE FUNCTION pg_catalog.varcharc(varcharc, integer, bool) + RETURNS varcharc +AS 'MODULE_PATHNAME','varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE CAST ( varcharc AS varcharc ) WITH FUNCTION varcharc(varcharc, integer, bool) AS IMPLICIT; + +CREATE CAST ( varcharc AS text ) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST ( text AS varcharc ) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST ( varcharc AS regclass ) WITH FUNCTION regclass(text) AS IMPLICIT; +CREATE CAST ( varcharc AS clob ) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST ( varcharc AS bpchar ) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST ( varcharc AS nvarchar2 ) WITHOUT FUNCTION AS IMPLICIT; + +CREATE CAST ( varcharc AS name ) WITH FUNCTION name(text) AS IMPLICIT; +CREATE CAST ( varcharc AS xml ) WITH FUNCTION xml(text) ; + +CREATE FUNCTION pg_catalog.varcharc_date(varcharc) + RETURNS date +AS 'MODULE_PATHNAME','varcharc_date' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharc_numeric(varcharc) + RETURNS numeric +AS 'MODULE_PATHNAME','varcharc_numeric' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharc_int4(varcharc) + RETURNS int4 +AS 'MODULE_PATHNAME','varcharc_int4' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharc_int8(varcharc) + RETURNS int8 +AS 'MODULE_PATHNAME','varcharc_int8' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE CAST ( varcharc AS date ) WITH FUNCTION varcharc_date(varcharc) AS IMPLICIT; +CREATE CAST ( varcharc AS numeric ) WITH FUNCTION varcharc_numeric(varcharc) AS IMPLICIT; +CREATE CAST ( varcharc AS int4 ) WITH FUNCTION varcharc_int4(varcharc) AS IMPLICIT; +CREATE CAST ( varcharc AS int8 ) WITH FUNCTION varcharc_int8(varcharc) AS IMPLICIT; + + +CREATE FUNCTION pg_catalog.set(varcharc) + RETURNS anyset +AS 'MODULE_PATHNAME','varcharctoset' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE CAST ( varcharc AS anyset ) WITH FUNCTION set(varcharc) AS IMPLICIT; +CREATE CAST ( varcharc AS raw ) WITH FUNCTION hextoraw(text) AS IMPLICIT; + +CREATE FUNCTION pg_catalog.varcharc_float4(varcharc) + RETURNS float4 +AS 'MODULE_PATHNAME','varcharc_float4' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.varcharc_float8(varcharc) + RETURNS float8 +AS 'MODULE_PATHNAME','varcharc_float8' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE CAST ( varcharc AS float4 ) WITH FUNCTION varcharc_float4(varcharc) AS IMPLICIT; +CREATE CAST ( varcharc AS float8 ) WITH FUNCTION varcharc_float8(varcharc) AS IMPLICIT; + +CREATE CAST ( bpchar AS varcharc ) WITH FUNCTION text(bpchar) AS IMPLICIT; +CREATE CAST ( nvarchar2 AS varcharc ) WITHOUT FUNCTION AS IMPLICIT; + +CREATE FUNCTION pg_catalog.name_textc(name) + RETURNS varcharc +AS 'MODULE_PATHNAME','name_textc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE CAST ( name AS varcharc ) WITH FUNCTION name_textc(name) AS ASSIGNMENT ; +CREATE CAST ( cidr AS varcharc ) WITH FUNCTION text(inet) AS ASSIGNMENT ; +CREATE CAST ( inet AS varcharc ) WITH FUNCTION text(inet) AS ASSIGNMENT ; +CREATE CAST ( bool AS varcharc ) WITH FUNCTION text(bool) AS ASSIGNMENT ; +CREATE CAST ( xml AS varcharc ) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (clob AS varcharc ) WITHOUT FUNCTION AS IMPLICIT; + +CREATE FUNCTION pg_catalog.date_varcharc(date) + RETURNS varcharc +AS 'MODULE_PATHNAME','date_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.timestamp_varcharc(timestamp) + RETURNS varcharc +AS 'MODULE_PATHNAME','timestamp_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int2_varcharc(int2) + RETURNS varcharc +AS 'MODULE_PATHNAME','int2_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int4_varcharc(int4) + RETURNS varcharc +AS 'MODULE_PATHNAME','int4_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int8_varcharc(int8) + RETURNS varcharc +AS 'MODULE_PATHNAME','int8_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.numeric_varcharc(numeric) + RETURNS varcharc +AS 'MODULE_PATHNAME','numeric_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.float4_varcharc(float4) + RETURNS varcharc +AS 'MODULE_PATHNAME','float4_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.float8_varcharc(float8) + RETURNS varcharc +AS 'MODULE_PATHNAME','float8_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.int1_varcharc(int1) + RETURNS varcharc +AS 'MODULE_PATHNAME','int1_varcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE FUNCTION pg_catalog.settovarcharc(anyset) + RETURNS varcharc +AS 'MODULE_PATHNAME','settovarcharc' +LANGUAGE C IMMUTABLE STRICT NOT FENCED; + +CREATE CAST (date AS varcharc ) WITH FUNCTION date_varcharc(date) AS IMPLICIT; +CREATE CAST (int2 AS varcharc ) WITH FUNCTION int2_varcharc(int2) AS IMPLICIT; +CREATE CAST (int4 AS varcharc ) WITH FUNCTION int4_varcharc(int4) AS IMPLICIT; +CREATE CAST (int8 AS varcharc ) WITH FUNCTION int8_varcharc(int8) AS IMPLICIT; +CREATE CAST (numeric AS varcharc ) WITH FUNCTION numeric_varcharc(numeric) AS IMPLICIT; +CREATE CAST (float4 AS varcharc ) WITH FUNCTION float4_varcharc(float4) AS IMPLICIT; +CREATE CAST (float8 AS varcharc ) WITH FUNCTION float8_varcharc(float8) AS IMPLICIT; +CREATE CAST (int1 AS varcharc ) WITH FUNCTION int1_varcharc(int1) AS IMPLICIT; +CREATE CAST (anyset AS varcharc ) WITH FUNCTION settovarcharc(anyset) AS IMPLICIT; + +CREATE CAST (raw AS varcharc ) WITH FUNCTION rawtohex(raw) AS IMPLICIT; + +CREATE FUNCTION pg_catalog.to_interval_varcharc(varcharc) + RETURNS interval AS + $$ select pg_catalog.interval_in(pg_catalog.varcharcout($1), 0::Oid, -1); $$ +LANGUAGE sql IMMUTABLE STRICT; + +CREATE CAST (varcharc AS interval ) WITH FUNCTION to_interval_varcharc(varcharc) AS IMPLICIT; + +CREATE FUNCTION pg_catalog.to_interval_bpcharc(bpcharc) + RETURNS interval AS + $$ select pg_catalog.interval_in(pg_catalog.bpcharcout($1), 0::Oid, -1); $$ +LANGUAGE sql IMMUTABLE STRICT; + +CREATE CAST (bpcharc AS interval ) WITH FUNCTION to_interval_bpcharc(bpcharc) AS IMPLICIT; + +CREATE FUNCTION pg_catalog.bpcharc_to_smalldatetime(bpcharc) + RETURNS smalldatetime AS + $$ select pg_catalog.smalldatetime_in(pg_catalog.bpcharcout($1), 0::Oid, -1); $$ +LANGUAGE sql IMMUTABLE STRICT; + +CREATE CAST (bpcharc AS smalldatetime ) WITH FUNCTION bpcharc_to_smalldatetime(bpcharc) AS IMPLICIT; + +CREATE FUNCTION pg_catalog.varcharc_to_smalldatetime(varcharc) + RETURNS smalldatetime AS + $$ select pg_catalog.smalldatetime_in(pg_catalog.varcharcout($1), 0::Oid, -1); $$ +LANGUAGE sql IMMUTABLE STRICT; + +CREATE CAST (varcharc AS smalldatetime ) WITH FUNCTION varcharc_to_smalldatetime(varcharc) AS IMPLICIT; + -- Gitee