473,804 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parser does not like %ROWTYPE in the RETURNS clause of a function declaration (BUG?)

Aother head banger for me.

Below is a complete example of the code

Using Postgres 7.4,
the function "test" gets this: psql:temp3.sql: 10: ERROR: syntax error
at or near "%" at character 135
the function "test2" gets this: psql:temp3.sql: 10: ERROR: syntax error
at or near "ROWTYPE" at character 141

Very odd. The first doesn't even like the '%' character -- perhaps because
doof is a table type rather than a column (domain) type???

And when we schema qualify the name of the table then the % is ok, but
ROWTYPE is not.

Is this a well-known limitation or a new (7.4) bug? I tried combing the
docs to no avail.

Thanks,

Ezra E.

<code>
/*
CREATE TABLE doof ( "pk_id" serial )
WITHOUT OIDS;
*/

CREATE OR REPLACE FUNCTION test(INTEGER)
RETURNS doof%ROWTYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;

CREATE OR REPLACE FUNCTION test2(INTEGER)
RETURNS public.doof%ROW TYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;
</code>
Nov 12 '05 #1
4 7144
ezra epstein wrote:
Aother head banger for me.

Below is a complete example of the code

Using Postgres 7.4,
the function "test" gets this: psql:temp3.sql: 10: ERROR: syntax error
at or near "%" at character 135
the function "test2" gets this: psql:temp3.sql: 10: ERROR: syntax error
at or near "ROWTYPE" at character 141

Very odd. The first doesn't even like the '%' character -- perhaps because
doof is a table type rather than a column (domain) type???

And when we schema qualify the name of the table then the % is ok, but
ROWTYPE is not.

Is this a well-known limitation or a new (7.4) bug? I tried combing the
docs to no avail.

Thanks,

Ezra E.

<code>
/*
CREATE TABLE doof ( "pk_id" serial )
WITHOUT OIDS;
*/

CREATE OR REPLACE FUNCTION test(INTEGER)
RETURNS doof%ROWTYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;

CREATE OR REPLACE FUNCTION test2(INTEGER)
RETURNS public.doof%ROW TYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;
</code>

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Try replacing the rowtype with SETOF doof:

CREATE OR REPLACE FUNCTION test(INTEGER)
RETURNS SETOF doof AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;

Hope that helps.
Ron
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #2
Dear ezra epstein ;
Using Postgres 7.4,
the function "test" gets this: psql:temp3.sql: 10: ERROR: syntax error
at or near "%" at character 135
the function "test2" gets this: psql:temp3.sql: 10: ERROR: syntax error
at or near "ROWTYPE" at character 141

Very odd. The first doesn't even like the '%' character -- perhaps because
doof is a table type rather than a column (domain) type???

ROWTYPE for SQL Language ???? you may please check that
<code>
/*
CREATE TABLE doof ( "pk_id" serial )
WITHOUT OIDS;
*/

CREATE OR REPLACE FUNCTION test(INTEGER)
RETURNS doof%ROWTYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;

CREATE OR REPLACE FUNCTION test2(INTEGER)
RETURNS public.doof%ROW TYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;
</code>

The above code gave error on mine system also PostgreSQL 7.3.4
what I think you want to something like this
<code>

CREATE OR REPLACE FUNCTION test2(INTEGER)
RETURNS public.doof AS '
SELECT * FROM doof WHERE pk_id = $1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;

CREATE OR REPLACE FUNCTION test1(INTEGER)
RETURNS doof AS '
SELECT * FROM doof WHERE pk_id = $1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;
</code>
Mine Limited knowledge tells me that this is not a BUG but just an
effect of thinking out of the box
Shoot back if I was right please.
Regards,
Vishal Kashyap

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #3
Thanks very much for the reply(s).

This does work! I'm not surprised that it does (after more reading of
docs). What surprises me is that %ROWTYPE does not work as it seems to work
most other places. I'm not enough of an Oracle PL/SQL whiz to know if
%ROWTYPE(s) can be returned from Oracle functions. If not, then this makes
some sense.
Still, for consistency, it seems, IMHO -- and from my limited knowledge
of Postgres -- that consistent declarations would be desirable. So if we
can:

DECLARE
result doof%ROWTYPE
BEGIN
....

