1

I have a table and its data are mentioned below :

id | function
1  | current_date       
2  | UUID()       
3  | RAND()

Structure of the table is

id int, function varchar(50)

Query : select * from func_table;
My excepted result is

id | function
1  | 2020-08-24
2  | 70d6cffc-ae01-11ea-80ca-c11529136ae3630       
3  | 0.982584554752

Thanks in advance.

1
  • See about PREPARE Commented Aug 24, 2020 at 15:19

1 Answer 1

4

You can use a giant case expression:

select (case when function = 'current_date' then cast(current_date as char)
             when function = 'uuid()' then cast(uuid as char)
             when function = 'rand()' then cast(rand as char)
        end) as value

If you actually want to evaluate the function directly, then you probably have a problem with your data model. SQL does not directly support such functionality.

Sign up to request clarification or add additional context in comments.

1 Comment

Its good, but I have few functions in the table so it couldn't be a easy way. Anyways Thanks for the support

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.