Re: Plpgsql - Custom fields Postgres 9.5

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Patrick B <patrickbakerbr(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Plpgsql - Custom fields Postgres 9.5
Date: 2016-12-14 21:35:53
Message-ID: CAKFQuwYa+iuPSogh_e=RDAfVHG1GKPrdtwN41ovTRPmmD7s4xQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 14, 2016 at 2:17 PM, Patrick B <patrickbakerbr(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2016-12-14 21:40:10 Re: Plpgsql - Custom fields Postgres 9.5
Previous Message Patrick B 2016-12-14 21:30:19 Re: Plpgsql - Custom fields Postgres 9.5