and we can, Then it seems consistent and sensible to allow the %ROWTYPE form
for declaring a return type.

As to the other post suggesting returning a SETOF -- that will work, but
it is not what I want. I really just want a single row (a tuple) not
multiple rows. So declaring SETOF would be the wrong return type.

Thanks for the replies.

== Ezra Epstein

"Sai Hertz And Control Systems" <sa****@sanchar net.in> wrote in message
news:3F******** ******@sancharn et.in...
Dear ezra epstein ;
Using Postgres 7.4,
the function "test" gets this: psql:temp3.sql: 10: ERROR: syntax errorat or near "%" at character 135
the function "test2" gets this: psql:temp3.sql: 10: ERROR: syntax errorat or near "ROWTYPE" at character 141

Very odd. The first doesn't even like the '%' character -- perhaps becausedoof is a table type rather than a column (domain) type???

ROWTYPE for SQL Language ???? you may please check that
<code>
/*
CREATE TABLE doof ( "pk_id" serial )
WITHOUT OIDS;
*/

CREATE OR REPLACE FUNCTION test(INTEGER)
RETURNS doof%ROWTYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;

CREATE OR REPLACE FUNCTION test2(INTEGER)
RETURNS public.doof%ROW TYPE AS '
SELECT * FROM doof WHERE pk_id=$1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;
</code>

The above code gave error on mine system also PostgreSQL 7.3.4
what I think you want to something like this
<code>

CREATE OR REPLACE FUNCTION test2(INTEGER)
RETURNS public.doof AS '
SELECT * FROM doof WHERE pk_id = $1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;

CREATE OR REPLACE FUNCTION test1(INTEGER)
RETURNS doof AS '
SELECT * FROM doof WHERE pk_id = $1;
' LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT;
</code>
Mine Limited knowledge tells me that this is not a BUG but just an
effect of thinking out of the box
Shoot back if I was right please.
Regards,
Vishal Kashyap

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #4
"ezra epstein" <ee************ ***@prajnait.co m> writes:
CREATE OR REPLACE FUNCTION test(INTEGER)
RETURNS doof%ROWTYPE AS '


As somebody else pointed out, just write "doof" and you are done.
%ROWTYPE is an Oracle-ism that we support in the bodies of plpgsql
functions for compatibility's sake, but not elsewhere.

BTW, there is a related notation that we do support in CREATE FUNCTION
argument and result type declarations:
table.field % TYPE
for naming a type by reference to a field that has that type.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
15105
by: Phil Reardon | last post by:
Ive been away from programming for a few years and am having difficulty accessing a function from a math/engineering library that I want to use . I thought that double foo(double); inserted in the calling routine would let me say x=foo(y); But I get a warning from the compilation that says "warning: nested extern declaration of 'foo'. Thanks for any suggestions
6
1434
by: feminine.aura | last post by:
I have to read a file containing integers into a vector. I could do something like this: ifstream data("file.dat"); istream_iterator<intbegin(data); istream_iterator<intend; vector<intc(begin,end); Now this does what i want it to.
4
2212
by: werasm | last post by:
Hi all, I have recently come accross this function declaration syntax. Initially it was puzzling (still is, to be honest), but I now realize that it declares a function that returns a reference to an array. The declarator: char (& foo() ); //(1)
28
4341
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
6117
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
1
1911
by: INeedADip | last post by:
What is the difference between: function setupGrid( param ){......} and setupGrid = function( param ){......} Are there any advantages to doing one over the other?
2
4518
by: Joseph Turian | last post by:
I have a class Feature defined, which is a kind of Vocab: template <class T, unsigned I> class Vocab : boost::totally_ordered<Vocab<T,I { public: Vocab(); Vocab(const T& t); template<typename VVocab(V v, bool dummy); .... };
2
2711
by: parag_paul | last post by:
I understand that a const qualifier after the function declaration makes it a const function for the class. Like int func1 const ( double, long int ); Now what is the purpose of the following const int func1 const ( double, long int );
13
1992
by: Sri Harsha Dandibhotla | last post by:
Hello all. I recently came across a function declaration as : char(*(*x()))(); This was not in some code but it was in a C questions thread on some group. I tried to decipher what it returns but couldn't make complete sense out of it. Can someone please explain what this function is supposed to return and expand it step by step. Thanks,
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.