Ok, I'm pretty good with MsftSQL, but there's enough differences with PostgreSQL to make things confusing.
I'm having a problem declaring a function (I want a stored proc). Here's my schema -
CREATE TABLE author
-
(
-
"authorName" character varying(100) NOT NULL,
-
"authorID" integer NOT NULL DEFAULT nextval('"author_authorID_seq"'::regclass),
-
CONSTRAINT "PK_authorID" PRIMARY KEY ("authorID"),
-
CONSTRAINT "UK_authorID" UNIQUE ("authorID")
-
)
-
-
CREATE TABLE book
-
(
-
"bookID" integer NOT NULL DEFAULT nextval('"book_bookID_seq"'::regclass),
-
"bookName" character varying(100) NOT NULL,
-
"authorID" integer NOT NULL,
-
CONSTRAINT book_pkey PRIMARY KEY ("bookID"),
-
CONSTRAINT "book_authorID_fkey" FOREIGN KEY ("authorID")
-
REFERENCES author ("authorID") MATCH SIMPLE
-
ON UPDATE RESTRICT ON DELETE RESTRICT,
-
CONSTRAINT "U_bookID" UNIQUE ("bookID")
-
)
-
-
create type t_book_author as ( bookID integer, authorID integer,
-
bookName varchar, authorName integer );
-
-
CREATE OR REPLACE FUNCTION testFunc( bID integer )
-
RETURNS SETOF t_book_author AS $$
-
begin
-
select B.bookID, B.authorID, B.bookName, A.authorName
-
from book B
-
inner join author A on A.authorID = B.authorID
-
where B.bookID = bID;
-
-
end;
-
$$ LANGUAGE plpgsql;
-
Now, when I try to run the function:
I get this error, which makes no sense to me at all.
ERROR: column a.authorid does not exist
SQL state: 42703
Context: PL/pgSQL function "testfunc" line 2 at SQL statement
Any ideas? Thanks
4 2020 michaelb 534
Recognized Expert Contributor
The first thing that caught my eye is that type t_book_author is defined as
(integer, integer, varchar, integer );
but what you actually select is
(integer, integer, varchar, varchar)
Can you correct this disagreement and see if it fixes the problem?
michaelb 534
Recognized Expert Contributor
Sorry, I could not think straight, but something made me come back and take another look at this posting.
My previous comment probably still holds, but nature of your problem is quite different.
When you created your tables you included column names in double-quotes, meaning you used a case-sensitive syntax. Therefore you must use case-sensitive syntax when referring to these columns in your queries, whether it is a plain SQL or a function.
For most people using case-sensitive names brings nothing but trouble.
Had you created your table with the same field names, but without double quotes, you would be able to address columns using case-insensitive syntax.
I think if you change your syntax to use case sensitive names it'll take care of your problem: -
select B."bookID", B."authorID", B."bookName", A."authorName" ... ...
-
Thanks, that makes complete sense.
Quick question, though. I'm using pgAdmin III to create my tables, and there doesn't seem to be a way to specify case insensitivity. Any ideas? Are there better admin tools out there for pgSql?
michaelb 534
Recognized Expert Contributor
My advise - stay away from it.
There are very few scenarios where case sensitive names for tables or columns help, more often this hurts because you have to watch your code and put all those names in double-quotes.
By the same token you should be able to create database objects with case sensitive names if you include names in double-quotes.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Thomas Matthews |
last post by:
Hi,
I'm getting linking errors when I declare a variable in the
global scope, but not inside a function. The declarations
are the same (only the names have been changed...).
class Book
{
public:
Book()
|
by: Rob Somers |
last post by:
Hey people,
I read a good thread on here regarding the reason why we use function
prototypes, and it answered most of my questions, but I wanted to
double check on a couple of things, as I am writing something up on
functions, and I don't like writing about things I am not sure about.
Ok, then, here we go:
I initially thought that one would only really need to use a function
|
by: Dennis Chang |
last post by:
Hi all,
I was reading about function pointers and came across something which
intrigued me.
K&R2 calls qsort (pg.119) within main as so:
qsort( (void **) lineptr, 0, nlines-1, (int (*) (void *, void*))(numeric ?
numcmp : strcmp) );
I guess what interests me is the nameless function pointer and then the
|
by: grist2mill |
last post by:
I want to create a standard tool bar that appears on all pages that is
a control. The toolbar has a button 'New'. What I wolud like when the
user clicks on 'New' depends on the page they are on. I would like to
do this by defining a NewFunc() that is different in each
(code-behind) page which is called by the standard 'New' button in the
toolbar.
How can I get this to work? So far I have the following (which doesnt
work). When the user...
|
by: Yelena Varshal via AccessMonster.com |
last post by:
Hello,
I have a problem with one of msaccess.exe API calls that work on my desctop
but does not work on the laptop from within MS ACCESS. There is a lot of
differences between 2 computers including one running Office 2000 and another
running Office 2003. This code was created by a previous developer. I need to
find the description and parameters of the API calls. I found the article
...
| |
by: Christian Christmann |
last post by:
Hi,
in a benchmark I've found an uncommon use of a function.
This is the simplified form:
1 int foo( int f )
2 {
3 return f;
4 }
5
|
by: svata |
last post by:
Hello there,
after some time of pondering I come to some solution which would suit
me best. Please correct, if I am wrong.
Function has two parameters. A string array, better said a pointer to
it, char *p_buf and int size.
int read_name( char *p_buf, int size) {
char *p_item_name_1;
|
by: Paulo Matos |
last post by:
Hi all,
I'm trying to work out a parser for function declarations but it turns
out that it is harder than I initially thought.
I'm looking at 3rd Ed of Stroustrup, page 808.
I'm trying to parse something like:
int foo(int, int);
const double *xpto(mytype *, mytype &) const;
But I'm not being able to find my way around the grammar.
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2
Ask on python-list@python.org .
- Josiah
|
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...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |