Re: Interval to number

Lists: pgsql-adminpgsql-generalpgsql-hackerspgsql-interfacespgsql-odbc
From: Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr>
To: <pgsql-admin(at)postgresql(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org>, pgsql-odbc <pgsql-odbc(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: UTF-8 safe ascii() function
Date: 2002-05-18 16:53:19
Message-ID: 200205181853.19420.jm.poure@freesurf.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Dear all,

I would like to transform UTF-8 strings into Java-Unicode. Example :
- Latin1 : 'é'
- UTF-8 : 'é'
- Java Unicode = '\u00233'

Basically, a Unicode compatible ascii() function would be fine.
ascii('é') should return 233.

1) Has anyone written an ascii UTF-8 safe wrapper to ascii() function? If yes,
would you be so kind to publish this function on the list.

2) Are there plans to add an ascii() UTF-8 safe function to PostrgeSQL?

Best regards,
Jean-Michel POURE


From: Patrice Hédé <phede-ml(at)islande(dot)org>
To: pgsql-general(at)postgresql(dot)org
Cc: jm(dot)poure(at)freesurf(dot)fr
Subject: Re: [HACKERS] UTF-8 safe ascii() function
Date: 2002-05-19 09:44:13
Message-ID: 20020519114413.2265b70e.phede-ml@islande.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Hi Jean-Michel,

Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr> a écrit :
> Dear all,
>
> I would like to transform UTF-8 strings into Java-Unicode. Example :
> - Latin1 : 'é'
> - UTF-8 : 'é'
> - Java Unicode = '\u00233'
>
> Basically, a Unicode compatible ascii() function would be fine.
> ascii('é') should return 233.
>
> 1) Has anyone written an ascii UTF-8 safe wrapper to ascii() function?
> If yes, would you be so kind to publish this function on the list.

OK, I just gave it a try, see the attachment.

The function is taking the first character of a TEXT element, and
returns its UCS2 value. I just did some basic test (i.e. I have not
tried with 3 or 4 bytes UTF-8 chars). The function is following the
Unicode 3.2 spec.

SELECT utf8toucs2('a'), utf8toucs2('é');
utf8toucs2 | utf8toucs2
------------+------------
97 | 233
(1 row)

The function returns -1 on error.

> 2) Are there plans to add an ascii() UTF-8 safe function to
> PostrgeSQL?

I don't think the function I did is useful as such. It would be better
to make a function that converts the whole string or something.

By the way, what is the encoding for Java Unicode ? is it always "\u"
followed by 5 hex digits (in which case your example is wrong) ? Then,
it shouldn't be too difficult to make the relevant function, though I'm
wondering if the Java programme would convert an incoming '\' 'u' '0'
'0' '2' '3' '3' to the corresponding UCS2/UTF16 character ?

Maybe we should have some similar input (and output ?) functionality in
psql, but then I would much prefer the Perl way, which is
\x{hex_digits}, which is unambiguous.

Regards,

Patrice

--
Patrice Hédé
email: patrice hede(à)islande org
www : http://www.islande.org/

Attachment Content-Type Size
utf8toucs2.c text/x-csrc 3.2 KB
utf8toucs2.sql text/x-sql 140 bytes
Makefile text/x-makefile 397 bytes

