Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type double does not exist in PostgreSQL

Tags:

postgresql

I have table like this:

CREATE TABLE workingtime_times
(
  workingno serial NOT NULL,
  checktime character(6) NOT NULL,
  timeoffset double precision DEFAULT 9
)

I create function like this:

CREATE OR REPLACE FUNCTION MyFName()
    RETURNS TABLE(
        CheckTime character varying,
        TimeOffset double 
    ) AS
$BODY$
BEGIN 
    RETURN QUERY 
    SELECT  t.CheckTime, t.TimeOffset
    FROM WorkingTime_Times t
    ORDER BY t.WorkingNo DESC
    limit 1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION MyFName()
  OWNER TO postgres;

It make an error like this:

type double does not exist

Why we can create an table with column datatype double but return in the function fail. What type we can return in this case?

like image 490
Hong Van Vit Avatar asked Oct 16 '18 04:10

Hong Van Vit


People also ask

What does := mean in PostgreSQL?

:= is the assignment operator in PL/pgSQL.

What is double precision in PostgreSQL?

The double precision type has a range of around 1E-307 to 1E+308 with a precision of at least 15 digits. Values that are too large or too small will cause an error. Rounding might take place if the precision of an input number is too high.

What is serial datatype in Postgres?

PostgreSQL has a special kind of database object generator called SERIAL. It is used to generate a sequence of integers which are often used as the Primary key of a table. Syntax: variable_name SERIAL.

How do I change the datatype in PostgreSQL?

First, specify the name of the table to which the column you want to change belongs in the ALTER TABLE clause. Second, give the name of column whose data type will be changed in the ALTER COLUMN clause. Third, provide the new data type for the column after the TYPE keyword.

What causes PostgreSQL error double does not exist?

Caused by: org.postgresql.util.PSQLException: ERROR: type "double" does not exist Postgres have instead "DOUBLE PRECISION" type.

Can not create types in PostgreSQL if not exists?

Types and Roles If Not Exists in PostgreSQL. For certain operations such as creating types and roles in PostgreSQL you are not able to use the handy IF NOT EXISTS parameter. This makes creating reusable scripts a bit more challenging, especially if you are going to be running these scripts more than once against the same database.

How to fix “operator does not exist” error in PostgreSQL?

If you get the “ operator does not exist: integer || integer” error in PostgreSQL, it’s probably because you’re trying to concatenate two numbers. If you really want to concatenate two numbers, the easiest way to overcome this issue is to cast at least one of them to a string data type first. Another way to do it is to use the CONCAT () function.

Is serial data type unique in PostgreSQL?

Note: Prior to PostgreSQL 7.3, serial implied UNIQUE . This is no longer automatic. If you wish a serial column to have a unique constraint or be a primary key, it must now be specified, just like any other data type.


1 Answers

The name of the type is DOUBLE PRECISIONand not just DOUBLE. Thus, your function header should look like this:

CREATE OR REPLACE FUNCTION MyFName() RETURNS TABLE(
    CheckTime CHARACTER VARYING, TimeOffset DOUBLE PRECISION 
) AS

You may also use type references:

CREATE OR REPLACE FUNCTION MyFName() RETURNS TABLE(
    CheckTime working_intems.checktime%TYPE, 
    TimeOffset workingtime_times.timeoffset%TYPE 
) AS
like image 167
clemens Avatar answered Sep 19 '22 18:09

clemens