Simple Authority Simple Authority - 5 months ago 7
SQL Question

Is it possible to select everything from a MySQL database meanwhile applying a function to a specific column?

Given a database table which is built like so:

| id | unique_id | display_name | ip_address | updated_at | created_at |
|----|--------------------------------------|-----------------|---------------|------------------|------------------|
| 1 | 768ef24f-79ab-481e-b50f-45b0466933c1 | SimpleAuthority | *binary data* | *some timestamp* | *some timestamp* |
| 2 | 069a79f4-44e9-4726-a5be-fca90e38aaf5 | Notch | *binary data* | *some timestamp* | *some timestamp* |


I know that I can
SELECT
each column explicitly and apply
INET6_NTOA
on
ip_address
:

SELECT id, unique_id, display_name, INET6_NTOA(ip_address), updated_at, created_at FROM users WHERE unique_id='768ef24f-79ab-481e-b50f-45b0466933c1';


however, that seems like too much work where without having that binary encoded data in there at all I could simply use a
*
:

SELECT * FROM users WHERE unique_id='768ef24f-79ab-481e-b50f-45b0466933c1';


Can I
SELECT
all this data using a query, while decoding that binary data in the
ip_address
column using
INET6_NTOA
?

Answer

Try this;)

SELECT *, INET6_NTOA(ip_address) FROM users WHERE unique_id='768ef24f-79ab-481e-b50f-45b0466933c1';
Comments