Need for advice and direction (again)

Started by Gevik Babakhaniover 18 years ago2 messageshackers
Jump to latest
#1Gevik Babakhani
pgdev@xs4all.nl

Hello Tom,

I would like to know your opinion about the way we should refer to composite
type params in functions.
For example:

CREATE TABLE emp (
name text,
salary numeric,
age integer,
cubicle point
);

CREATE FUNCTION double_salary(emp) RETURNS numeric AS $$
SELECT $1.salary * 2 AS salary;
$$ LANGUAGE SQL;

How should we refer to emp in the following example.

CREATE FUNCTION double_salary(PARAM1 emp) RETURNS numeric AS $$

-- At this moment PARAM1.salary will fail because PARAM1
-- is compared to the name of this function
SELECT PARAM1.salary * 2 AS salary;

-- Would this be correct?
SELECT double_salary.PARAM1.salary * 2 AS salary;

$$ LANGUAGE SQL;

Regards,
Gevik.

------------------------------------------------
Gevik Babakhani

PostgreSQL NL http://www.postgresql.nl
TrueSoftware BV http://www.truesoftware.nl
------------------------------------------------

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gevik Babakhani (#1)
Re: Need for advice and direction (again)

"Gevik Babakhani" <pgdev@xs4all.nl> writes:

How should we refer to emp in the following example.

CREATE FUNCTION double_salary(PARAM1 emp) RETURNS numeric AS $$

-- At this moment PARAM1.salary will fail because PARAM1
-- is compared to the name of this function
SELECT PARAM1.salary * 2 AS salary;

It'd need to be

SELECT (PARAM1).salary * 2 AS salary;

This is already the case in other usages of composite types.

regards, tom lane