What is redshift equivalent of NLS_DATE_FORMAT ?
For example , I want to set date format to below format
ALTER SESSION SET NLS_DATE_FORMAT='YYYYMMDDHH24MISS';
Redshift does not have such a configuration option. The only thing you can control is the datestyle: http://docs.aws.amazon.com/redshift/latest/dg/r_SET.html
Literals follow this style: http://docs.aws.amazon.com/redshift/latest/dg/r_Date_and_time_literals.html
you can manipulate the timestamp format to be like that, then update the value you have like
update table set timestamp = cast(to_char(timestamp, 'YYYYMMDDHHMMSS') as bigint)
so '2016-12-31 02:43:23' will be 20161231024323
Related
We are making use of tRedshiftOutputBulk exec and we have set it to 'Drop table if exists and create' as an action on table. The problem is that a Date field of with a pattern of 'yyyy-MM-dd HH:mm:ssZ' is being created as Timestamp rather than TimestampTZ on Redshift.
#mark
What pattern have you given in Date format and Time format field of the component?
you can use the change time pattern 'yyyy-MM-dd HH:mm:ssTZ'
I am creating a table that will be populated with a COPY. Here's the format of that data:
6/30/2014 2:33:00 PM
MM-DD-YYYY HH:MM:SS ??
What would I use as the formatting for the CREATE TABLE statement?
CREATE TABLE practice (
Data_Time ????
)
One alternative might be to read as varchar() then format later. Seems convoluted tho.
Always store timestamps as timestamp (or timestamptz).
Never use string types (text, varchar, ...) for that.
CREATE TABLE practice (
practice_id serial PRIMARY KEY
, data_time timestamp NOT NULL
);
If your timestamp literals are clean and follow the standard MDY format, you can set the DateStyle temporarily for the transaction to read proper timestamp types directly:
BEGIN;
SET LOCAL datestyle = 'SQL, MDY'; -- works for your example
COPY practice (data_time) FROM '/path/to/file.csv';
COMMIT;
Else, your idea is not that bad: COPY to a temporary table with a text column, sanitize the data and INSERT timestamps from there possibly using to_timestamp(). Example:
Formatting Date(YY:MM:DD:Time) in Excel
You should pretty much never use vharchar() in postgres. Always use text. But it sounds to me like you want 2 columns
create table practice (date_time timestamp, format text)
create automatic datetime(date with timestamp) when update the data in postgresql(phppgadmin) on database table
Plese advise me
thanks
1.if you use timestamp type in the column when you update the record then date time also updated
2.if you use varchar type in the column when you fire a query
demo
$sql = "update table_name set field_name=now() where your condition";
Is there any other way to get datetime field from oracle database in 24hour format???like
-> "select getxsddate(col_name) from tab_name" will get you datetime format as "2012-04-04T12:31:00"...I wanted to know if there are any other ways as i`m not satisfied with this format.
select to_char(col_name, 'yyyy-mm-dd hh24:mi:ss') from tab_name
You can read more about to_char function here
Another very simple way is to set, in the database nls parameters, the parameter date_format='DD-MM-YYYY HH24:MI:SS'
I am using Perl's DBD::ODBC to connect to an Oracle database. However, an issue arises when I try to execute a select query using a date in the where clause. It seems this issue occurs because of the database's date format being DD-MON-RR (see DBD::ODBC::FAQ). Since I cannot change the database's settings, can anyone suggest a workaround?
The database's default date format only matters if you depend on it, which you should not in general. You can:
1) Specify the format of the date in your query:
select *
from news
where news_date = to_date ('01-DEC-2009','DD-MON-RRRR');
2) Use the ANSI standard for date literals:
select *
from news
where news_date = DATE '2009-12-01';
One option is to use the TO_DATE() function (or the ANSI 'DATE' keyword) to convert the format in every query:
WHERE date_field > TO_DATE('2009-11-01', 'YYYY-MM-DD');
-- or
WHERE date_field > DATE '2009-11-01'
If you have to do this a lot, a better option would be to set the format for the session:
$dbh->do("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
$dbh->do("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SSxFF'");
$dbh->do("ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SSxFF'");
Then:
my $sth = $dbh->prepare(<<EOT);
SELECT date_field
FROM some_table
WHERE date_field > '2009-11-01'
EOT
Don't rely on implicit datatype conversion. You can always specify the date format in the where clause:
WHERE your_column = to_date(:your_parameter, 'yyyy/mm/dd')