Skip site navigation (1) Skip section navigation (2)

PSQL

From: Atif Jung <atifjung(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: PSQL
Date: 2010-07-06 09:24:49
Message-ID: AANLkTinnWldWIcoX9QRPzkCa-OYLqTRZejmunU3-JFjJ@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
I'm having problems with the following stored procedure. The problematic
line is the one in red. Any help greatly appreciated.

CREATE or replace FUNCTION converttojulian(datex DATE) RETURNS CHAR(5) AS $$
   DECLARE
   result  CHAR(5);
   m1  INTEGER;
   d1  INTEGER;
   y1  INTEGER;
   year  CHAR(4);
   d2  INTEGER;
   days  CHAR(3);
   days1  CHAR(3);
   date2  DATE;
BEGIN
   m1 := EXTRACT (MONTH FROM DATE datex);
   d1 := EXTRACT (DAY FROM DATE datex);
   y1 := EXTRACT (YEAR FROM DATE datex);
   date2 := MDY(m1,d1,y1);
   d2 := CAST((datex -date2)+1 AS INTEGER);
   year := SUBSTR(CAST(y1 AS CHAR(4)),1,4);
   days1 := SUBSTR(CAST(d2 AS CHAR(3)),1,3);
   IF d2 < 10 THEN
      days := '00' || SUBSTR(days1,1,1);
   ELSEIF d2 < 100 THEN
      days := '0' || SUBSTR(days1,1,2);
   ELSE
      days := SUBSTR(days1,1,3);
   END IF;
   result := SUBSTR(year,3,2) || days;
   RETURN result;
END;
$$ LANGUAGE plpgsql;

The error reads :

psql:converttojulian.sql:32: ERROR:  syntax error at or near "$1"
LINE 1: SELECT  EXTRACT (MONTH FROM DATE  $1 )
                                                                            ^

QUERY:  SELECT  EXTRACT (MONTH FROM DATE  $1 )
CONTEXT:  SQL statement in PL/PgSQL function "converttojulian" near line 12

It doesn't seem to like the use of the input paramater datex. I've tried
using an alias but still get the same problem.

Thanks

Atif

Responses

  • Re: PSQL at 2010-07-06 14:16:38 from Tom Lane

pgsql-novice by date

Next:From: Tom LaneDate: 2010-07-06 14:16:38
Subject: Re: PSQL
Previous:From: Darryl PyeDate: 2010-07-06 02:49:48
Subject: Join Scalability

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group