473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

execute funtions in psql

1
Hi,

I am new to psql so i am having a little trouble acommodating with the language. Here is the problem: I have created a small functions that returns true or false:
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION DriverLogin(VARCHAR, VARCHAR)
  2. RETURNS BOOLEAN AS '
  3. DECLARE
  4.     l_username ALIAS FOR $1;
  5.     l_password ALIAS FOR $2;
  6.  
  7.      /* for checking the rowcount */
  8.     myRowCount  INTEGER;
  9.  
  10.     /* for getting @@IDENTITY, which PostgreSQL calls an OID */
  11.     theOid   OID;
  12. BEGIN
  13.     select * from tblUsers where usertype=1 and username=l_username and userpassword=l_password;
  14.     GET DIAGNOSTICS myRowCount := ROW_COUNT;
  15.     IF myRowCount = 0 THEN
  16.        return false;
  17.     END IF;
  18.     return true;
  19. END;
  20. ' LANGUAGE 'plpgsql';
  21.  
the problem is that i do not know how to call this function from psql or even php. I tried in psql:
PERFORM DriverLogin('a','f'); and it works but it does not show the result returned by the function.

When i tried to call it like this:
SELECT DriverLogin('a','f'); I get this error:
ERROR: SELECT query has no destination for result data
HINT: If you want to discard the results, use PERFORM instead.
CONTEXT: PL/pgSQL function "driverlogin" line 11 at SQL statement

So if anyone can please help me I would appreciate it. Thanks!
May 25 '07 #1
2 7291
bartonc
6,596 Expert 4TB
You have posted in the Articles section.
Please find the PostgreSQL Forum here.
I'd move your post, but I'm not a moderator of this forum.
May 25 '07 #2
michaelb
534 Expert 512MB
Please read the Posting Guidelines at the top of the Forum, especially the section regarding the use of the CODE tags.

I think a simple SQL like this will suffice:
Expand|Select|Wrap|Line Numbers
  1. select count(*) from tblUsers 
  2. where usertype = 1 and username = 'abc' and userpassword = 'xyz';
  3.  
But if you do want to have a function there's no need to have it so bloated, a thin SQL function should do the job:
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION DriverLogin(VARCHAR, VARCHAR)
  2. RETURNS integer AS '
  3.    SELECT COUNT(1)::integer FROM tblUsers  WHERE usertype = 1 AND login = $1 AND passwd = $2;
  4. ' LANGUAGE SQL;
  5.  
  6. -- call the function
  7. select DriverLogin('john', 'abc123');
  8.  
May 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Daniel Schuchardt | last post by:
Hi @ all, i'm sure there was a psql-function to transfere my Blob-Data to the server but I can't remember. I have a script like this : UPDATE xy SET z = lo_import('localpath_and_file'); ...
3
by: Bernie V | last post by:
Hi group, I have 2 js files where I have scrollfuntions. Is it possible to execute the 2 funtions in the page load event ? What code do i have to use to execute function1();function2() ? At...
4
by: Phil Campaigne | last post by:
Hi All, I just installed postgresql 7.3.4 as an upgrade to 7.3.2 and all went well untill I tried to log into a database that I successfully created. Here are the steps in question: bash-2.05b$...
7
by: Willem Herremans | last post by:
I am developing a client application for postgreSQL in Tcl/Tk (see http://gborg.postgresql.org/project/pfm ). It mainly uses PgTcl or pgintcl. I don't have any problems with those, but I am also...
1
by: Josué Maldonado | last post by:
Hello List, I'm having this issue with beta 8.0 C:\pgsql\bin>pg_dump -U postgres farmacia > xfar.sql Password: C:\pgsql\bin>psql -U postgres farmacia2 < xfar.sql Password: psql: FATAL: ...
2
by: Russ Brown | last post by:
Hello, Today I tried connecting to my database locally via psql. I got the usual welcome & basic help messages, but it never got to the prompt: it just hung. So I checked top and the psql...
1
by: Jack Bauer | last post by:
How can I execute a query which prompt the user for input? Something like SELECT FROM Table WHERE Name= In Oracle PL/SQL, you use & before variable names to have the SQL*Plus ask for input....
3
by: oksofar | last post by:
Hello - I'm running PG 8.1 on Windows XP. I've installed the server to run as a service. The psql command fails to connect to the server, although I can connect with other clients. When I...
1
by: GOPALA | last post by:
Hi , How To Execute A Psql Commands Through Batch File(.bat). My Aim Is , Usting Batch File , Connect The Database And Then Execute The Psql Statements.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.