lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
535 stars 192 forks source link

PostgreSQL bytea returned as hex string #84

Open ghost opened 6 years ago

ghost commented 6 years ago

For example:

create table test(col bytea);
insert into test values ('abc'::text::bytea);
select * from test;

shows

   col
----------
 \x616263
(1 row)

When read using LuaSQL, the value returned is the same string displayed: \x616263 rather than the string abc, even though Lua supports binary strings. This is highly inconvenient because it forces the application to decode the hexadecimal string, which has a high impact in performance (3x in my application).

I assume that a similar situation happens when writing data (which thankfully I don't need to use), but since it can only be done through a valid SQL statement, there's no way around that until prepared statements are available.

(Edited to make the example string longer and to match the output with the statement)

fcr-- commented 5 years ago

Lua also supports numbers and yet type(conn:execute('select 1'):fetch()) is string. I'd guess this was done for simplicity, since handling of specific types in return values in postgresql is not exactly easy.