> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oxla.com/llms.txt
> Use this file to discover all available pages before exploring further.

# pg_typeof()

## Overview

The <a href="https://www.postgresql.org/docs/current/functions-info.html#FUNCTIONS-INFO-CATALOG" target="_blank">pg\_typeof()</a> is a system catalog information function that retrieves the data type of any given value. It returns a string literal corresponding to the expression type.

## Syntax

The syntax of the `pg_typeof()` function is as follows:

```sql theme={null}
SELECT pg_typeof(`any`);
```

## Parameters

The following parameters are required to execute this function:

* `any`: represents any value you want to determine the data type of

## Examples

### Numeric

This example shows the function usage with a numeric value:

```sql theme={null}
SELECT pg_typeof(100) as "data type";
```

```sql theme={null}
 data type 
-----------
 integer
```

### String

In this example, we will use a string value as an input:

```sql theme={null}
SELECT pg_typeof('event'::TEXT) as "data type";
```

```sql theme={null}
 data type 
-----------
 text
```

### Interval

Here we will focus on using an interval input:

```sql theme={null}
SELECT pg_typeof(INTERVAL '1 day') as "data type";
```

```sql theme={null}
 data type 
-----------
 interval
```

### Table

For the needs of this section we will create a sample table and then use `pg_typeof()` to retrieve the data types of information stored in the table

```sql theme={null}
CREATE TABLE timestamp_example (
    id int,
    event_time timestamp,
    description text
);

INSERT INTO timestamp_example (event_time, description)
VALUES 
  ('2023-10-20 12:30:00', 'Event 1'),
  (NULL, 'Event 2');
```

Now that we created the table, let's use `pg_typeof()` function to determine the data types of the **event\_time** and description columns for each row

```sql theme={null}
SELECT 
    pg_typeof(event_time) AS event_time_type,
    pg_typeof(description) AS description_type
FROM timestamp_example;
```

By executing the query above we will get the following output

```sql theme={null}
       event_time_type       | description_type 
-----------------------------+------------------
 timestamp without time zone | text
 timestamp without time zone | text
```
