

In this one I get the data type of the return value of the make_date() function. In this case I passed the isfinite() function to the pg_typeof() function as its argument.Īnd here’s another example. It’s more likely that it will come from a variable.īut you could also use pg_typeof() to find out the return type of a function. SELECTīoolean | boolean Return Type of a FunctionĪgain, it’s unlikely you’ll be explicitly providing true or false to this function. Here’s an example of expilictly providing a boolean value. Here it is again, except that I change the data type to a different string type ( char(8)).

Raise notice 'Value: % % Type: %', myString, E'\n', pg_typeof(myString) DO $$ĭECLARE myString varchar(10) := 'Elephant' In this example, I put the previous string into a variable, then get its data type. In the real world, it’s more likely that you’ll be trying to get the data type of a variable. This last example was a bit superfluous, as I explicitly stated the variable type, which meant that I already knew what the result was going to be. In Postgres, character varying is the name for varchar (actually, varchar is the alias for character varying). Therefore you’ll need to specify its actual data type. Therefore, you can’t just surround an argument in single quotes and expect it to know what its data type is. In Postgres, there’s more than one type of string (e.g. The function has the following syntax: pg_typeof(any) Therefore it’s the same as an OID for comparison purposes but displays as a type name. It returns a regtype, which is an OID alias type. More specifically, it returns the OID of the data type of the value that is passed to it. In PostgreSQL, the pg_typeof() function allows you to get the data type of any value.
