Re: [GENERAL] Plpgsql - Custom fields Postgres 9.5 - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] Plpgsql - Custom fields Postgres 9.5
Date
Msg-id CAKFQuwYa+iuPSogh_e=RDAfVHG1GKPrdtwN41ovTRPmmD7s4xQ@mail.gmail.com
Whole thread Raw
In response to [GENERAL] Plpgsql - Custom fields Postgres 9.5  (Patrick B <patrickbakerbr@gmail.com>)
List pgsql-general
On Wed, Dec 14, 2016 at 2:17 PM, Patrick B <patrickbakerbr@gmail.com> wrote:

As you can see, I select a date. So in December, the date will be: BETWEEN '201612015' AND '201601015', for example.


​That is an unusual timestamp value...what's the 5 for?​ (I've figured this out...but its still unusual)


1. Why when I run the function manually I get this error?
select logextract(201612015, 201612015);
ERROR:  operator does not exist: timestamp without time zone >= integer
LINE 13:                 BETWEEN

 I presume this is wrong: CREATE or REPLACE FUNCTION logextract(date_start integer, date_end integer) - But what should I use instead?


I don't understand why "date" wouldn't be your first choice here.​  Or, better yet, a single argument of type daterange.


2. To call the function, I have to login to postgres and then run: select logextract(201612015, 201612015);
How can I do it on cron? because the dates will be different every time.


​PostgreSQL knows what the current date is so describe how to compute your desired boundaries given a single date.
Dates and times are their own types in PostgreSQL.  They are incompatible with integers.  You either to convert one or the other if you want to perform a comparison.

David J.


pgsql-general by date:

Previous
From: Patrick B
Date:
Subject: Re: [GENERAL] Plpgsql - Custom fields Postgres 9.5
Next
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] Plpgsql - Custom fields Postgres 9.5