I'm new in cassandra and specially to the cql syntax. But I have a created a column that is timestamp which gets me datetime as this '2018-05-18 03:08:58.246000+0000' but where I filter by created I get this error
InvalidRequest: Error froim server: code=2200 [Invalid query] message="Unable to coerce '2018-05-18 03:08:58.246000+0000' to formatted date (long)"
Which lead me to think that I either need to convert the datetime into a tick or do some sort of casting.
how convert datetime to timestamp on cqlsh in a where clause?
Although Cassandra stores timestamp fractions using the .ffffff format defined by the ISO 8601 standard as you mentioned.
cqlsh:test_keyspace> select * from timestamp_table ;
timestamp | other_field
---------------------------------+---------------
2018-05-18 03:08:58.246000+0000 | Other content
2018-05-18 03:08:58.000000+0000 | Other content
When interacting with the database (ie. INSERT, SELECT, ...) you need to use the .fff format like so:
cqlsh:test_keyspace> select * from timestamp_table WHERE timestamp='2018-05-18 03:08:58.123+0000';
timestamp | other_field
---------------------------------+---------------
2018-05-18 03:08:58.123000+0000 | Other content
Otherwise you will get the error you mentioned.
Error when Reading
cqlsh:test_keyspace> select * from timestamp_table WHERE timestamp='2018-05-18 03:08:58.123000+0000';
InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to coerce '2018-05-18 03:08:58.123000+0000' to a formatted date (long)"
Error when writing
cqlsh:test_keyspace> INSERT INTO timestamp_table (timestamp , other_field ) VALUES ( '2018-05-18 03:08:58.123456+0000', 'Other content');
InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to coerce '2018-05-18 03:08:58.123456+0000' to a formatted date (long)"
Related
In my ADF pipeline I am trying to convert an output from my lookup activity to be in YYYY-MM-DD hh:mm:ss date format within the source query of a copy activity. The current output from my lookup activity is in YYYY-MM-DDThh:mm:ss format and I need to remove the 'T'.
I have tried using the dynamic content and formatDateTime functions but am having problems with the syntax. I am also using an SQL query to retrieve only the relevant data. The below is what I am
using as an input in the dynamic content query. I am able to get this to work, but I need to change '03/15/2018 12:00:00' to refer to the output of my lookup activity named LookupNewWaterMarkActivity.
SELECT *
FROM tableName
WHERE updatedDate >
'#{formatDateTime('03/15/2018 12:00:00', 'yyyy-MM-dd HH:mm:ss')}'
I have tried the below, but get the following error message:
'cannot fit package::output:any & { count, value } into the function parameter string. (6)'
SELECT *
FROM tableName
WHERE updatedDate >
'#{formatDateTime(activity('LookupNewWaterMarkActivity').output, 'yyyy-MM-dd HH:mm:ss')}'
Does anyone know how I can format the output of my activity within an SQL query any other way?
I am getting the below error when running the below code.
#concat('SELECT * FROM tableName WHERE sys_updated_on_value > ''',formatDateTime(activity('LookupNewWaterMarkActivity').output.value[0].sys_updated_on_value, 'yyyy-MM-dd HH:mm:ss'),'''')
Error code: FailToResolveParametersInExploratoryController
Details
The parameters and expression cannot be resolved for schema operations.
Error Message: { "message": "ErrorCode=InvalidTemplate,
ErrorMessage=The expression 'concat('SELECT * FROM tableName WHERE
sys_updated_on_value >
''',formatDateTime(activity('LookupNewWaterMarkActivity').output.value[0].sys_updated_on_value,
'yyyy-MM-dd HH:mm:ss'),'''')\n\n' cannot be evaluated because property
'value' doesn't exist, available properties are 'value[0]'.." }
Use the lookup activity output (activity('Lookup1').output.value[0].columnName) value in your expression with column name as shown below to refer the lookup activity output in later activities.
Lookup activity output:
Copy activity:
Expression:
#concat('SELECT * FROM tb2 WHERE date1 > ''',formatDateTime(activity('Lookup1').output.value[0].date1, 'yyyy-MM-dd HH:mm:ss'),'''')
Update:
If you have enables firstRow property in your lookup, use the below expression:
#concat('SELECT * FROM tb2 WHERE date1 > ''',formatDateTime(activity('Lookup1').output.firstRow.date1, 'yyyy-MM-dd HH:mm:ss'),'''')
I want to restrict the rows I retrieve by using 'between' for two dates.
The 'saledate' column I used has the following infomation
SALEDATE DATE FORMAT 'YYYY-MM-DD' NOT NULL
The code I used:
SELECT *
FROM trnsact
WHERE saledate BETWEEN '2005-01-01' AND '2005-06-30';
And then I got an error 'Error Code - 3535
Error Message - [Teradata Database] [TeraJDBC 15.10.00.09] [Error 3535][SQLState 22003]
A character string failed conversion to a numeric value.'
I also tried with DATE:
SELECT *
FROM trnsact
WHERE saledate BETWEEN DATE '2005-01-01' AND DATE '2005-06-30';
But end up with another error
Error Message - [Teradata Database] [TeraJDBC 15.10.00.09] [Error 3706] [SQLState 42000] Syntax error: Invalid DATE Literal.
Thanks for your help
You need to use DATE literals:
SELECT *
FROM trnsact
WHERE saledate BETWEEN DATE '2005-01-01' AND DATE '2005-06-31';
try below query for teradata. It's too late though.
SELECT *
FROM trnsact
WHERE saledate BETWEEN
to_date('2005-01-01','YYYY-MM-DD') AND
to_date('2005-06-30','YYYY-MM-DD') ;
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')))
gql_query.query_string = "SELECT * FROM <entity> where `timestamp` <= datetime('2014-06-05 00:00:00')"
gql_query.allow_literal = True
resp = datastore.run_query(req)
results = [entity_result.entity
for entity_result in resp.batch.entity_result]
When I run above query it produces error as follows:
ERROR:root:Error while doing datastore operation
ERROR:root:RPCError: runQuery Invalid datetime text (does not match pattern): "2014-06-05 00:00:00"
ERROR:root:HTTPError: 400 Bad Request
Cloud Datastore GQL uses RFC 3339 section 5.6 to represent datetime strings. In this case, you would need to use a 'T' between the date and time rather than a space and append a 'Z' to the end of the string:
SELECT * FROM <entity> WHERE `timestamp` <= datetime('2014-06-05T00:00:00Z')
Full documentation on synthetic literals, including more detailed information about datetime literals, can be found here.
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';