Issue with Timestamp field in Fload - teradata

I am facing an issue with the fastload where my Timestamp fields are getting rejected to error table.
Below is the value of timestamp(6) field in my flat file.
23-06-2016 11:51:21.000000 23-06-2016 11:51:21.000000
Below is my code:
SET RECORD VARTEXT "ยก";
DEFINE
TRANSACTION_SOURCE_TYPE_ID (VARCHAR(54))
,TRANSACTION_SOURCE_TYPE_CODE (VARCHAR(20))
,TRANSACTION_SOURCE_TYPE_DESC (VARCHAR(110))
,EFFECTIVE_START_DATE (VARCHAR(54))
,EFFECTIVE_END_DATE (VARCHAR(54))
,COUNTRY_CODE (VARCHAR(13))
,SOURCE_SYSTEM_ID (VARCHAR(54))
,DW_LOAD_TIMESTAMP (VARCHAR(76))
,DW_UPD_LOAD_TIMESTAMP (VARCHAR(76))
,FORCE_SKEW_KEY (VARCHAR(51))
FILE=?INPUT_FILE;
SHOW;
INSERT INTO ?DWSBKPDB.TRANSACTION_TMP
(
TRANSACTION_SOURCE_TYPE_ID
,TRANSACTION_SOURCE_TYPE_CODE
,TRANSACTION_SOURCE_TYPE_DESC
,EFFECTIVE_START_DATE
,EFFECTIVE_END_DATE
,COUNTRY_CODE
,SOURCE_SYSTEM_ID
,DW_LOAD_TIMESTAMP
,DW_UPD_LOAD_TIMESTAMP
,FORCE_SKEW_KEY
)
VALUES
(
:TRANSACTION_SOURCE_TYPE_ID
,:TRANSACTION_SOURCE_TYPE_CODE
,:TRANSACTION_SOURCE_TYPE_DESC
,:EFFECTIVE_START_DATE (DATE, FORMAT 'YYYY-MM-DD')
,:EFFECTIVE_END_DATE (DATE, FORMAT 'YYYY-MM-DD')
,:COUNTRY_CODE
,:SOURCE_SYSTEM_ID
,:DW_LOAD_TIMESTAMP (TIMESTAMP, FORMAT 'YYYY-MM-DDBHH:MI:SS.S(6)')
,:DW_UPD_LOAD_TIMESTAMP (TIMESTAMP, FORMAT 'YYYY-MM-DDBHH:MI:SS.S(6)')
,:FORCE_SKEW_KEY
);
DW_LOAD_TIMESTAMP is creating problem here.
Any idea as to why this is happening.
Regards,
Amit

Your data obviously doesn't match the FORMAT.
:DW_LOAD_TIMESTAMP(TIMESTAMP, FORMAT 'DD-MM-YYYYBHH:MI:SS.S(6)')

Related

Invalid format string in timestamp

I am trying to cast a value to timestamp(0) and insert into a table. The column Port_Out_END_Dttm is timestamp(0). It's giving me invalid format string.
,MAX(coalesce(SRC.Port_Out_END_Dttm,cast('31/12/9999 00:00:00' as timestamp FORMAT 'dd/mm/yyyyBhh:mi:ss(0)') ))as Port_Out_END_Dttm
The entire query is like:
sel
,case when Port_Out_Ver_Phase_END_Dttm in cast ('12/31/9999' as date format 'MM/DD/YYYY') then null else Port_Out_Ver_Phase_END_Dttm end as Port_Out_Ver_Phase_END_Dttm
from
(
sel
,MAX(coalesce(SRC.Port_Out_END_Dttm,cast('31/12/9999 00:00:00' as timestamp FORMAT 'dd/mm/yyyyBhh:mi:ss(0)') ))as Port_Out_END_Dttm
from table
)
First i need to coalesce the nulls to a high end date and then again take that date as null
What's wrong over here?
Thanks for your help.
There's no need to CAST a hard-coded string to a Date/Time/Timestamp, better use a Standard SQL Date/Time/Timestamp Literal instead:
TIMESTAMP '9999-12-31 00:00:00'
DATE '9999-12-31'
TIME '00:00:00'
MAX(COALESCE(SRC.Port_Out_END_Dttm, TIMESTAMP '9999-12-31 00:00:00'))
Btw, you might need to add a time zone to the literal, otherwise it might be based on your session time zone:
TIMESTAMP '9999-12-31 00:00:00+00:00'
Your syntax looks slightly off to me. Try this version:
MAX(COALESCE(SRC.Port_Out_END_Dttm,
CAST('31/12/9999 00:00:00' AS timestamp(0) FORMAT 'DD/MM/YYYYbhh:mi:ss')))

Teradata SQL Assistant Date Inserts

