Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql. CREATE CAST 'character varying' to 'integer'

Tags:

postgresql

I want to CREATE CAST a suitable function to convert 'character varying' to 'integer'. Can anyone suggest a function? Everything I try fails.

like image 880
Simon Avatar asked Jan 21 '11 15:01

Simon


People also ask

How do I convert character to numeric in PostgreSQL?

Discussion: Use the :: operator to convert strings containing numeric values to the DECIMAL data type. In our example, we converted the string ' 5800.79 ' to 5800.79 (a DECIMAL value). This operator is used to convert between different data types.

What is character varying [] in PostgreSQL?

The notations varchar( n ) and char( n ) are aliases for character varying( n ) and character( n ) , respectively. character without length specifier is equivalent to character(1) . If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.

How do I cast type in PostgreSQL?

PostgreSQL supports a CAST operator that is used to convert a value of one type to another. Syntax: CAST ( expression AS target_type ); Let's analyze the above syntax: First, specify an expression that can be a constant, a table column, an expression that evaluates to a value.

What is the difference between varchar and character varying in PostgreSQL?

VARCHAR is an alias for CHARACTER VARYING , so no difference, see documentation :) The notations varchar(n) and char(n) are aliases for character varying(n) and character(n) , respectively. character without length specifier is equivalent to character(1) .


Video Answer


1 Answers

Use this:

CREATE CAST (varchar AS integer) WITH INOUT [AS IMPLICIT];

It uses the input/output functions of the data types involved.

like image 131
Peter Eisentraut Avatar answered Oct 20 '22 01:10

Peter Eisentraut