Proposal TODO Item: SQL-language reference parameters by name - Mailing list pgsql-hackers

From Gevik Babakhani
Subject Proposal TODO Item: SQL-language reference parameters by name
Date
Msg-id 001001c81af9$3b7c9b60$0a01a8c0@gevmus
Whole thread Raw
Responses Re: Proposal TODO Item: SQL-language reference parameters by name
Re: Proposal TODO Item: SQL-language reference parameters by name
List pgsql-hackers

Hi all,

 

I am working a lot with custom procedures/functions which are implemented in “language sql”. At the moment function parameter refs cannot work with parameter names. I would like to try to implement this. The actual TODO item is:

 

Allow SQL-language functions to reference parameters by parameter name

Currently SQL-language functions can only refer to dollar parameters, e.g. $1

 

After a quick look at how ref parameters in plpgsql and sql function are handled, I would like to start a discussion about the following implementation plan.

 

Implementation of the name parameter parsing in scan.l/gram.y can be achieved by adopting the same mechanism as plpgsql does. If I am not mistaking plpgsql parser creates a stack to store parameter identifiers.

 

Correct me if this would be wrong or not possible, but I am thinking of mapping the name references to the parameter numbers (par2 => $2) this way I hope to keep the implementation small and perhaps extend "struct ParamRef" to hold a possible parameter name.

 

Then there is the issue of error reporting for ambiguous parameter names (non existing parameter names and names which conflict with actual column names). I guess this can be handeled in "fmgr_sql_validator”

 

Please let me know your opinion.

 

Regards,

Gevik.

pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: Proposal: real procedures again (8.4)
Next
From: Camilo Porto
Date:
Subject: Re: URGENT HELP about 'duration' stats