Ingres error trying to query timestamp without timezone column - sql

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

Related

Multiple to_timestamp() transformation in SELECT

I am currently having a varchar tm column, that stores timestamps such as: '15.11.2021 11:07:27'
The datestyle is currently set to ISO,MDY
How can I transform that varchar using SELECT value in order to preserve its format?
If I use to_timestamp(tm, 'DD.MM.YYYY HH24:MI:SS')::timestamp without time zone I still get it in other format 2021-11-15 11:07:27
I also tried to do double to_timestamps, but then an error function to_timestamp(timestamp with time zone, unknown) does not exist appears.
So the question is: Is there any way to convert from varchar type "15.11.2021 11:07:27" to timestamp type 15.11.2021 11:07:27 using select statement?
DbFiddle
PS. Even though I used it in DBFiddle, I cant change datestyle on the target server
Postgres version 13.5
EDIT: also, if I use cast(tm as timestamp) I receive date/time field value out of range: "15.11.2021 11:07:27" error.
You could try using:
CONVERT(varchar, timestamp, 103) AS YOUR_VALUE
This way you would convert timestamp without changing its original form.

Converting string to timestamp issues sql

I'm trying to cast a string to timestamp but I'm getting the following error:
Failed to output to file. Query failed: Value cannot be cast to timestamp: 2020-03-23T05:17:44.000Z
I'm using the query below:
select CAST(purchase_date AS timestamp)
from main_table
You can use from_iso8601_timestamp function if timestamp with time zone type is acceptable.
Or, you can use date_parse function.
Try parse_datetime():
select parse_datetime('2020-03-23T05:17:44.000Z', '%Y-%m-%dT%H:%i:%s.%fZ')

sql teradata filtering on date - database version Teradata 15.10.06.02 and provider version Teradata.Net 15.11.0.0

my table has a date column. its data type is date. I confirmed it by going to table name>>columns and it says MTH_END_DT [DATE, Not NULL]
I want to filter my data for a particular date. If I put a condition where MTH_END_DT = '6/1/2018' I get an error select failed [3535] A character string failed conversion to a numeric value.
I followed this page. I used where MTH_END_DT = date '6/1/2018' and i get an error syntax error invalid date literal
I tried where cast(timestamp_column as date) = date '2013-10-22'; something like this and it throws error too
How should i filter my data?
There's only one reliable way to write a date, using a date literal, date 'yyyy-mm-dd'
where MTH_END_DT = DATE '2018-06-01'
For a Timestamp it's
TIMESTAMP '2018-06-01 15:34:56'
and for Time
TIME '15:34:56'
In SQL Assistant it's recommended to switch to Standard SQL format YYYY-MM-DD in Tools-Options-Data Format-Display dates in this format
I did have the similar problem when I was filtering a particular date for my query with Teradata. First method I tried was putting 'DATE' term as the following:
WHERE saledate = DATE'04/08/01' but this did not solve the problem.
I then used an approach I stumbled upon when surfing, finally it worked.
WHERE extract(year from saledate)=2004 AND extract(MONTH from saledate)=8 AND extract(DAY from saledate)= 1 source
I think this really should not be this long, but it worked.
It seems to me it’s most likely you have input the date format incorrectly? Maybe it includes a time by default.
For example
where MTH_END_DT = ‘2013-10-22-00:00:00:00’

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;

Error in Casting date postgreSQL

I'm trying to cast a varchar into a date with this following code, and the following error is outputting, any idea why?
ALTER TABLE import.employee
ALTER COLUMN birth_date
TYPE date
USING (birth_date::date);
ERROR: date/time field value out of range: "05/29/1960"
HINT: Perhaps you need a different "datestyle" setting.
********** Error **********
ERROR: date/time field value out of range: "05/29/1960"
SQL state: 22008
Hint: Perhaps you need a different "datestyle" setting.
Set the datestyle before:
set datestyle = mdy;
If you need to get the ::date from birth_date, first give the DATE format to your field using the given functions in Data Type Formatting Functions docs.