Context is Teradata SQL Assistant
Successfully created the following table:
CREATE VOLATILE TABLE RSN_WEEKLY_TMP, NO LOG
(
EXPLICIT_DATE DATE FORMAT 'MM/DD/YYYY'
)
PRIMARY INDEX (EXPLICIT_DATE)
ON COMMIT PRESERVE ROWS;
1) The following INSERT works successfully:
INSERT INTO JOCOOPER.RSN_WEEKLY_TMP (EXPLICIT_DATE) VALUES (CURRENT_DATE);
2) The following INSERT does not work and returns with Error:INSERT Failed [26665] Invalid date.
INSERT INTO JOCOOPER.RSN_WEEKLY_TMP (EXPLICIT_DATE) VALUES (02/02/2016);
3) However, if I use a string 'date value' and CAST it as a Date it works.
INSERT INTO JOCOOPER.RSN_WEEKLY_TMP (EXPLICIT_DATE) VALUES (CAST('02/03/2016' AS DATE FORMAT 'MM/DD/YYYY') );
I need to know how to make example #2 work? Please Advise?
02/02/2016 is an INTEGER calculation, dividing 2 by 2 by 2016, results in zero, of course this is not a valid date.
CAST('02/03/2016' AS DATE FORMAT 'MM/DD/YYYY') works because it tells the parser how to convert the string to a DATE.
The only recommended (and the shortest) way is a Standard SQL DATE literal:
DATE '2016-02-03'
You never need to think about formats because there's only one: YYYY-MM-DD
Actually, this format works too
insert into table_name (datecol) select '2015/12/31';
In your example:
CREATE VOLATILE TABLE RSN_WEEKLY_TMP, NO LOG
(
--EXPLICIT_DATE DATE FORMAT 'MM/DD/YYYY'
EXPLICIT_DATE DATE
)
PRIMARY INDEX (EXPLICIT_DATE)
ON COMMIT PRESERVE ROWS;
INSERT INTO JOCOOPER.RSN_WEEKLY_TMP (EXPLICIT_DATE) select '2016/02/02';

Remove millisecond from timestamp column in Postgres while inserting

Can any body tell how to remove or skip the millisecond part while inserting the current time to the timestamp column in Postgres database table. Actually the column that holds the data type timestamp without timezone and default is set to now() i.e. it will take the current date and time.
It inserts right date and time but it puts the millisecond part for example the format that gets entered is "2015-01-07 10:27:44.234534" which has millisecond part i.e 234534 which I don't want to be inserted. I only want the the data that is to be inserted is as "2015-01-07 10:27:44". Can any body let me know without changing the data type of that column how to insert the current date and time skipping the millisecond part.
Change your default to strip off the milliseconds:
create table foo
(
id integer not null primary key,
created_at timestamp default date_trunc('second', current_timestamp)
);
Or to change the default for an existing table:
alter table foo
alter column created_at set default date_trunc('second', current_timestamp);
To change the existing values, you can use:
update foo
set created_at = date_trunc('second', created_at)
where created_at is not null;
Instead of using date_trunc you can also just cast the value: created_at::timestamp(0) for the update statement, or current_timestamp::timestamp(0) in the default value.
As alternative, if you could modify the data type of that column, you could insert by default the CURRENT_TIME:
CREATE TABLE my_table (
col1 TEXT,
col2 INTEGER,
ts TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP
);
The 0 between parentheses is saying that you don't want any milliseconds. See the documentation for further details.

SQLite ORDER BY DATE after importing .csv file

