简体   繁体   中英

Date compatible Function from Oracle to Postgres

I am trying to convert the below definition to Postgres.

Current Oracle code:

PROCEDURE Run_All (inDate DATE DEFAULT SYSDATE) IS

In Postgres I used different versions:

  1.  CREATE OR REPLACE FUNCTION ssp2_pcat.gen_fios_xml$run_all (indate timestamp(0) DEFAULT CURRENT_DATE) 
  2.  CREATE OR REPLACE FUNCTION ssp2_pcat.gen_fios_xml$run_all (indate timestamp without timezone DEFAULT ('now'::text)::date) 
  3.  CREATE OR REPLACE FUNCTION ssp2_pcat.gen_fios_xml$run_all (indate date DEFAULT ('now'::text)::date) 
  4.  CREATE OR REPLACE FUNCTION ssp2_pcat.gen_fios_xml$run_all (indate timestamp(0) DEFAULT CURRENT_TIMESTAMP::timestamp(0)) 

But still it's throwing an error as below:

ERROR:  column "timestamp" does not exist
LINE 1: SELECT TIMESTAMP
               ^
QUERY:  SELECT TIMESTAMP
CONTEXT:  PL/pgSQL function "gen_fios_xml$run_all"(date) line 13 during statement block local variable initialization
SQL state: 42703

What would be the right way to convert, am I missing something in Postgres? Any update is absolutely appreciated!

The error is not in the part of the function that you are showing, it is in line 13 of the function body in a SELECT statement.

Your function signatures should work, but if you need the hour-to-second part of the Oracle DATE , the perfect translation would be:

CREATE FUNCTION ssp2_pcat.gen_fios_xml$run_all
    (indate timestamp(0) without time zone DEFAULT localtimestamp(0))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM