0

I've got an id column in my mysql table which contain a uuid in a binary(16) form , if i will select only this specific column like this:

SELECT uuid_from_bin(id) FROM table_name;

i will get the uuid properly but as soon as i try to select * like this: select * from table_name; i'm getting the uuid in binary form.

i tried something like this:

SELECT uuid_from_bin(id),* FROM table_name;

but this gives me an error

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
j.broklin
  • 45
  • 4
  • And what error do you get? Please include full error message in the question. – Joakim Danielson Apr 07 '19 at 12:00
  • 1
    Don't use `select *`. Specify only the columns you need. [Here's why.](https://stackoverflow.com/questions/3639861/why-is-select-considered-harmful) – Zohar Peled Apr 07 '19 at 12:02
  • @ZoharPeled i need every column but the id should be converted to uuid that's all , i can specifiy every column by name but i thought there is more simple approach – j.broklin Apr 07 '19 at 12:06
  • It's bad practice to use `select *`, with a few exceptions here and there. – Zohar Peled Apr 07 '19 at 12:08
  • *"Don't use select *. Specify only the columns you need"* i totally agree @ZoharPeled to bad most database abstraction layers work like that and select all data from a record assuming you don't manually build your query. – Raymond Nijland Apr 07 '19 at 12:20
  • 1
    @RaymondNijland that doesn't make it a good practice by any means. I personally avoid using full-scale ORM's partially because of performance issues.... – Zohar Peled Apr 07 '19 at 12:22

2 Answers2

1
SELECT *, uuid_from_bin(id) as uuid FROM table_name;
shakhawat
  • 2,639
  • 1
  • 20
  • 36
0

try to use alias for your table. in my example the alias is t

SELECT uuid_from_bin(t.id), t.* FROM table_name t;

if you need only specific columns, so do not use * in your select. use only columns you need e.g.

SELECT uuid_from_bin(t.id), t.col1, t.col2 ...
  FROM table_name t;
hotfix
  • 3,376
  • 20
  • 36