From a6b05a671e5828957e593062fa36e55273f626a3 Mon Sep 17 00:00:00 2001 From: AlexPeshkoff Date: Fri, 8 Nov 2019 20:16:33 +0300 Subject: [PATCH] Started with doc for a feature --- doc/sql.extensions/README.data_types | 29 --------- .../README.management_statements_psql.md | 5 +- doc/sql.extensions/README.set_bind.md | 62 +++++++++++++++++++ doc/sql.extensions/README.time_zone.md | 26 -------- 4 files changed, 64 insertions(+), 58 deletions(-) create mode 100644 doc/sql.extensions/README.set_bind.md diff --git a/doc/sql.extensions/README.data_types b/doc/sql.extensions/README.data_types index ac6dbc10b0..e89361d2d6 100644 --- a/doc/sql.extensions/README.data_types +++ b/doc/sql.extensions/README.data_types @@ -175,21 +175,6 @@ DECFLOAT (FB 4.0) by a comma-separated string with its value (case does not matter; using a single optional space after commas). - SET DECFLOAT BIND - controls how are DECFLOAT values represented in outer - world (i.e. in messages or in XSQLDA). Valid binding types are: NATIVE (use IEEE754 - binary representation), CHAR/CHARACTER (use ASCII string), DOUBLE PRECISION (use - 8-byte FP representation - same as used for DOUBLE PRECISION fields) or BIGINT - with possible comma-separated SCALE clause (i.e. 'BIGINT, 3'). Various bindings - are useful if one plans to use DECFLOAT values with some old client not supporting - native format. One can choose between strings (ideal precision, but poor support - for further processing), floating point values (ideal support for further processing - but poor precision) or scaled integers (good support for further processing and - required precision but range of values is very limited). When using in a tool like - generic purporse GUI client choice of CHAR binding is OK in most cases. By default - NATIVE binding is used. - The initial configuration may be specified with DPB isc_dpb_decfloat_bind followed - by a string with its value (case does not matter). - 5. The length of DECFLOAT literals are limited to 1024 characters. For longer values, you will need to use the scientific notation. For example, the 0.0<1020 zeroes>11 cannot be used as a literal, instead you can use the equivalent in scientific notation: 1.1E-1022. @@ -226,17 +211,3 @@ Enhancement in precision of calculations with NUMERIC/DECIMAL (FB 4.0) various math (log, exp, etc.) and aggregate functions using high precision numeric argument is DECFLOAT(34). - SET INT128 BIND - controls how are INT128 values represented in outer - world (i.e. in messages or in XSQLDA). Valid binding types are: NATIVE (use 128-bit - binary representation), CHAR/CHARACTER (use ASCII string), DOUBLE PRECISION (use - 8-byte FP representation - same as used for DOUBLE PRECISION fields) or BIGINT - with possible comma-separated SCALE clause (i.e. 'BIGINT, 3'). Various bindings - are useful if one plans to use 128-bit integers with some old client not supporting - native format. One can choose between strings (ideal precision, but poor support - for further processing), floating point values (ideal support for further processing - but poor precision) or scaled integers (good support for further processing and - required precision but range of values is very limited). When using in a tool like - generic purporse GUI client choice of CHAR binding is OK in most cases. By default - NATIVE binding is used. - The initial configuration may be specified with DPB isc_dpb_int128_bind followed - by a string with its value (case does not matter). diff --git a/doc/sql.extensions/README.management_statements_psql.md b/doc/sql.extensions/README.management_statements_psql.md index 540bd316d0..96a9f1c977 100644 --- a/doc/sql.extensions/README.management_statements_psql.md +++ b/doc/sql.extensions/README.management_statements_psql.md @@ -8,14 +8,13 @@ As many applications depends that some management statements be issued on the co The management statements part of this improvement are: - `ALTER SESSION RESET` +- `SET BIND OF ... TO` - `SET DECFLOAT ROUND` - `SET DECFLOAT TRAPS TO` -- `SET DECFLOAT BIND` - `SET ROLE` - `SET SESSION IDLE TIMEOUT` - `SET STATEMENT TIMEOUT` - `SET TIME ZONE` -- `SET TIME ZONE BIND` - `SET TRUSTED ROLE` ## Examples @@ -24,7 +23,7 @@ The management statements part of this improvement are: create or alter trigger on_connect on connect as begin - set decfloat bind double precision; + set bind of decfloat to double precision; set time zone 'America/Sao_Paulo'; end ``` diff --git a/doc/sql.extensions/README.set_bind.md b/doc/sql.extensions/README.set_bind.md new file mode 100644 index 0000000000..64aa458d49 --- /dev/null +++ b/doc/sql.extensions/README.set_bind.md @@ -0,0 +1,62 @@ +# SQL Language Extension: SET BIND + +## Implements capability to setup columns coercion rules in current session. + + +### Author: + + Alex Peshkoff + + +### Syntax is: + +```sql +SET BIND OF type1 TO type2; +SET BIND OF type NATIVE; +``` + +### Description: + +Makes it possible to define rules of describing types of returned to the client columns in non-standard way - `type1` is replaced with `type2`, automatic data coercion takes place. + +When incomplete type definition is used (i.e. `CHAR` instead `CHAR(n)`) in left part of `SET BIND` coercion will take place for all `CHAR` columns, not only default `CHAR(1)`. When incomplete type definiton is used in right side of the statement firebird engine will define missing parts automatically based on source column. + +### Samples: + +```sql +SELECT CAST('123.45' AS DECFLOAT(16)) FROM RDB$DATABASE; --native +``` +``` + CAST +======================= + 123.45 +``` + +```sql +SET BIND OF DECFLOAT TO DOUBLE PRECISION; +SELECT CAST('123.45' AS DECFLOAT(16)) FROM RDB$DATABASE; --double +``` +``` + CAST +======================= + 123.4500000000000 +``` + +```sql +SET BIND OF DECFLOAT(34) TO CHAR; +SELECT CAST('123.45' AS DECFLOAT(16)) FROM RDB$DATABASE; --still double +``` +``` + CAST +======================= + 123.4500000000000 +``` + +```sql +SELECT CAST('123.45' AS DECFLOAT(34)) FROM RDB$DATABASE; --text +``` +``` +CAST +========================================== +123.45 +``` diff --git a/doc/sql.extensions/README.time_zone.md b/doc/sql.extensions/README.time_zone.md index 4038ec0893..059ac48084 100644 --- a/doc/sql.extensions/README.time_zone.md +++ b/doc/sql.extensions/README.time_zone.md @@ -163,32 +163,6 @@ set time zone 'America/Sao_Paulo'; set time zone local; ``` -### `SET TIME ZONE BIND` statement - -Changes the session time zone bind for compatibility with old clients. - -The default is `NATIVE`, which means that `TIME WITH TIME ZONE` and `TIMESTAMP WITH TIME ZONE` expressions are returned with they new data types to the client. - -Old clients may not understand the new data types, so it's possible to define the bind to `LEGACY` and the expressions will be returned as `TIME WITHOUT TIME ZONE` and `TIMESTAMP WITHOUT TIME ZONE`, with appropriate conversion. - -The bind configuration is also applicable to input parameters. - -The initial configuration of time zone bind may be specified with DPB `isc_dpb_time_zone_bind` followed by a string with its value (case does not matter). - -#### Syntax - -``` -SET TIME ZONE BIND { NATIVE | LEGACY } -``` - -#### Examples - -``` -set time zone bind native; - -set time zone bind legacy; -``` - ### `AT` expression Translates a time/timestamp value to its correspondent value in another time zone.