My issue is quite weird, because it won't order my query result by its date field.. This is what I had done so far:
I create a table with schema below:
CREATE TABLE temp_price_list (
kode TEXT,
nama TEXT,
merk TEXT,
jenis TEXT,
modal TEXT,
tanggal DATE,
keterangan TEXT);
Below are my csv data:
44O2-24V,SEAL-BEAM,KOITO-II,UNIVERSAL,OL3-10,2010/12/17,OCU2-201
4401-24V,SEAL-BEAM,KOITO-II,UNIVERSAL,OL3-10,2010/10/15,OCU2-201
4401-24V,SEAL-BEAM,KYOTO,BULAT-KECIL-2COP,,2010/03/31,OL311
4402-24V,SEAL-BEAM,KYOTO,BULAT-KECIL-3COP,,2013/02/06,OLU2-IO
4402-24V,SEAL-BEAM,GEN,UNIVERSAL,,2014/04/30,IEU219
"H4-7""SEGI",SEAL-BEAM,GEN JP,UNIVERSAL,,2010/04/30,IEU211
7010-BLAT,SEAL-BEAM,RRT,12V=3COP=75W,CWU2-IO,2013/02/06,IWU2=24
7010-BLAT,SEAL-BEAM,DEPO,12V=3COP=75W,SOU222=PC,2012/01/07,IWU2=24
6014-12V,SEAL-BEAM,KYOTO,BULAT BIG 7010-12V 3C0P,OAU2-201,2010/08/10,OEU2-10
6052-12V,SEAL-BEAM,KYOTO,SEGI BESAR 3-COP,CFU2-IO,2013/02/06,CSU2-10
4402-24V,SEAL-BEAM,GEN,UNIVERSAL,CEU2-22,2010/05/26,IU311
4401-24V,SEAL-BEAM,GEN,UNIVERSAL =34=CO3,CEU2-22,2010/06/30,IU311
4001-12V,SEAL-BEAM,AIKOH,UNIVERSAL,,2010/09/17,XOU229
4002-12V,SEAL-BEAM,KYOTORRT,UNIVERSAL,,2013/02/06,OLU2-IO
4002-12V,SEAL-BEAM,GEN,UNIVERSAL,,2011/04/16,CSU222
33365-87701,SYNCROMES-KEY,SB,S-75 SMALL,,2012/01/25,O3-10
33365-87503,SYNCROMES-KEY,SB,S-75 BIG,,2012/01/25,OLRT-10
33365-87503,SYNCROMES-KEY,GB,S-75 BIG,,2012/01/25,I3-11
9-33263-048-1,SYNCROMES-KEY,GTYPE,PTER 3/4,,2010/05/31,F311
8-94152-557-0,SYNCROMES-KEY,G-TYPE,PTER 1/2,,2010/03/31,F311
Then I import those data using below command:
.mode csv
.import C:/sqlite/test.csv temp_price_list
Then I'll try to fetch the data using below query:
SELECT * FROM temp_price_list ORDER BY DATE(tanggal) DESC;
However it doesn't order it by date, just as the same ordering as the input. Any idea guys ?
I'm stuck here..
Reason - The Date information in your table is not in the correct format.
How to solve
Before inserting the data in your date column, convert the data into one of the standard date formats
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDDDDDDDD
as mentioned in the below link. http://www.sqlite.org/lang_datefunc.html
when you want to insert date to database, you can use this code.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(new Date());
In database insert the string 'date'

Date stored in table is wrong in SQLite

Can you tell my the date in the SQLite database is taking as
12/3/1899 instead of 12/3/2009.
I am inserting correct date while saving in this format. I can't understand what is the reason.What conversion has to be done in Insert Statement. Can any one help me out.
CREATE TABLE [PIs] ( [PIGUID] GUID PRIMARY KEY NOT NULL,
[CompanyGUID] GUID NOT NULL,
[No] varCHAR(50) NOT NULL,
[Dt] TIMESTAMP NOT NULL,
[SupplierLgrGUID] GUID NOT NULL,
[SupplierLgrAddressGUID] GUID NOT NULL,
[SupplierBillNo] varCHAR(50) NULL,
[SupplierBillDt] TIMESTAMP NULL,
[CrDays] INTEGER NULL,
[DueDt] TIMESTAMP NULL,
[Narration] varCHAR(300) NULL,
[CreatedDt] TIMESTAMP NOT NULL,
[LastEditedDt] TIMESTAMP NOT NULL,
)
My Insert Statement is as follow:
INSERT INTO PIs(
PIGUID,CompanyGUID,No,Dt,SupplierLgrGUID,SupplierLgrAddressGUID,
SupplierBillNo,SupplierBillDt,CrDays,DueDt,Narration,CreatedDt,
LastEditedDt)
VALUES(
'806aeec2-762a-432e-800f-0354df3b7852' ,
'375888f5-e1a5-4c75-9154-62ffc83dca97', 'PI/0809/004' ,
datetime('8/19/2009 12:44:25 PM'),
'ff376218-c2d9-4e02-86e6-e90c8d5efc43',
'7dad4725-2e37-4596-88f4-7b088f0d91c4', '0021',
datetime('8/19/2009 12:44:25 PM'), 12,
datetime('8/31/2009 12:44:25 PM'), 'narration',
datetime('now'),datetime('now')
)
I have installed SQLite 3.3.8 and my operating system is Windows Vista.
Any help would be appreciated..
Regards
Asif
The sqlite format for date is the ISO standard ie YYYY-MM-DD and not the one you have used
See Sqllite date format
Try
SELECT date('now');
to see
This link has some information you should read on using TIMESTAMP and DATETIME for SQLite.
Here's an excerpt:
TIMESTAMP, DATETIME
A string type of unlimited length used to store date/time combinations. The required format is 'YYYY-MM-DD HH:MM:SS', anything not following this pattern is ignored.
I had trouble with this one also... If your using VB.NET here is how to insert the TimeStamp, I mean DateTime into SQLlite
DateTime.UtcNow.ToString("o")
The important part is the .ToString("o") because this formats the date to ISO 8601
Here is the link that explains everything about the format - http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#Roundtrip
It looks like this when it goes into the database.
2010-12-16T02:09:55.7870590Z
But After you insert the data it looks like this.
12/16/2010 2:09:55 AM
Hope this helps someone else out there.

Resources