Redshift Extract Function issue - sql

While using this query:
SELECT date_time
FROM test_table
where EXTRACT('epoch' FROM CONVERT_TIMEZONE(replace(timezone, '+', '-'),date_time::timestamp)) >= 1513036800
and EXTRACT('epoch' FROM CONVERT_TIMEZONE(replace(timezone, '+', '-'),date_time::timestamp)) <= 1513555200
limit 10
I am getting this error:
An error occurred when executing the SQL command:
[Amazon](500310) Invalid operation: Invalid data
Details:
-----------------------------------------------
error: Invalid data
code: 8001
context: Invalid format or data given: 0000-00-00 00:00:00
query: 1909217
location: funcs_timestamp.cpp:219
process: query1_59 [pid=25572]
-----------------------------------------------;
1 statement failed.
Execution time: 0.63s
I am unable to use "Extract" function two times in a single query.
I have tried to use "Between" as well. but that did not work.
If I remove one of any extract query from the date range. Then it would work.

Related

BigQuery - Error while reading table:Could not convert value to date. Error: Invalid date:

I'm trying to read a Google Sheet in BQ. After selecting auto-detect schema, I get this error on trying to run the query. I'm not sure what do I need to adjust in the date schema to make the query work.
SELECT date FROM proejct.dataset.table LIMIT 1000
Sharing the error and two screenshots from the query
Error while reading table: project.dataset.table, error message: Could not convert value to date. Error: Invalid date: '1/15/2011'. Row 1; Col 2.
The format YYYY-MM-DD should work for you
select DATE "2021-1-1"

Snowflake SQL compilation error: syntax error line XX at position XX unexpected '('

While running SQL query on Snowflake, I am getting syntax error that I have unexpected '('. Below is the code that is giving me the error.
,(EndOrder_time) - min(StartOrder_time) over (
partition by EntryNumber, TechnicianEnterpriseID
order by RouteDateTime rows between 1 preceding and current row
) day (4) to second as Repair_Time
Snowflake calculates timestamp diffs in this way:
DATEDIFF(SECONDS, StartOrder_time, EndOrder_time)
Snowflake added the ability to use the + and - for date math in November. "day (4) to second" is not Snowflake syntax

Convert date to specific format using Postgresql

I am needing to convert records where the TEXT values look like this using Postgresql:
26-AUG-2015
to:
2015-08-26
I'm not sure what version of Postgresql exists on the vendor server but I tried to do a select statement using:
SELECT to_char(sle.log_field1, 'YYYY-MM-DD')
FROM student_log_entires sle;
But I'm getting this error:
Error: SQL Error: SQLSTATE[42883]: Undefined function: 7 ERROR: function to_char(text, unknown) does not exist LINE 25: AND to_char(sle.log_field1, 'YYYY-MM-DD') >=... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.
I did also try:
SELECT to_date(sle.log_field1, 'YYYY-MM-DD')
FROM student_log_entries sle
But I got this error:
Error: SQL Error: SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid value "[E] " for "YYYY" DETAIL: Value must be an integer. Query: SELECT to_date(sle.log_field1, 'YYYY-MM-DD') FROM student_log_entries sle
Any suggestions/direction would be appreciated. Thanks.
This assumes that lc_time is set to English:
SELECT to_char(to_date('26-AUG-2015', 'DD-MON-YYYY'), 'YYYY-MM-DD');
to_char
------------
2015-08-26
(1 row)
You can convert the value to a date and then back to a string:
select to_char(to_date('26-AUG-2015', 'DD-MON-YYYY'), 'YYYY-MM-DD')
Under many circumstances, processing the value as a date is probably sufficient.
Your approach doesn't work because the value is apparently already stored as a string, so converting it back to a string with a date format doesn't make sense.
EDIT:
You may be able to get by using a simple regular expression:
select (case when col ~ '^[0-9]{2}[-][A-Z]{3}[-][0-9]{4}$'
then to_char(to_date('26-AUG-2015', 'DD-MON-YYYY'), 'YYYY-MM-DD')
end)
Of course, if the formatting errors are more subtle, then a more complex regular expression would be needed.
try this,
SELECT to_char(sle.log_field1, 'YYYY-MM-DD') FROM student_log_entires sale;

Date Manipulation in Informix DB

based on other forum entries, I believe that I need to utilise the below code to convert a date in Informix to a month:
select
MONTH(DATE_FIELD) as "Month Conversion"
from TABLE
Unfortunately when I run it, I get this error
Error: ERROR Mixed numeric and alpha operands in expression -
job_cost_master.jcm_start_date SQLState: 42000 ErrorCode: -1
You cannot use a column ALIAS with spaces and/or in quotes.
This should work:
select
MONTH(DATE_FIELD) as month_conversion
from TABLE
Regards

Ingres error trying to query timestamp without timezone column

I'm trying to write a query on a column that's of the time "Timestamp without timezone" and this is my where clause:
and (cv.expire_ts >= 'today' or ifnull(cv.expir_ts, '') = '')
I get the following error:
Error: 'today' is invalid format or value for timestamp without time zone or timestamp with local time zone. Please enter a valid timestamp value in yyyy-mm-dd hh:mm:ss[.fff...] format.
SQLState: 22007
ErrorCode: 4328
Error: Specified cursor is not known to the server.
SQLState: 24000
ErrorCode: 590366
How can I make this query work on this type of column?
Try using the CURRENT_DATE constant, without quotes.
I think missing part is date function for 'today'
Refer