cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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 III

Hi @Himanshu Agrawalโ€‹ ,

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

Ajay Kumar Pandey

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
Databricks Employee
Databricks Employee

Capture dโ€™eฬcran 2023-02-23 aฬ€ 10.43.49I tried it in Databricks SQL It does work.

SergeRielau
Databricks Employee
Databricks Employee

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!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group