cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Databricks sql not able to evaluate expression current_user

Himanshu_90
New Contributor III

Hi,

I have a table as below:

create table default.test_user(

ID bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1),

usr1 varchar(255) NOT NULL,

ts1 timestamp NOT NULL,

usr2 varchar(255) NOT NULL,

ts2 timestamp NOT NULL) USING Delta;

I tried to insert data as below:

insert into table default.test_user

(usr1,ts1,usr2,ts2)

values

(current_user,current_timestamp,current_user,current_Timestamp)

I am getting error as below:

cannot evaluate expression current_user() AS `current_user()` in inline table definition; line 4 pos 1

Please suggest.

8 REPLIES 8

Kemp48
New Contributor II

The current_user function in Databricks SQL is not evaluated as a valid expression, as it is not supported by the platform. Instead, you can use the current_user_name function to retrieve the current user's name.

Thanks,

Aetna Medicare

Himanshu_90
New Contributor III

select current_user is working for me... it is the combination with current_timestamp which is not working. Please try this:

insert into table default.test_user

(usr1,ts1,usr2,ts2)

values

(current_user,current_timestamp,current_user,current_Timestamp)

Ajay-Pandey
Esteemed Contributor II

Hi @Himanshu Agrawal​ ,

It's working for me, please refer below snapshot for the same-

select current_user works for me as well... but it does not work for the specific scenario which i have pasted... with the current_timestamp

Try this:

insert into table default.test_user

(usr1,ts1,usr2,ts2)

values

(current_user,current_timestamp,current_user,current_Timestamp)

Sundot
New Contributor II
  1. Syntax. Copy. current_date()
  2. Arguments. This function takes no arguments.
  3. Returns. A DATE. The braces are optional.
  4. Examples. SQL Copy. > SELECT current_date(); 2020-04-25 > SELECT current_date; 2020-04-25.
  5. Related functions. current_timestamp function

youssefmrini
Honored Contributor III
Honored Contributor III

Capture d’écran 2023-02-23 à 10.43.49I tried it in Databricks SQL It does work.

SergeRielau
Contributor III
Contributor III

It appears current_user() is blocked from VALUES because it is considered non-detereministic.

I've taken the liberty of opening:

https://issues.apache.org/jira/browse/SPARK-42638

feel free to open a support ticket to add some **ompf**.....

Anonymous
Not applicable

Hi @Himanshu Agrawal​ 

Hope everything is going great.

Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you. 

Cheers!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.