LN function - Amazon Redshift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

LN function

Returns the natural logarithm of the input parameter.

Synonym of DLOG1 function.

Syntax

LN(expression)

Argument

expression

The target column or expression that the function operates on.

Note

This function returns an error for some data types if the expression references an Amazon Redshift user-created table or an Amazon Redshift STL or STV system table.

Expressions with the following data types produce an error if they reference a user-created or system table. Expressions with these data types run exclusively on the leader node:

  • BOOLEAN

  • CHAR

  • DATE

  • DECIMAL or NUMERIC

  • TIMESTAMP

  • VARCHAR

Expressions with the following data types run successfully on user-created tables and STL or STV system tables:

  • BIGINT

  • DOUBLE PRECISION

  • INTEGER

  • REAL

  • SMALLINT

Return type

The LN function returns the same type as the input expression.

Examples

To return the natural logarithm or base e logarithm of the number 2.718281828, use the following example.

SELECT LN(2.718281828); +--------------------+ | ln | +--------------------+ | 0.9999999998311267 | +--------------------+

Note that the answer is nearly equal to 1.

The following example uses the TICKIT sample database. For more information, see Sample database.

To return the natural logarithm of the values in the userid column in the USERS table, use the following example.

SELECT username, LN(userid) FROM users ORDER BY userid LIMIT 10; +----------+--------------------+ | username | ln | +----------+--------------------+ | JSG99FHE | 0 | | PGL08LJI | 0.6931471805599453 | | IFT66TXU | 1.0986122886681098 | | XDZ38RDD | 1.3862943611198906 | | AEB55QTM | 1.6094379124341003 | | NDQ15VBM | 1.791759469228055 | | OWY35QYB | 1.9459101490553132 | | AZG78YIP | 2.0794415416798357 | | MSD36KVR | 2.1972245773362196 | | WKW41AIW | 2.302585092994046 | +----------+--------------------+