RDBMS code 6706: The string contains an untranslatable character in teradata - teradata

I got the following error while inserting data into teradata DB using data stage job, I can not see data file and all the fields in #table are varchar, below is my code:
insert into #table
(
column1,
column2
)
values
(
column1_value,
column2_value
);
Error:
RDBMS code 6706: The string contains an untranslatable character

Related

Teradata - Column datatypes not copied for views

I am trying to create view from table as below
CREATE TABLE tb
(
a INTEGER,
b INTEGER
)
CREATE VIEW vtb AS
(SELECT *
FROM tb);
And then when I executed the following command the type of the column is null
help view vtb;
Is there a way to copy the column datatypes while creating the view ?

Create index on timestamp delivered by JSON - incorrect datetime value

I constantly retrieve JSON data from some API and put that data into a MariaDB table.
The JSON ships with a timestamp which I'd like to place an index on, because this attribute is used for querying the table.
The JSON looks something like this (stripped):
{
"time": "2021-12-26T14:00:00.007294Z",
"some_measure": "0.10031"
}
I create a table:
CREATE TABLE some_table (
my_json JSON NOT NULL,
time TIMESTAMP AS (JSON_VALUE(my_json , '$.time')),
some_measure DOUBLE AS (JSON_VALUE(my_json , '$.some_measure'))
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;
my_json holds the entire JSON snippet, time and some_measure are virtual columns properly extracting the corresponding JSON values on the fly.
Now, trying to add an index on the TIMESTAMP attribute:
CREATE INDEX some_index ON some_table (time);
This fails:
SQL Error [1292] [22007]: (conn=454) Incorrect datetime value:
'2021-12-26T14:00:00.007294Z' for column `some_db`.`some_table`.`time` at row 1
How can I add an index on that timestamp?
The issue here is that converting a string (the JSON timestamp) to a TIMESTAMP is non-deterministic because it involves server side settings (sql_mode) and timezone settings.
Indexing virtual columns which are non-deterministic is not supported.
You would want to use a VARCHAR data type instead and index that:
CREATE TABLE some_table (
my_json JSON NOT NULL,
time VARCHAR(100) AS (JSON_VALUE(my_json , '$.time')),
some_measure DOUBLE AS (JSON_VALUE(my_json , '$.some_measure'))
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;
You should be able to create your index:
CREATE INDEX some_index ON some_table (`time`);
You can still query time because MariaDB automatically converts DATETIMEs if used against a VARCHAR:
SELECT
*
FROM some_table
WHERE time > '2008-12-31 23:59:59' + INTERVAL 1 SECOND;
The query will use the index:
I finally came up with a solution that works for me.
Changes are:
use STR_TO_DATE() to create a valid DATETIME from the JSON timestamp
make the generated (virtual) column PERSISTENT
use data type DATETIME instead of TIMESTAMP
So the new code looks like this:
CREATE TABLE some_table (
my_json JSON NOT NULL,
time DATETIME AS (STR_TO_DATE((JSON_VALUE(my_json , '$.time')), '%Y-%m-%d%#%T%.%#%#')) PERSISTENT,
some_measure DOUBLE AS (JSON_VALUE(my_json , '$.some_measure'))
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;
CREATE INDEX some_index ON some_table (`time`);

what is the correct format for inserting dates from text file using Teradata SQL Assistant

I am trying to insert data from a tab delimited text file to a Teradata table i created.
It seems Teradata SQL Assistant does not recognize the dates in the file as dates
If I try the following code
create set table my_table
(
update_date date
, status_code smallint
)
INSERT INTO my_table
VALUES (?, ?)
I recieve the error: Invalid value for update_date
However, when I try the code
create set table my_table
(
update_date varchar(32)
, status_code smallint
)
INSERT INTO my_table
VALUES (?, ?)
The upload works smoothly.
I tried several formats: 28/08/2019, 2019-08-28 and also '2019-08-28'. All had yielded the same error
Casting the value in the text file to a date by providing the correct format had solved the problem
The following code performs the required task with no errors:
create set table my_table
(
update_date date
, status_code smallint
)
insert into my_table
values (cast (? as date format 'dd/mm/yyyy'), ?)

Sybase iq cannot load table with datetime column

I'm trying to load table to a sybase iq database from a text file, and have a trouble loading datetime field... Always get error data type conversion is not possible. I tried a lot of ways in solving it...
creating varchar field and converting it to data
creating temp table and inserting values into my table from temp table using dateformat, cast, convert,
load table table_name(
datetime_column datetime('dd-mm-yyyy hh-mm-ss')
) from ...
Nothing helps. Any help? thanks.
So I found the solution
load table table_name (
temp_date ' | ',
-- dt datetime column
)
from file_name
---------------------------------------
set dateformat dmy;
update table_name set dt = temp_date
ALTER TABLE table_name
DROP temp_date

Select tuples between two different dates in SQL Lite

I'm trying to find all the results between two dates in SQLite.
select log_ID
from Message
where Timestamp between DATE('2014-04-17 03:27:08','YYYY-MM-DD HH:MI:SS')
and DATE('2014-04-18 03:27:08','YYYY-MM-DD HH:MI:SS');
This query is executing successfully but it gives no results.
I've tried using DATE and TO_DATE functions as well.
Schema:
CREATE TABLE Message(
Log_ID INTEGER PRIMARY KEY,
Session_ID TEXT NOT NULL,
Timestamp DATETIME NOT NULL,
Admill_Msg TEXT, Logcat_Msg TEXT);
Sample tuples:
155|admil.out.txt|2014-04-17 03:26:48.730000||PID:926 TID:926 TAG:I/Zygote LOG:Preloading resources...
156|admil.out.txt|2014-04-17 03:26:48.730000||PID:926 TID:926 TAG:W/Resources LOG:Preloaded drawable resource #0x1080096 (android:drawable/toast_frame) that varies with configuration!!
157|admil.out.txt|2014-04-17 03:26:48.740000||PID:926 TID:926 TAG:W/Resources LOG:Preloaded drawable resource #0x1080105 (android:drawable/btn_check_on_pressed_holo_light) that varies with configuration!!
You are using the date function wrong; there is not format parameter.
strftime could do such formatting, but that is not necessary because the timestamps are simply strings.
Just compare the strings directly:
select log_ID
from Message
where Timestamp between '2014-04-17 03:27:08'
and '2014-04-18 03:27:08';

Resources