[FeatureRequest] Base Convert Function

Started by Tomáš Mudruňkaabout 15 years ago11 messages
#1Tomáš Mudruňka
tomas@mudrunka.cz

Hi!
Is there possibility of having internal base converting function in PgSQL?
There are already functions for converting between decimal and hexadecimal
notations i think pgsql can be able to convert between number with radixes
from 1 to 36 (actually fast (de)encoding base36 is what i need)...

thx

--
S pozdravem
Best regards
Tomáš Mudruňka - Spoje.net / Arachne Labs

XMPP/Jabber: harvie@jabbim.cz, ICQ: 283782978

#2Robert Haas
robertmhaas@gmail.com
In reply to: Tomáš Mudruňka (#1)
Re: [FeatureRequest] Base Convert Function

2010/12/21 Tomáš Mudruňka <tomas@mudrunka.cz>:

Is there possibility of having internal base converting function in PgSQL?
There are already functions for converting between decimal and hexadecimal
notations i think pgsql can be able to convert between number with radixes
from 1 to 36 (actually fast (de)encoding base36 is what i need)...

It should be pretty easy to write such a function in C, perhaps using
strtol() or strtoul(). Because PostgreSQL uses an extensible
architecture, you could load such a function into your copy of
PostgreSQL and use it in your environment even if it weren't part of
the core distribution. There are a number of existing "contrib"
modules that you can look at for examples of how to do this.

Whether or not we'd accept a patch to add such a function to core or
contrib, I'm not sure. Nobody's written one yet...

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Robert Haas (#2)
Re: [FeatureRequest] Base Convert Function

Dne 21. prosince 2010 12:48 Robert Haas <robertmhaas@gmail.com> napsal(a):

2010/12/21 Tomáš Mudruňka <tomas@mudrunka.cz>:

Is there possibility of having internal base converting function in PgSQL?
There are already functions for converting between decimal and hexadecimal
notations i think pgsql can be able to convert between number with radixes
from 1 to 36 (actually fast (de)encoding base36 is what i need)...

It should be pretty easy to write such a function in C, perhaps using
strtol() or strtoul().  Because PostgreSQL uses an extensible
architecture, you could load such a function into your copy of
PostgreSQL and use it in your environment even if it weren't part of
the core distribution.  There are a number of existing "contrib"
modules that you can look at for examples of how to do this.

Whether or not we'd accept a patch to add such a function to core or
contrib, I'm not sure.  Nobody's written one yet...

Most used transformations are available from core now - just need a
wrapper function.

This functions isn't a clean, - should be based on int, long int or bytea?

Pavel

Show quoted text

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Florian Pflug
fgp@phlo.org
In reply to: Robert Haas (#2)
Re: [FeatureRequest] Base Convert Function

On Dec21, 2010, at 12:48 , Robert Haas wrote:

2010/12/21 Tomáš Mudruňka <tomas@mudrunka.cz>:

Is there possibility of having internal base converting function in PgSQL?
There are already functions for converting between decimal and hexadecimal
notations i think pgsql can be able to convert between number with radixes
from 1 to 36 (actually fast (de)encoding base36 is what i need)...

It should be pretty easy to write such a function in C, perhaps using
strtol() or strtoul().

If you're not comfortable doing this in C, you might also want to consider
one of procedural languages pl/pgsql, pl/perl, pl/python. pl/pgsql is probably
only viable if you just need this for ints and bigints, unless you don't
care about performance.

best regards,
Florian Pflug

#5Tomáš Mudruňka
tomas@mudrunka.cz
In reply to: Florian Pflug (#4)
Re: [FeatureRequest] Base Convert Function

Thx for you answers :-)
Well... i know that i can write my own plugin and i am familiar with C so
this is not the problem, but i think that such feature should be
implemented directly in PgSQL because there are already functions for
converting to/from base 16 so why don't make this more flexible and
generalize it to any other radix? It's quite simple to do and i don't see
any reason why 16 should be there and 8, 32 or 36 shouldn't :-)

peace

On Tue, 21 Dec 2010 15:04:03 +0100, Florian Pflug <fgp@phlo.org> wrote:

On Dec21, 2010, at 12:48 , Robert Haas wrote:

2010/12/21 Tomáš Mudruňka <tomas@mudrunka.cz>:

Is there possibility of having internal base converting function in
PgSQL?
There are already functions for converting between decimal and
hexadecimal
notations i think pgsql can be able to convert between number with
radixes
from 1 to 36 (actually fast (de)encoding base36 is what i need)...

It should be pretty easy to write such a function in C, perhaps using
strtol() or strtoul().

If you're not comfortable doing this in C, you might also want to

consider

one of procedural languages pl/pgsql, pl/perl, pl/python. pl/pgsql is
probably
only viable if you just need this for ints and bigints, unless you don't
care about performance.

best regards,
Florian Pflug

--
S pozdravem
Best regards
Tomáš Mudruňka - Spoje.net / Arachne Labs

XMPP/Jabber: harvie@jabbim.cz, ICQ: 283782978

#6Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tomáš Mudruňka (#5)
Re: [FeatureRequest] Base Convert Function

Hello

Dne 21. prosince 2010 21:11 Tomáš Mudruňka <tomas@mudrunka.cz> napsal(a):

Thx for you answers :-)
Well... i know that i can write my own plugin and i am familiar with C so
this is not the problem, but i think that such feature should be
implemented directly in PgSQL because there are already functions for
converting to/from base 16 so why don't make this more flexible and
generalize it to any other radix? It's quite simple to do and i don't see
any reason why 16 should be there and 8, 32 or 36 shouldn't :-)

* It isn't a typical and often request,
* There are not hard breaks for custom implementation,
* You can use plperu or plpython based solutions,
* It's not part of ANSI SQL

Regards

Pavel Stehule

Show quoted text

peace

On Tue, 21 Dec 2010 15:04:03 +0100, Florian Pflug <fgp@phlo.org> wrote:

On Dec21, 2010, at 12:48 , Robert Haas wrote:

2010/12/21 Tomáš Mudruňka <tomas@mudrunka.cz>:

Is there possibility of having internal base converting function in
PgSQL?
There are already functions for converting between decimal and
hexadecimal
notations i think pgsql can be able to convert between number with
radixes
from 1 to 36 (actually fast (de)encoding base36 is what i need)...

It should be pretty easy to write such a function in C, perhaps using
strtol() or strtoul().

If you're not comfortable doing this in C, you might also want to

consider

one of procedural languages pl/pgsql, pl/perl, pl/python. pl/pgsql is
probably
only viable if you just need this for ints and bigints, unless you don't
care about performance.

best regards,
Florian Pflug

--
S pozdravem
Best regards
  Tomáš Mudruňka - Spoje.net / Arachne Labs

XMPP/Jabber: harvie@jabbim.cz, ICQ: 283782978

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Pavel Golub
pavel@microolap.com
In reply to: Pavel Stehule (#6)
Re: [FeatureRequest] Base Convert Function

Hello, Pavel.

You wrote:

PS> Hello

PS> Dne 21. prosince 2010 21:11 Tomáš Mudruňka <tomas@mudrunka.cz> napsal(a):

Thx for you answers :-)
Well... i know that i can write my own plugin and i am familiar with C so
this is not the problem, but i think that such feature should be
implemented directly in PgSQL because there are already functions for
converting to/from base 16 so why don't make this more flexible and
generalize it to any other radix? It's quite simple to do and i don't see
any reason why 16 should be there and 8, 32 or 36 shouldn't :-)

PS> * It isn't a typical and often request,
PS> * There are not hard breaks for custom implementation,
PS> * You can use plperu or plpython based solutions,
PS> * It's not part of ANSI SQL

But MySQL has such function. What's wrong with us? ;)

PS> Regards

PS> Pavel Stehule

peace

On Tue, 21 Dec 2010 15:04:03 +0100, Florian Pflug <fgp@phlo.org> wrote:

On Dec21, 2010, at 12:48 , Robert Haas wrote:

2010/12/21 Tomáš Mudruňka <tomas@mudrunka.cz>:

Is there possibility of having internal base converting function in
PgSQL?
There are already functions for converting between decimal and
hexadecimal
notations i think pgsql can be able to convert between number with
radixes
from 1 to 36 (actually fast (de)encoding base36 is what i need)...

It should be pretty easy to write such a function in C, perhaps using
strtol() or strtoul().

If you're not comfortable doing this in C, you might also want to

consider

one of procedural languages pl/pgsql, pl/perl, pl/python. pl/pgsql is
probably
only viable if you just need this for ints and bigints, unless you don't
care about performance.

best regards,
Florian Pflug

--
S pozdravem
Best regards
  Tomáš Mudruňka - Spoje.net / Arachne Labs

XMPP/Jabber: harvie@jabbim.cz, ICQ: 283782978

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--
With best wishes,
Pavel mailto:pavel@gf.microolap.com

#8Kenneth Marshall
ktm@rice.edu
In reply to: Pavel Golub (#7)
Re: [FeatureRequest] Base Convert Function

On Tue, Dec 21, 2010 at 11:28:17PM +0200, Pavel Golub wrote:

Hello, Pavel.

You wrote:

PS> Hello

PS> Dne 21. prosince 2010 21:11 Tom???? Mudru??ka <tomas@mudrunka.cz> napsal(a):

Thx for you answers :-)
Well... i know that i can write my own plugin and i am familiar with C so
this is not the problem, but i think that such feature should be
implemented directly in PgSQL because there are already functions for
converting to/from base 16 so why don't make this more flexible and
generalize it to any other radix? It's quite simple to do and i don't see
any reason why 16 should be there and 8, 32 or 36 shouldn't :-)

PS> * It isn't a typical and often request,
PS> * There are not hard breaks for custom implementation,
PS> * You can use plperu or plpython based solutions,
PS> * It's not part of ANSI SQL

But MySQL has such function. What's wrong with us? ;)

You are not really helping to make a good case... :)

Ken

#9Andrew Dunstan
andrew@dunslane.net
In reply to: Pavel Golub (#7)
Re: [FeatureRequest] Base Convert Function

On 12/21/2010 04:28 PM, Pavel Golub wrote:

PS> * It isn't a typical and often request,
PS> * There are not hard breaks for custom implementation,
PS> * You can use plperu or plpython based solutions,
PS> * It's not part of ANSI SQL

But MySQL has such function. What's wrong with us? ;)

Our aim is not to duplicate everything in MySQL.

cheers

andrew

#10Pavel Golub
pavel@microolap.com
In reply to: Andrew Dunstan (#9)
Re: [FeatureRequest] Base Convert Function

Hello.

Guys, guys! It was only a joke! :)

Please accept my appologies.

Anyway I find such function usefull even though I still hadn't
situation when it might be needed.
You wrote:

AD> On 12/21/2010 04:28 PM, Pavel Golub wrote:

PS> * It isn't a typical and often request,
PS> * There are not hard breaks for custom implementation,
PS> * You can use plperu or plpython based solutions,
PS> * It's not part of ANSI SQL

But MySQL has such function. What's wrong with us? ;)

AD> Our aim is not to duplicate everything in MySQL.

AD> cheers

AD> andrew

--
With best wishes,
Pavel mailto:pavel@gf.microolap.com

#11Robert Haas
robertmhaas@gmail.com
In reply to: Pavel Golub (#10)
Re: [FeatureRequest] Base Convert Function

On Tue, Dec 21, 2010 at 4:57 PM, Pavel Golub <pavel@microolap.com> wrote:

Anyway I find such function usefull even though I still hadn't
situation when it might be needed.

Yeah, I agree. I'm not sure we should add it to core, but it's
certainly just as useful as many things we have in contrib. I'll bet
it would get at least as much use as the six argument form of
levenshtein_less_equal().

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company