I have a table with a date column that I know is stored in GMT. I have a procedure that accepts a date input and an account ID. The procedure:
1) gets the account ID timezone (stored in table account)
2) determines the start and end range in GMT as follows:
v_start_time := cast( from_tz( cast( i_date as timestamp ), v_tz ) at time zone c_gmt as date ); -- where i_date is input, v_tz is 'US/Eastern' or any other tzname from v$timezone_names, and c_gmt is the string 'GMT'
v_end_time := v_start_time + 1; -- Add exactly one day to start date
3) return sys_refcursor to caller as:
open o_cur for
select gmt_col, some_value
from my_table
where account_id = i_account_id
and gmt_col between v_start_time and v_end_time;
However, the developer would like both the gmt_date and the local time in the cursor. First, I attempted to use the exact same conversion method as I had to determine v_start_time, that is:
open o_cur for
select gmt_col,
cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone v_tz as date ) as local_time, some_value
from my_table
where account_id = i_account_id
and gmt_col between v_start_time and v_end_time;
However, when compiled, this results in ORA-00905: missing keyword. I attempted to add the single quotes around the "v_tz" like: chr( 39 ) || v_tz || chr( 39 ), but that doesn't work - the proc compiles, but when I open the cursor, I get ORA-01882: timezone region not found. After a bit of experimentation, here are two solutions that allow "at time zone" to work smoothly in sql:
SOLUTION 1:
open o_cur for
select gmt_col,
cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone ( select v_tz from dual ) as date ) as local_time, some_value
from my_table
where account_id = i_account_id
and gmt_col between v_start_time and v_end_time;
SOLUTION 2:
in package spec:
function echo( i_sound in varchar2 ) return varchar2;
pragma restrict_references( echo, wnps, rnps, wnds, rnds );
in package body:
function echo( i_sound in varchar2 ) return varchar2 is begin return i_sound; end;
in procedure:
open o_cur for
select gmt_col,
cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone echo( v_tz ) as date ) as local_time, some_value
from my_table
where account_id = i_account_id
and gmt_col between v_start_time and v_end_time;
Performance appears to be comparable for each. The second solution hints at something I've started to do recently, which is to use functions to return "constants" with pragma restrict_references, so I can use the constant values flexibly between pl/sql and sql. For example:
function c_gmt return varchar2;
pragma restrict_references( c_gmt, wnds, rnds, wnps, rnps );
select * from v$timezone_names where tzabbrev = c_gmt;
select c_gmt from dual;
v_start_time := blah blah blah || c_gmt;
etc...
You shouldn't need the extra select from dual. Just putting the variable in parenthesis should do the trick (don't ask me why though):
open o_cur for
select gmt_col,
cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone (v_tz) as date ) as local_time, some_value
from my_table
where account_id = i_account_id
and gmt_col between v_start_time and v_end_time;
Related
I have some SQL code, which works as designed. I'm trying to convert the code to a procedure to make it flexible so that different values maybe passed in.
I am running into an error while trying to create the procedure.
Errors: PROCEDURE CREATE_XXX
Line/Col: 28/1 PL/SQL: SQL Statement ignored
Line/Col: 37/3 PL/SQL: ORA-00928: missing SELECT keyword
The problem seems to be occurring in a CTE, which contains a SELECT so I'm a bit confused and can use some assistance.
Below is a test CASE that contains the working SQL along with the procedure I'm trying to create.
Thanks in advance for your help, patience and expertise and to all who answer.
ALTER SESSION SET NLS_DATE_FORMAT = 'MMDDYYYY HH24:MI:SS';
create table schedule(
schedule_id NUMBER(4),
location_id number(4),
base_date DATE,
start_date DATE,
end_date DATE,
CONSTRAINT start_min check (start_date=trunc(start_date,'MI')),
CONSTRAINT end_min check (end_date=trunc(end_date,'MI')),
CONSTRAINT end_gt_start CHECK (end_date >= start_date),
CONSTRAINT same_day CHECK (TRUNC(end_date) = TRUNC(start_date))
);
/
CREATE TABLE locations AS
SELECT level AS location_id,
'Door ' || level AS location_name,
CASE round(dbms_random.value(1,3))
WHEN 1 THEN 'A'
WHEN 2 THEN 'T'
WHEN 3 THEN 'T'
END AS location_type
FROM dual
CONNECT BY level <= 15;
ALTER TABLE locations
ADD ( CONSTRAINT locations_pk
PRIMARY KEY (location_id));
-- works fine
WITH params AS
(
SELECT 1 AS schedule_id,
TO_DATE ( '2021-08-21 00:00:00'
, 'YYYY-MM-DD HH24:MI:SS'
) AS base_date
, INTERVAL '83760' SECOND AS offset
, INTERVAL '10' MINUTE AS incr
, INTERVAL '5' MINUTE AS duration
FROM dual
)
SELECT p.schedule_id
, l.location_id
, p.base_date
, p.base_date + offset
+ (incr * (ROWNUM - 1)) AS start_date
, p.base_date + offset
+ (incr * (ROWNUM - 1))
+ p.duration AS end_date
FROM locations l
CROSS JOIN params p
ORDER BY start_date
;
-- having problem
CREATE OR REPLACE PROCEDURE CREATE_XXX
(
i_schedule_id IN PLS_INTEGER,
i_base_date IN DATE,
i_offset IN PLS_INTEGER DEFAULT 0,
i_incr IN PLS_INTEGER DEFAULT 10,
i_duration IN PLS_INTEGER DEFAULT 5
)
AS
l_offset interval day to second;
l_incr interval day to second;
l_duration interval day to second;
BEGIN
l_offset :=
NUMTODSINTERVAL(i_offset, 'SECOND') ;
l_incr :=
NUMTODSINTERVAL(i_incr, 'MINUTE') ;
l_duration :=
NUMTODSINTERVAL(i_duration, 'MINUTE') ;
WITH params AS(
SELECT
i_schedule_id
,i_base_date
,l_offset
,l_incr
,l_duration
FROM DUAL
)
INSERT INTO schedule(
schedule_id
,location_id
,base_date
,start_date
,end_date
)
VALUES
(p.schedule_id
,l.location_id
,p.base_date
,start_date
,end_date
);
SELECT p.schedule_id
, l.location_id
, p.base_date
, p.base_date + p.offset
+ (p.incr * (ROWNUM - 1)) AS start_date
, p.base_date + p.offset
+ (p.incr * (ROWNUM - 1))
+ p.duration AS end_date
FROM locations l
CROSS JOIN params p
ORDER BY start_date;
END;
/
The issue is this statement.
WITH params AS(
SELECT
i_schedule_id
,i_base_date
,l_offset
,l_incr
,l_duration
FROM DUAL
)
INSERT INTO schedule(
schedule_id
,location_id
,base_date
,start_date
,end_date
)
VALUES
(p.schedule_id
,l.location_id
,p.base_date
,start_date
,end_date
);
I'm not sure what you're trying to accomplish. Syntactically, if you want to have a CTE as part of an insert, you'd want to do an insert ... select
INSERT INTO schedule(
schedule_id
,location_id
,base_date
,start_date
,end_date
)
WITH params AS(
SELECT
i_schedule_id
,i_base_date
,l_offset
,l_incr
,l_duration
FROM DUAL
)
SELECT
p.schedule_id
,l.location_id
,p.base_date
,start_date
,end_date
FROM params p;
From there, though, you've still got several syntax issues that it's not obvious how you'd want to solve all of them.
p.schedule_id isn't valid because there is no schedule_id column in the params CTE. My guess is that you want to alias i_schedule_id to schedule_id in the CTE.
l.location_id doesn't make sense because you're not selecting from a table that could plausibly be given an alias of l.
There is no base_date, start_date, or end_date column in your params CTE. And it's not obvious how you'd plausibly fix that.
Maybe you actually intended the subsequent select statement to actually be part of this insert statement despite the fact that you terminated the insert with a semicolon? If so, maybe you want
INSERT INTO schedule(
schedule_id
,location_id
,base_date
,start_date
,end_date
)
WITH params AS(
SELECT
i_schedule_id schedule_id
,i_base_date base_date
,l_offset offset
,l_incr incr
,l_duration duration
FROM DUAL
)
SELECT p.schedule_id
, l.location_id
, p.base_date
, p.base_date + p.offset
+ (p.incr * (ROWNUM - 1)) AS start_date
, p.base_date + p.offset
+ (p.incr * (ROWNUM - 1))
+ p.duration AS end_date
FROM locations l
CROSS JOIN params p
ORDER BY start_date;
That would produce code that compiles at least. There doesn't, however, appear to be any reason to bother with a CTE here at all. Just reference the local variables and input parameters directly. I've also eliminated the order by since it doesn't make sense in the context of an insert statement. I assume there is a reason that you need to take input parameters as integers and convert them to local variables with the same name and a different data type rather than just passing in interval parameters to the procedure. If you can do that, you can further simplify things by eliminating the local variables.
CREATE OR REPLACE PROCEDURE CREATE_XXX
(
i_schedule_id IN PLS_INTEGER,
i_base_date IN DATE,
i_offset IN PLS_INTEGER DEFAULT 0,
i_incr IN PLS_INTEGER DEFAULT 10,
i_duration IN PLS_INTEGER DEFAULT 5
)
AS
l_offset interval day to second;
l_incr interval day to second;
l_duration interval day to second;
BEGIN
l_offset :=
NUMTODSINTERVAL(i_offset, 'SECOND') ;
l_incr :=
NUMTODSINTERVAL(i_incr, 'MINUTE') ;
l_duration :=
NUMTODSINTERVAL(i_duration, 'MINUTE') ;
INSERT INTO schedule(
schedule_id
,location_id
,base_date
,start_date
,end_date
)
SELECT i_schedule_id
, l.location_id
, i_base_date
, i_base_date + l_offset
+ (l_incr * (ROWNUM - 1)) AS start_date
, i_base_date + l_offset
+ (l_incr * (ROWNUM - 1))
+ l_duration AS end_date
FROM locations l;
END;
/
I have a view where I am selecting a date column and reading it as a local date in denodo. In my column, I have a date '00-Jan-1900' like this which is giving issue so I wanted to replace this with empty.
When I run this query, I get results as shown in the table2. But what I want is just an empty record in place of this date and looking like TABLE3.
Query:
select
to_localdate('dd-MM-yyyy', substring(replace("DATE", '00-Jan-1900', ''), 0, 10)) AS dtm
from XX
Table1:
DATE
22-Dec-2016
00-Jan-1900
30-Sep-2014
After replacing the date i get
Table2:
DATE
0201-12-22
0201-09-30
Is there a way i get output table like this?
TABLE3:
DATE
22-Dec-2016
30-Sep-2014
In my column, I have a date '00-Jan-1900' like this which is giving issue so I wanted to replace this with empty.
In Oracle, you can use:
UPDATE table_name
SET value = NULL
WHERE EXTRACT( DAY FROM value ) = 0;
If you have the table:
CREATE TABLE table_name ( value DATE );
Then, some extra hoops need to be jumped through to insert an invalid date (namely generating the date from binary data so that the normal validation process for date values can be skipped) by creating this function:
CREATE FUNCTION createDate(
year int,
month int,
day int,
hour int,
minute int,
second int
) RETURN DATE DETERMINISTIC
IS
hex CHAR(14);
d DATE;
BEGIN
hex := TO_CHAR( FLOOR( year / 100 ) + 100, 'fm0X' )
|| TO_CHAR( MOD( year, 100 ) + 100, 'fm0X' )
|| TO_CHAR( month, 'fm0X' )
|| TO_CHAR( day, 'fm0X' )
|| TO_CHAR( hour + 1, 'fm0X' )
|| TO_CHAR( minute + 1, 'fm0X' )
|| TO_CHAR( second + 1, 'fm0X' );
DBMS_OUTPUT.PUT_LINE( hex );
DBMS_STATS.CONVERT_RAW_VALUE( HEXTORAW( hex ), d );
RETURN d;
END;
/
Then, you can have the data:
INSERT INTO table_name ( value )
SELECT DATE '1900-01-01' FROM DUAL UNION ALL
SELECT createDate( 1900, 1, 0, 0, 0, 0 ) FROM DUAL;
and:
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
SELECT value,
TO_CHAR( value, 'YYYY-MM-DD HH24:MI:SS' ) AS string_value
FROM table_name;
Outputs:
VALUE | STRING_VALUE
:------------------ | :------------------
1900-01-01 00:00:00 | 1900-01-01 00:00:00
1900-01-00 00:00:00 | 0000-00-00 00:00:00
To get rid of your invalid value, you can use:
UPDATE table_name
SET value = NULL
WHERE EXTRACT( DAY FROM value ) = 0;
Then:
SELECT value,
TO_CHAR( value, 'YYYY-MM-DD HH24:MI:SS' ) AS string_value
FROM table_name;
Outputs:
VALUE | STRING_VALUE
:------------------ | :------------------
1900-01-01 00:00:00 | 1900-01-01 00:00:00
null | null
db<>fiddle here
Is there a way i get output table like this?
TABLE3:
DATE
22-Dec-2016
30-Sep-2014
You can use:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-Mon-YYYY';
And then just run your query and it should change the output (but you will need to make sure the format is set in future sessions when you run the query).
Or you can specify the format model using TO_CHAR:
SELECT TO_CHAR( your_column, 'DD-Mon-YYYY' ) AS your_column
FROM your_table
I have made this query but when I execute it, I got error about "invalid number".
But in SQL Developer for Oracle, there is no error; I got the result that I want but in Toad I got 'Invalid Number' .
DECLARE v_rep number;
BEGIN
EXECUTE IMMEDIATE
'SELECT to_number(REPLACE(max(substr(to_char(r_timestamp_arr,''HH24:MI''),1,2) ||
ltrim(to_char(round(to_number(Substr(to_char(r_timestamp_arr, ''HH24:MI''),4,2)) /
60,2),''.00''))), ''.'', '','')) -
to_number(REPLACE(MIN(substr(to_char(r_timestamp_arr,''HH24:MI''),1,2) ||
ltrim(to_char(round(to_number(Substr(to_char(r_timestamp_arr, ''HH24:MI''),4,2)) /
60,2),''.00''))), ''.'', '',''))
FROM TV_MAX
WHERE TV_UID = ''7a87e8e4861a4d0aae65da1a7248b256'''
INTO v_rep;
END ;
You don't need EXECUTE IMMEDIATE and don't need to use strings:
Oracle Setup:
CREATE TABLE tv_max ( tv_uid, r_timestamp_arr ) AS
SELECT '7a87e8e4861a4d0aae65da1a7248b256', DATE '2019-12-27' + INTERVAL '00:00' HOUR TO MINUTE FROM DUAL UNION ALL
SELECT '7a87e8e4861a4d0aae65da1a7248b256', DATE '2019-12-27' + INTERVAL '01:30' HOUR TO MINUTE FROM DUAL;
Query 1:
If you want to ignore the date component of the date & time:
DECLARE
v_rep NUMBER;
BEGIN
SELECT ( MAX( r_timestamp_arr - TRUNC( r_timestamp_arr ) )
- MIN( r_timestamp_arr - TRUNC( r_timestamp_arr ) )
) * 24
INTO v_rep
FROM tv_max
WHERE TV_UID = '7a87e8e4861a4d0aae65da1a7248b256';
DBMS_OUTPUT.PUT_LINE( v_rep );
END;
/
Query 2:
If you want the min/max respecting the date component then the query can be even simpler:
DECLARE
v_rep NUMBER;
BEGIN
SELECT ( MAX( r_timestamp_arr ) - MIN( r_timestamp_arr ) ) * 24
INTO v_rep
FROM tv_max
WHERE TV_UID = '7a87e8e4861a4d0aae65da1a7248b256';
DBMS_OUTPUT.PUT_LINE( v_rep );
END;
/
Output:
For the test data, both output:
1.5
db<>fiddle here
Looks like You want to know the difference between max and min hour (including minutes, excluding seconds), date part truncated. So take truncated times, subtract as dates, you will get result in days, multiply by 24, result will be in hours. Query does not depend on NLS settings:
select 24 * (to_date(max(to_char(r_timestamp_arr, 'hh24:mi')), 'hh24:mi')
- to_date(min(to_char(r_timestamp_arr, 'hh24:mi')), 'hh24:mi')) as diff
from tv_max
where tv_uid = '7a87e8e4861a4d0aae65da1a7248b256'
dbfiddle
I have a PROCESS_TIME with data type VARCHAR2(32),
in which I store the times as hh24:mi:ss,
and I intend to add these times on some grouping logic.
A minified version of the table
CREATE TABLE "SCHEMA"."MY_TABLE"
( "MY_TABLE_ID" VARCHAR2(32 BYTE) NOT NULL ENABLE,
"START_TIME" DATE NOT NULL ENABLE,
"END_TIME" DATE NOT NULL ENABLE,
"LOAD_PROCESS_TIME" VARCHAR2(32 BYTE) DEFAULT '00:00:00',
)
and a minified version of Insert
Insert into MY_TABLE (MY_TABLE_ID,START_TIME,END_TIME,LOAD_PROCESS_TIME)
values ('8880508C9AC4441DB8E16E023F206C2F',to_date('05/11/2018 07:22','MM/DD/YYYY HH:MI'),to_date('05/11/2018 08:22','MM/DD/YYYY HH:MI'),'01:00:14');
Insert into MY_TABLE (MY_TABLE_ID,START_TIME,END_TIME,LOAD_PROCESS_TIME) values ('C858EB646A794D04B5C77779C50EBFCF',
to_date('05/12/2018 10:20','MM/DD/YYYY HH:MI'),
to_date('05/12/2018 11:20','MM/DD/YYYY HH:MI'),
'02:30:10');
Intended Query
SELECT TO_CHAR(TRUNC(END_TIME, 'DD'), 'DD-MON-YY'),
sum(LOAD_PROCESS_TIME)
FROM MY_TABLE
WHERE END_TIME > SYSDATE -14
GROUP BY TRUNC(END_TIME,'DD')
ORDER BY TRUNC(END_TIME,'DD');
Can you please help me achieve this using Oracle SQL?
You can calculate the time interval as a fractional number of days and sum that:
SQL Fiddle
Oracle 11g R2 Schema Setup:
CREATE TABLE table_name ( PROCESS_TIME ) AS
SELECT '01:23:04' FROM DUAL UNION ALL
SELECT '23:00:00' FROM DUAL UNION ALL
SELECT '11:36:56' FROM DUAL;
Query 1:
SELECT SUM(
TO_DATE( PROCESS_TIME, 'HH24:MI:SS' )
- TO_DATE( '00:00:00', 'HH24:MI:SS' )
) AS num_days
FROM table_name
Results:
| NUM_DAYS |
|----------|
| 1.5 |
You could also create a custom object to aggregate INTERVAL DAY TO SECOND data types:
CREATE TYPE IntervalSumType AS OBJECT(
total INTERVAL DAY(9) TO SECOND(9),
STATIC FUNCTION ODCIAggregateInitialize(
ctx IN OUT IntervalSumType
) RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateIterate(
self IN OUT IntervalSumType,
value IN INTERVAL DAY TO SECOND
) RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateTerminate(
self IN OUT IntervalSumType,
returnValue OUT INTERVAL DAY TO SECOND,
flags IN NUMBER
) RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateMerge(
self IN OUT IntervalSumType,
ctx IN OUT IntervalSumType
) RETURN NUMBER
);
/
CREATE OR REPLACE TYPE BODY IntervalSumType
IS
STATIC FUNCTION ODCIAggregateInitialize(
ctx IN OUT IntervalSumType
) RETURN NUMBER
IS
BEGIN
ctx := IntervalSumType( INTERVAL '0' DAY );
RETURN ODCIConst.SUCCESS;
END;
MEMBER FUNCTION ODCIAggregateIterate(
self IN OUT IntervalSumType,
value IN INTERVAL DAY TO SECOND
) RETURN NUMBER
IS
BEGIN
IF value IS NOT NULL THEN
self.total := self.total + value;
END IF;
RETURN ODCIConst.SUCCESS;
END;
MEMBER FUNCTION ODCIAggregateTerminate(
self IN OUT IntervalSumType,
returnValue OUT INTERVAL DAY TO SECOND,
flags IN NUMBER
) RETURN NUMBER
IS
BEGIN
returnValue := self.total;
RETURN ODCIConst.SUCCESS;
END;
MEMBER FUNCTION ODCIAggregateMerge(
self IN OUT IntervalSumType,
ctx IN OUT IntervalSumType
) RETURN NUMBER
IS
BEGIN
self.total := self.total + ctx.total;
RETURN ODCIConst.SUCCESS;
END;
END;
/
And then a custom aggregation function:
CREATE FUNCTION SUM_INTERVALS( value INTERVAL DAY TO SECOND )
RETURN INTERVAL DAY TO SECOND
PARALLEL_ENABLE AGGREGATE USING IntervalSumType;
/
Query 2:
SELECT SUM_INTERVALS( TO_DSINTERVAL( '+0 '||PROCESS_TIME ) )
AS total_difference
FROM table_name
Results:
| TOTAL_DIFFERENCE |
|------------------|
| 1 12:0:0.0 |
Update - Query 3:
SELECT TO_CHAR( num_days * 24, 'FM99990' )
|| ':' || TO_CHAR( MOD( num_days * 24*60, 60 ), 'FM00' )
|| ':' || TO_CHAR( MOD( num_days * 24*60*60, 60 ), 'FM00' )
AS total_time
FROM (
SELECT SUM(
TO_DATE( PROCESS_TIME, 'HH24:MI:SS' )
- TO_DATE( '00:00:00', 'HH24:MI:SS' )
) AS num_days
FROM table_name
)
Results:
| TOTAL_TIME |
|------------|
| 36:00:00 |
------------------------------answer----------------------------------------
As a completion to the discussion , the query which worked was
SELECT TO_CHAR(TRUNC(END_TIME, 'DD'), 'DD-MON-YY'),
to_char(sum(TO_DATE(LOAD_PROCESS_TIME,'HH24:MI:SS')- TO_DATE( '00:00:00', 'HH24:MI:SS' ))*24,'FM00')
|| ':'|| TO_CHAR(MOD(sum(TO_DATE(LOAD_PROCESS_TIME,'HH24:MI:SS')- TO_DATE( '00:00:00', 'HH24:MI:SS' ))*24*60,60),'FM00')
||':'|| TO_CHAR(MOD(sum(TO_DATE(LOAD_PROCESS_TIME,'HH24:MI:SS')- TO_DATE( '00:00:00', 'HH24:MI:SS' ))*24*60*60,60),'FM00')
as Days
FROM MY_TABLE
WHERE END_TIME > SYSDATE -30
GROUP BY TRUNC(END_TIME,'DD')
ORDER BY TRUNC(END_TIME,'DD');
My story evaluated from this:
I created a function create dynamic partition table with Table_Year_Month format such as table_2018_04, table_2018_05 .... The arguments of creation partition function are bigint such as create_partition_function(1518164237,1520583437) ;. After that I convert bigint to date to can get year and month from timestamp. But the check function ( check(timestamp >= date)) don't work
I can't compare bigint >= date in sql. What's operator can compare their?
I tried convert timestamp to datetime with UNIX_TIMESTAMP function of sql but don't work
CREATE OR REPLACE FUNCTION create_partition_function( DATE, DATE )
returns void AS $$
DECLARE
create_query text;
index_query text;
BEGIN
FOR create_query, index_query IN SELECT
'create table user_event_firebase_'
|| TO_CHAR( d, 'YYYY_MM' )
|| ' ( check( timestamp >= UNIX_TIMESTAMP(date,'%Y %M %D' )'''
|| TO_CHAR( d, 'YYYY-MM-DD' )
|| ''' and timestamp < UNIX_TIMESTAMP(date,'%Y %M %D' ) '''
|| TO_CHAR( d + INTERVAL '1 month', 'YYYY-MM-DD' )
|| ''' ) ) inherits ( user_event_firebase );',
'create index user_event_firebase_'
|| TO_CHAR( d, 'YYYY_MM' )
|| '_time on user_event_firebase_'
|| TO_CHAR( d, 'YYYY_MM' )
|| ' ( timestamp );'
FROM generate_series( to_timestamp($1), to_timestamp($2), '1 month'::interval ) AS d
LOOP
EXECUTE create_query;
EXECUTE index_query;
END LOOP;
END;
$$
language plpgsql;
p/s : bigint and dateare data type in sql.
ERROR: invalid input syntax for integer: "2018-02-09"
CONTEXT: SQL statement "create table user_event_firebase_2018_02 ( check( timestamp >= bigint '2018-02-09' and timestamp < bigint '2018-03-09' ) ) inherits ( user_event_firebase );"
PL/pgSQL function create_partition_function(date,date) line 21 at EXECUTE
You can convert date/timestamp to seconds using
SELECT extract(epoch from '2016-05-03'::date)
--result: 1462233600
SELECT to_timestamp(1462233600)::date;
--result: '2016-05-03'