user10531062
user10531062

Reputation: 197

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!

Upvotes: 0

Views: 313

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 248225

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))

Upvotes: 1

Related Questions