USERNAME: from Tableau to SQL

Returns the configured user name. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

USERNAME()

Sample data

labelquantityamountflag
cedar cedar 6512.8True
ORCHID-west66-7.6False
maple-east670null
willow north6825.3True
birch-birch694.9False
pine/south70-1.2null
ash719True
nullnullnullnull

The same calculation as SQL

SELECT 'linh@example.test' AS result FROM input

Runs the example above.

Result

result
linh@example.test
linh@example.test
linh@example.test
linh@example.test
linh@example.test
linh@example.test
linh@example.test
linh@example.test

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • SQL must receive the application user context; database session identity is a different principal.

    Naive SQL

    SELECT 'warehouse_service' AS result FROM input
    result
    warehouse_service
    warehouse_service
    warehouse_service
    warehouse_service
    warehouse_service
    warehouse_service
    warehouse_service
    warehouse_service

    Matches the calculation

    SELECT 'linh@example.test' AS result FROM input
    result
    linh@example.test
    linh@example.test
    linh@example.test
    linh@example.test
    linh@example.test
    linh@example.test
    linh@example.test
    linh@example.test

Signature

USERNAME()