/usr/share/doc/firebird/sql.extensions
# SQL Language Extension: SET BIND ## Implements capability to setup columns coercion rules in current session. ### Author: Alex Peshkoff <peshkoff@mail.ru> ### Syntax is: ```sql SET BIND OF { type-from | TIME ZONE } TO { type-to | LEGACY | EXTENDED | NATIVE }; ``` ### Description: Makes it possible to define rules of describing types of returned to the client columns in non-standard way - `type-from` is replaced with `type-to`, 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)`. Special incomplete type `TIME ZONE` stands for all types (namely TIME & TIMESTAMP) WITH TIME ZONE. When incomplete type definiton is used in right side of the statement (TO part) firebird engine will define missing details about that type automatically based on source column. Changing bind of any NUMERIC/DECIMAL does not affect appropriate underlying integer type. On contrary, changing bind of integer datatype also affects appropriate NUMERICs/DECIMALs. Special `TO` part format `LEGACY` is used when datatype, missing in previous FB version, should be represented in a way, understandable by old client software (may be with some data losses). The following coercions are done for legacy datatypes: | Native datatype | Legacy datatype | |--------------------------|-----------------------------| | BOOLEAN | CHAR(5) | | DECFLOAT | DOUBLE PRECISION | | INT128 | BIGINT | | TIME WITH TIME ZONE | TIME WITHOUT TIME ZONE | | TIMESTAMP WITH TIME ZONE | TIMESTAMP WITHOUT TIME ZONE | Using `EXTENDED` in the `TO` part directs firebird engine to coerce to extended form of `FROM` datatype. Currently it works only for TIME/TIMESTAMP WITH TIME ZONE - they are coerced to EXTENDED TIME/TIMESTAMP WITH TIME ZONE appropriately. Setting `NATIVE` means `type` will be used as if there were no previous rules for it. Except SQL-statement there are two more ways to specify data coercion - tag `isc_dpb_set_bind` in DPB and `DataTypeCompatibility` parameter in firebird.conf & databases.conf. The later the rule is introduced (.conf->DPB->SQL) the higher priotiy it has. I.e. one can override .conf in any other way and DPB from SQL statement. Value of clumplet with `isc_dpb_set_bind` tag in DPB should be specified as a set of partially formed SET BIND statements, i.e. with prefix SET BIND OF is omitted, separated by semicolons. For example: ```c++ dpb->insertString(&status, isc_dpb_set_bind, "decfloat to char; int128 to char"); ``` `DataTypeCompatibility` is minor firebird version for which we want to provide some compatibility regarding data types. That compatibility may be not absolute - for example SET BIND can't care about type of particular SQL functions. The following types will be described in legacy form when `DataTypeCompatibility=3.0`: DECFLOAT, INT128 and TIME(STAMP) WITH TIME ZONE. When `DataTypeCompatibility=2.5` in addition to this list BOOLEAN will be described as legacy type as well. Only fields returned by database engine in regular messages are modified according to SET BIND rules. Variables returned by getting slice of an array are not affected by SET BIND statement. ### SQL 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 ``` In a case of missing ICU on client: ```sql SELECT CURRENT_TIMESTAMP FROM RDB$DATABASE; ``` ``` CURRENT_TIMESTAMP ========================================================= 2020-02-21 16:26:48.0230 GMT* ``` ```sql SET BIND OF TIME ZONE TO EXTENDED; SELECT CURRENT_TIMESTAMP FROM RDB$DATABASE; ``` ``` CURRENT_TIMESTAMP ========================================================= 2020-02-21 19:26:55.6820 +03:00 ```
.
Edit
..
Edit
README.PSQL_stack_trace.txt
Edit
README.aggregate_filter.md
Edit
README.aggregate_tracking
Edit
README.alternate_string_quoting.txt
Edit
README.autonomous_transactions.txt
Edit
README.blob_append.md
Edit
README.builtin_functions.txt
Edit
README.case
Edit
README.coalesce
Edit
README.column_type_psql.txt
Edit
README.common_table_expressions
Edit
README.context_variables
Edit
README.context_variables2
Edit
README.cumulative_roles.txt
Edit
README.current_time
Edit
README.cursor_variables.txt
Edit
README.cursors
Edit
README.data_type_results_of_aggregations.txt
Edit
README.data_types
Edit
README.db_triggers.txt
Edit
README.ddl.txt
Edit
README.ddl_access.txt
Edit
README.ddl_triggers.txt
Edit
README.default_parameters
Edit
README.derived_tables.txt
Edit
README.distinct
Edit
README.domains_psql.txt
Edit
README.exception_handling
Edit
README.execute_block
Edit
README.execute_statement
Edit
README.execute_statement2
Edit
README.explicit_locks
Edit
README.expression_indices
Edit
README.external_connections_pool
Edit
README.floating_point_types.md
Edit
README.global_temporary_tables
Edit
README.hex_literals.txt
Edit
README.identity_columns.txt
Edit
README.iif
Edit
README.isc_info_xxx
Edit
README.joins.txt
Edit
README.keywords
Edit
README.leave_labels
Edit
README.length
Edit
README.linger
Edit
README.list
Edit
README.management_statements_psql.md
Edit
README.mapping.html
Edit
README.merge.txt
Edit
README.null_value
Edit
README.nullif
Edit
README.offset_fetch.txt
Edit
README.order_by_expressions_nulls
Edit
README.packages.txt
Edit
README.plan
Edit
README.regr_functions.txt
Edit
README.returning
Edit
README.rows
Edit
README.savepoints
Edit
README.scrollable_cursors.txt
Edit
README.select_expressions
Edit
README.sequence_generators
Edit
README.set_bind.md
Edit
README.set_role
Edit
README.set_transaction.txt
Edit
README.similar_to.txt
Edit
README.sql_security.txt
Edit
README.statistical_functions.txt
Edit
README.subroutines.txt
Edit
README.substring_similar.txt
Edit
README.time_zone.md
Edit
README.trim
Edit
README.universal_triggers
Edit
README.update_or_insert
Edit
README.user_management
Edit
README.view_updates
Edit
README.window_functions.md
Edit