Re: Version Number Function?

From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: David E(dot) Wheeler <david(at)kineticode(dot)com>
Cc: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Version Number Function?
Date: 2008-10-14 16:53:43
Message-ID: 0D51B226-9689-48F5-A08E-31208ADA7B58@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Oct 14, 2008, at 08:33, David E. Wheeler wrote:

> Well, the C version I borrowed from dumpitils seems to work great.
> Any reason I shouldn't stay with that?

Also, here's a simpler SQL version, for those following along at home:

create or replace function pg_version_num() returns int language
SQL as $$
SELECT SUM(
(string_to_array(current_setting('server_version'), '.'))
[i]::int
* CASE i WHEN 1 THEN 10000 WHEN 2 THEN 100 ELSE 1 end
)::int FROM generate_series(1, 3) AS gen(i);
$$;
CREATE FUNCTION

There must be a way to get string_to_array() to evaluate only once, yes?

Best,

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Joseph Krogh 2008-10-14 17:04:32 Re: Window Functions
Previous Message Alvaro Herrera 2008-10-14 16:46:57 Re: Transactions and temp tables