From: Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr>
To: Patrice Hédé <phede-ml(at)islande(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: [HACKERS] UTF-8 safe ascii() function
Date: 2002-05-19 10:44:56
Message-ID: 200205191244.56474.jm.poure@freesurf.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Dear Patrice,

Thank you very much. This will save the lives of Java users.

> I don't think the function I did is useful as such. It would be better
> to make a function that converts the whole string or something.

Yes, this would save the lives of some Javascript users. Java Unicode notation
is the only Unicode understood by Javascript.

> By the way, what is the encoding for Java Unicode ? is it always "\u"
> followed by 5 hex digits (in which case your example is wrong) ? Then,
> it shouldn't be too difficult to make the relevant function, though I'm
> wondering if the Java programme would convert an incoming '\' 'u' '0'
> '0' '2' '3' '3' to the corresponding UCS2/UTF16 character ?

Java Unicode notation is not case sensitive ('\u' = '\U') and is followed by
an hexadecimal value.

> Maybe we should have some similar input (and output ?) functionality in
> psql, but then I would much prefer the Perl way, which is
> \x{hex_digits}, which is unambiguous.

This would be perfect. We should also handle the HTML unicode nation :
&#{dec_digits} and &#x{hex_digits} as it is unambiguous.

Cheers,
Jean-Michel


From: Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr>
To: Patrice Hédé <phede-ml(at)islande(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: [HACKERS] UTF-8 safe ascii() function
Date: 2002-05-19 18:08:18
Message-ID: 200205192008.18893.jm.poure@freesurf.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Le Dimanche 19 Mai 2002 11:44, Patrice Hédé a écrit :
> The function is taking the first character of a TEXT element, and
> returns its UCS2 value. I just did some basic test (i.e. I have not
> tried with 3 or 4 bytes UTF-8 chars). The function is following the
> Unicode 3.2 spec.

Hi Patrice,

I tried a Japanese character :
SELECT utf8toucs2 ('支'::text) which returns -1

Do you know why it does not return the UCS-2 value?

Cheers,
Jean-Michel POURE


From: Patrice Hédé <phede-ml(at)islande(dot)org>
To: jm(dot)poure(at)freesurf(dot)fr
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [HACKERS] UTF-8 safe ascii() function
Date: 2002-05-19 19:14:42
Message-ID: 20020519211442.4d19606e.phede-ml@islande.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr> a écrit :

> I tried a Japanese character :
> SELECT utf8toucs2 ('æ_¯'::text) which returns -1
>
> Do you know why it does not return the UCS-2 value?

Oops, my mistake. I forgot to update a test after a copy-paste. Here is
a new version which should be correct this time ! :)

Patrice

--
Patrice Hédé
email: patrice hede à islande org
www : http://www.islande.org/

Attachment Content-Type Size
utf8toucs2.c text/x-csrc 3.2 KB

From: Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr>
To: Patrice Hédé <phede-ml(at)islande(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [HACKERS] UTF-8 safe ascii() function
Date: 2002-05-20 07:31:31
Message-ID: 200205200931.32094.jm.poure@freesurf.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Le Dimanche 19 Mai 2002 21:14, Patrice Hédé a écrit :
> Oops, my mistake. I forgot to update a test after a copy-paste. Here is
> a new version which should be correct this time ! :)

Thanks Patrice, merci Patrice !


From: "Gareth Kirwan" <gbjk(at)thermeoneurope(dot)com>
To: <pgsql-admin(at)postgresql(dot)org>
Subject: Interval to number
Date: 2002-05-20 11:53:01
Message-ID: 00fb01c1fff4$e5030cd0$55eaa8c0@gbjk1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Postgres 7.2
I have an interval selected from a max(occurance) - min(occurance) where
bla.
I now want to multiply this by a rate - to create a charge...

If I use to_char( interval, 'SSSS');
I will get a seconds conversion - but that works on seconds since midnight -
hence
with a one day period.

Are there any better ways of converting a timestamp to an integer?

Thanks

Gareth


From: Brian McCane <bmccane(at)mccons(dot)net>
To: Gareth Kirwan <gbjk(at)thermeoneurope(dot)com>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Interval to number
Date: 2002-05-20 16:35:07
Message-ID: 20020520113223.I80087-100000@fw.mccons.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc


EXTRACT is your friend :)

SELECT EXTRACT(EPOCH FROM max(occurrance) - min(occurrance))::integer ;

- brian

k=# SELECT EXTRACT(EPOCH FROM now() - '2001-01-01') ;
date_part
----------------
43583467.94995
(1 row)

On Mon, 20 May 2002, Gareth Kirwan wrote:

>
> Postgres 7.2
> I have an interval selected from a max(occurance) - min(occurance) where
> bla.
> I now want to multiply this by a rate - to create a charge...
>
> If I use to_char( interval, 'SSSS');
> I will get a seconds conversion - but that works on seconds since midnight -
> hence
> with a one day period.
>
> Are there any better ways of converting a timestamp to an integer?
>
>
> Thanks
>
> Gareth
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"


From: "Gareth Kirwan" <gbjk(at)thermeoneurope(dot)com>
To: "'Brian McCane'" <bmccane(at)mccons(dot)net>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Interval to number
Date: 2002-05-20 16:40:46
Message-ID: 00fc01c2001d$17efd380$55eaa8c0@gbjk1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

Oh :(

I'd given up waiting for a response.
Thanks though Brian ... I currently have the triggered function:

CREATE FUNCTION logSession () RETURNS opaque AS '
DECLARE
client_rate numeric(10,2);
period interval;
to_charge numeric(10,2);
BEGIN
SELECT INTO client_rate rate from clients c where c.id=OLD.client;
SELECT INTO period max(time) - min(time) FROM convs WHERE
session_id=OLD.id;
SELECT INTO to_charge (to_number(to_char(period, ''SSSS''), ''99999D99'')
/ 60 * client_rate);

INSERT INTO previous_sessions SELECT * from current_sessions c WHERE
c.id=OLD.id;
INSERT INTO logged_convs SELECT * from convs c WHERE c.session_id=OLD.id;

INSERT INTO session_logs (session_id, time, length, charge, paid) VALUES
(OLD.id,OLD.time,period, to_charge, ''false'');
RETURN OLD;
END;'
language 'plpgsql';

So I'll try to build it into that.

-----Original Message-----
From: Brian McCane [mailto:bmccane(at)mccons(dot)net]
Sent: 20 May 2002 17:35
To: Gareth Kirwan
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: [ADMIN] Interval to number

EXTRACT is your friend :)

SELECT EXTRACT(EPOCH FROM max(occurrance) - min(occurrance))::integer ;

- brian

k=# SELECT EXTRACT(EPOCH FROM now() - '2001-01-01') ;
date_part
----------------
43583467.94995
(1 row)

On Mon, 20 May 2002, Gareth Kirwan wrote:

>
> Postgres 7.2
> I have an interval selected from a max(occurance) - min(occurance) where
> bla.
> I now want to multiply this by a rate - to create a charge...
>
> If I use to_char( interval, 'SSSS');
> I will get a seconds conversion - but that works on seconds since
midnight -
> hence
> with a one day period.
>
> Are there any better ways of converting a timestamp to an integer?
>
>
> Thanks
>
> Gareth
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid
those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"


From: lee johnson <lee(at)imyourhandiman(dot)com>
To: "pgsql-interfaces(at)postgresql(dot)org" <pgsql-interfaces(at)postgresql(dot)org>
Subject: no pg_hba.conf
Date: 2002-05-22 14:19:53
Message-ID: 1022077194.9671.2.camel@handimanstation
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

hi..

redhat 7.3 ..can't seem to get pgaccess to want to load my database
which btw is created and for which a user is also..postmaster is running
fine with -i -D /usr/local/pgsql/data..

when I try to load my database into pgaccess it says: no pg_hba.conf
entry for host 127.0.0.1.user lee..database handiman..

thx anyone
lee
-====


From: "Joel Burton" <joel(at)joelburton(dot)com>
To: "lee johnson" <lee(at)imyourhandiman(dot)com>, <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: no pg_hba.conf
Date: 2002-05-23 13:07:11
Message-ID: JGEPJNMCKODMDHGOBKDNEECFCPAA.joel@joelburton.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

> -----Original Message-----
> From: pgsql-interfaces-owner(at)postgresql(dot)org
> [mailto:pgsql-interfaces-owner(at)postgresql(dot)org]On Behalf Of lee johnson
> Sent: Wednesday, May 22, 2002 10:20 AM
> To: pgsql-interfaces(at)postgresql(dot)org
> Subject: [INTERFACES] no pg_hba.conf
>
>
> hi..
>
> redhat 7.3 ..can't seem to get pgaccess to want to load my database
> which btw is created and for which a user is also..postmaster is running
> fine with -i -D /usr/local/pgsql/data..
>
> when I try to load my database into pgaccess it says: no pg_hba.conf
> entry for host 127.0.0.1.user lee..database handiman..

So... is that true? Have you looked in pg_hba.conf? What did you add to
that?

-J.

Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant


From: lee <lee(at)imyourhandiman(dot)com>
To: Joel Burton <joel(at)joelburton(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: no pg_hba.conf
Date: 2002-05-26 15:15:45
Message-ID: 3CF0FC21.5090005@imyourhandiman.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc

>
>
>So... is that true? Have you looked in pg_hba.conf? What did you add to
>that?
>
>
>
okay its working now ...I had previously upgraded 'to'
RH7.3 but backed out due to needing temporarily to install windows and
upon a fresh install of 7.3 all is fine now .

thx for efforts mucho
lee
-=