sql - Is it possible to get the binary (or hexadecimal) representation of a value stored as double precision in a PostgreSQL database? -


Is it possible to obtain a binary (or hexadecimal) representation of the value stored in a postgresql database as a double exact?

I have already tried to use a left bit (64) (the double precision is stored with the size of 8 bytes) but I get the following error:

  SELECT (1.031:: Double Accuracy) :: Bit (64)> gt; & Gt; Error: type double spissation can not be inserted for bit selection (1024 :: double precision): bit (64) & gt; & Gt; Error: bit   

can not be entered for double type of precision: it works: Select

  (1024 :: integer): : Bit (32) & gt; & Gt; Choose 0000000000000000000000010000000000 (-1024 :: integer) :: bit (32) & gt; & Gt; Choose 11111111111111111111110000000000 (1024 :: big) :: Bit (64) & gt; & Gt; Choose 00000000000000000000000000000000000000000000010000000000 ((1717986 9 184 + 858 9934592) :: bigint) :: bit (64) & gt; & Gt; 000000000000000000000000000000000000000000000000000000000   

Official documents for double exact values ​​from SQL queries do not provide a way to do this.

However

  select -0 :: double excision AS minszro, 0 :: double excursion ace plusjro   

PGADamin III Returns the following results:

  "Kamazoro" plusjoro "-0; 0   

indicates that between PGDamin2 values ​​returned by postgres (Which is only different by the sign bit of the binary presentation) (IEEE standard 754) 0 and -0).

Anyhow I think pgAdmin is internal Receives a binary representation of the double precision value from the answer to the database from the dot, and it represents the decimal representation on the screen.

Double receives the binary representation of the exact value, and accordingly it shows a decimal presentation on the screen.

No, in fact it is not exactly binary It is -0 and 0 are text submissions that come verbatim to the server if pgAdmin considers binary, then it might be able to display the result of this SQL sequence Is:

  DECLARE c Select with Binero cursor -0 :: Double precision, minuszero, 0 :: double precision S PlusZoro; 1 stick from C;   

And in fact, it displays empty string as output in each column.

psql command line tool is also unable to deal with binary because it does not support empty byte in raw query result.

This is not a limitation of the C code Library, however PQexec () with its simplest function. Raw bytes can be obtained and can be displayed in this hex with this code:

  PGresult * res = PQexec (conn, "DECLARE C BINARY CURSOR WITH" "SELECT -0 :: At least as double accuracy, 0 :: double exceeds A.S.Placejo; "" F1c to F "); If ((int i = 0; i & lt; pecenfield (rac); i ++) {printf ("column% s:", PurityFace (reserved for reserve), (for RSA & peaccelestustus (RSC) == PGRESTUTS_OK) I)); (Int j = 0; j.m. lt; pyphousysis (rays, 0); J ++) printf ("% 02x", ((unsigned char *) peakviewview (race, 0, eye)) [j]); Printf ("\ n"); }}   

Result:

column minuszero: 8000000000000000
Columns Pluscero: 0000000000000000

You can see this icon bit as the first (and only) bit in the first column. This network is in the byte order, the first MSB, which is contrary to the disk representation of the small Andian architecture used in the XAC family.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -