Unix Technical Forum

Find out encoding of data

This is a discussion on Find out encoding of data within the Pgsql General forums, part of the PostgreSQL category; --> Hi! I have this problem that Im not sure if my stored data has the correct coding. When I ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 11:02 PM
joynes
 
Posts: n/a
Default Find out encoding of data


Hi!
I have this problem that Im not sure if my stored data has the correct
coding. When I view the data from a postgres console I just see the
characters and depending on my console-encoding it looks differently.

What I really want to see is the hexadecimal or octal value of the bytes of
the retrieved data. Can postgres give me this somehow (without exporting
tables to files and look at the files).

/br joynes
--
View this message in context: http://www.nabble.com/Find-out-encod...html#a12983073
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 11:02 PM
Albe Laurenz
 
Posts: n/a
Default Re: Find out encoding of data

joynes wrote:
> What I really want to see is the hexadecimal or octal value
> of the bytes of the retrieved data. Can postgres give me
> this somehow (without exporting tables to files and look at
> the files).


Maybe 'decode' can help you:

test=> SELECT decode('10EUR', 'escape');
decode
----------------
10\342\202\254
(1 row)

Yours,
Laurenz Albe

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 11:02 PM
joynes
 
Posts: n/a
Default Re: Find out encoding of data


Hi!
This doesnt work for me but it is exactly what I want. When I run your
example I just get:

>SELECT decode('10EUR', 'escape');

decode
--------
10EUR
(1 rad)

I get the same result, both if the database is UTF8 or ISO-Latin1 and also
with different versions of postgres (7 and 8)

And when I read the documentation for 'decode' it tells that it just decodes
binary strings encoded with 'encode'.
How did you get that result from running decode?


/br joynes
--
View this message in context: http://www.nabble.com/Find-out-encod...html#a12995704
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 11:03 PM
Albe Laurenz
 
Posts: n/a
Default Re: Find out encoding of data

joynes wrote:
> This doesnt work for me but it is exactly what I want. When I run your
> example I just get:
>
> >SELECT decode('10EUR', 'escape');

> decode
> --------
> 10EUR
> (1 rad)
>
> I get the same result, both if the database is UTF8 or
> ISO-Latin1 and also
> with different versions of postgres (7 and 8)
>
> And when I read the documentation for 'decode' it tells that
> it just decodes
> binary strings encoded with 'encode'.
> How did you get that result from running decode?


I suspect that somewhere along the line the Euro symbol I
used in the query got changed to 'EUR'.

Try some other string with weird characters.

It will show all non-ASCII characters in escaped octal
notation, while ASCII characters will remain as they are.

This should help you - if I understood you correctly,
you want to know the actual bytes stored in a database
field. To find our the numeric representation of an ASCII
field, you can use the function ascii().

Yours,
Laurenz Albe

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 11:04 PM
joynes
 
Posts: n/a
Default Re: Find out encoding of data


Yeah you're right.

I didnt test it with any special characters. It works when I do

Thx a lot!

--
View this message in context: http://www.nabble.com/Find-out-encod...html#a13014617
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:36 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com