Thread: help with function .. .. date data type

help with function .. .. date data type

From
"ed"
Date:

I have a table with 7 columns and Im trying to pull a section(rows) of the table

by using the date column(field), in a function. I want it to work like so;

# Select Slice('03/01/2004', '03/05/2003');

But Im getting an error .. .. ...

------------------------- this is the error ------------------------------

NOTICE: Error occurred while executing PL/pgSQL function slice

NOTICE: line 9 at SQL statement

ERROR: zero-length delimited identifier

-------------------------- end of error -----------------------------------

What Am I doing wrong.

------------------------------ my code ----------------------------------

CREATE FUNCTION Slice(date, date)

RETURNS date AS'

DECLARE

f_table RECORD;

lower Alias for $1;

upper Alias for $2;

BEGIN

set datestyle to ""US, SQL"";

for name in lower..upper

Loop

SELECT * INTO f_table from g_table          -- my g_table is the real table in the datebase.

WHERE g_table.date BETWEEN upper AND lower

ORDER BY g_table.date;

End Loop;

 

END;

'Language 'plpgsql';

Ed..

 
 
 

Re: help with function .. .. date data type

From
Tom Lane
Date:
"ed" <ntworldnet@netzero.net> writes:
> ERROR: zero-length delimited identifier

> What Am I doing wrong.

> set datestyle to ""US, SQL"";

You should be using doubled single quotes here, not doubled double
quotes.  That is,

set datestyle to ''US, SQL'';

            regards, tom lane

Re: help with function .. .. date data type

From
John DeSoi
Date:
On Jun 19, 2005, at 11:39 PM, ed wrote:

> set datestyle to ""US, SQL"";


You have two double quotes here where you need to have single quotes:

set datestyle to ''US, SQL'';


After you fix this, I think you'll run into a few more problems. You
have your function as returning a date, but it looks like you are
trying to return a set of rows. Here is some documentation with
examples:

http://techdocs.postgresql.org/guides/SetReturningFunctions

Documentation note: I can't find this information in the current
documentation. The index entry for "Set Returning Functions" gives this
link:

http://www.postgresql.org/docs/8.0/interactive/functions-srf.html

which seems far less helpful. Have I missed it?


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL