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?
:= is the assignment operator in PL/pgSQL.
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.
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.
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.
Caused by: org.postgresql.util.PSQLException: ERROR: type "double" does not exist Postgres have instead "DOUBLE PRECISION" type.
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.
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.
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.
The name of the type is DOUBLE PRECISION
and 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With