【发布时间】:2013-08-14 14:09:56
【问题描述】:
我需要一些关于在 postgreSQL 中定义函数的帮助:
这是我的表定义:
CREATE TABLE venue (
id INTEGER DEFAULT NEXTVAL('venue_id_seq')
, building_code building_code
, floorNo int
, roomNo int
, width int
, length int
);
我需要创建一个与该表相关的函数,该函数为我提供楼层面积。这是我目前所拥有的:
CREATE FUNCTION floorArea(id int) RETURNS int AS '
SELECT venue.width * venue.length AS result ;
' LANGUAGE SQL;
我不知道如何制作变量等。
我想要一些类似的东西:
var width= Select width from venue where id=$1;
var length= Select length from venue where id=$1;
return width * length;
【问题讨论】:
标签: function postgresql variables plpgsql