[SQL] Creating a boolean function

2001-09-19 Thread Miguel González

by the way you know how to create the following sql function?

I need to return a boolean saying if an object is onloan.

the loan table is as follows:

loans
-
code_loan
code_user
typetable


i want to check these three fields, the first two fields (the code ones) are
integer and the last a string.

I tried

create function check_loan (text,int,int)
returns bool
as
'select CAST(typetable AS text) from loans where typetable=$1 and
code_user=$2 and code_loan=$3;'
language 'sql';


But I got that the parser cannot identify the =$ operator and requires me to
do the proper casting.

How can I do it? Sorry for the questions, but I am new at creating functions
and I have to hand in this project tomorrow.

Many thanks

Miguel






---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



[SQL] URGENT ! Nouveau virus

2001-09-19 Thread Denis Bucher


Hello !

Ok...

I wrote a small text against that virus just in case you need it !

http://www.horus.ch/virus180901.txt

A bientôt !

Denis Bucher


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [SQL] Holiday Calculations?

2001-09-19 Thread clayton cottingham

clayton cottingham wrote:
> 
> Brett Schwarz wrote:
> >
> > I couldn't resist, so I went ahead and did all of them. I might be using
> > these in a future app anyways. Again these are Tcl procs, but you may be
> > able to transfer the logical to another language, if you want.
> >
> 
> if you need this in perl i think Data::Manip might hep:
> 

sorry ,
i noticed a typo it should be
Date::Manip

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster



Re: [SQL] Out of free buffers... HELP!

2001-09-19 Thread Tom Lane

"Diehl, Jeffrey" <[EMAIL PROTECTED]> writes:
> Brick* implies 1334 tables

Hmm ... I wonder if the query is somehow holding onto a buffer pin for
the last block of each successively-accessed table?  Will look into it.

What -B (# of shared buffers) setting are you running the postmaster
with?  Try setting it to 1500 or more, if it's not already.

regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



Re: [SQL] Out of free buffers... HELP!

2001-09-19 Thread Josh Berkus

Mike,

> I recently lost a hard drive and had to re-install, so the PG version
> I am
> using is only about 3 weeks old.  However, as I said in my original
> post, I
> have A LOT of data in this database.  Brick* implies 1334 tables,
> some of
> which have 2.5M records...  All told, I have about 355G of data.  I
> don't
> care if it takes DAYS to run queries like this, but I need them to
> finish.

Um, Mike, I think you need *professional* DB tuning/performance help.
Maybe a contract with PostgreSQL Inc. or Bruce Momjian or Red Hat?  Or
me, if your budget is limited (but I'm not as good as Bruce or Chris)

-Josh

__AGLIO DATABASE SOLUTIONS___
   Josh Berkus
  Complete information technology  [EMAIL PROTECTED]
   and data management solutions   (415) 565-7293
  for law firms, small businessesfax 621-2533
and non-profit organizations.  San Francisco

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster



[SQL] PL/PGSQL Regexe

2001-09-19 Thread rdear

I'm doing a check within a PL/PGSQL function using a regular expression 
and I get the error:

ERROR:  regcomp failed with error invalid character range

This appears to be because of the underscore "_" character. The regex I 
want to use is ''[A-Za-z0-9_]'' but this doesn't work. Any suggestions 
or is this a bug/feature?



---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



Re: [SQL] Registring a C function in PostgreSQL II

2001-09-19 Thread Haller Christoph

I'm working on a HP-UX system, so some of the 
following has to be adapted, but in principle 
it's the same on every system and it works. 
First piece of code is a standalone program, 
which you should always write and test before 
you start creating C functions inside PostgreSQL. 
Second piece is your sendemail function slightly 
modified to make it run on my system. 
When I do a 
select sendemail('ch', 'was soll das?') ;
I'm receiving an email from postgres. 
Regards, Christoph 

First piece:

/*
cc -Aa -g -I/opt/pgsql/include/ -c sendemtest.c
cc sendemail.o sendemtest.o -o sendemtest
*/
#include 
#include 
#include 
#include "postgres.h"

void main() {
   char buf[1024];
   int ln;
   text *res;
   text *to;
   int sendemail(text *email,text *message);
   
   strcpy(buf, "Kissenminister Aussinger \n");
   ln = strlen(buf);
   
   res = (text *) malloc(VARHDRSZ + ln);
   memset(res, 0, VARHDRSZ + ln);
   res->vl_len = VARHDRSZ + ln;
   memcpy(res->vl_dat, buf, (int) ln);
   
   strcpy(buf, "ch");
   ln = strlen(buf);
   
   to = (text *) malloc(VARHDRSZ + ln);
   memset(to, 0, VARHDRSZ + ln);
   to->vl_len = VARHDRSZ + ln;
   memcpy(to->vl_dat, buf, (int) ln);
   
   sendemail(to, res);
}

Second piece: 

/*
cc -Aa -g -I/opt/pgsql/include/ +z -c sendemail.c
ld -b -o sendemail.sl sendemail.o

CREATE FUNCTION sendemail(text,text) RETURNS int4
 AS '/fdsk2/users/ch/tools/pgsql.mydoc/sendemail.sl' LANGUAGE 'c';
DROP FUNCTION sendemail(text,text);
*/
 #include 
 #include 
 #include "postgres.h"

 int sendemail(text *email,text *message)
 {
 int result = 0 ; 

 char string_tosend [300];

 sprintf(string_tosend,"/usr/bin/echo \"%s\" 
>/tmp/mailtmp.txt\n",VARDATA(message));

 result += system(string_tosend);

 sprintf(string_tosend,"/usr/bin/mail -dt %s 


Re: [SQL] PL/PGSQL Regexe

2001-09-19 Thread Tom Lane

rdear <[EMAIL PROTECTED]> writes:
> I'm doing a check within a PL/PGSQL function using a regular expression 
> and I get the error:

> ERROR:  regcomp failed with error invalid character range

> This appears to be because of the underscore "_" character. The regex I 
> want to use is ''[A-Za-z0-9_]'' but this doesn't work.

Seems to work for me:

regression=# select 'a' ~ '[A-Za-z0-9_]';
 ?column?
--
 t
(1 row)

regression=# select '_' ~ '[A-Za-z0-9_]';
 ?column?
--
 t
(1 row)

regression=# select ':' ~ '[A-Za-z0-9_]';
 ?column?
--
 f
(1 row)

How old is your Postgres?  (I can tell by the spelling of the error
message that it's not current.)

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [SQL] Creating a boolean function

2001-09-19 Thread Jeff Eckermann

Maybe the reason is that you defined the function to return bool, but are
attempting to return text?
You need conditional logic, which suggests pl/pgsql is the way to go.
Something simple should do it, like:

create function check_loan (text,int,int)
returns bool
as '
begin
select * from loans where typetable=$1 and code_user=$2 and code_loan=$3;
if found then return true;
else return false;
end if;
return true;
end;
' language 'plpgsql';

Since this is your project, I will take the luxury of not testing that code
:-)


- Original Message -
From: "Miguel González" <[EMAIL PROTECTED]>
To: "Haller Christoph" <[EMAIL PROTECTED]>
Cc: "PostgreSQL SQL" <[EMAIL PROTECTED]>
Sent: Wednesday, September 19, 2001 1:55 PM
Subject: Creating a boolean function


> by the way you know how to create the following sql function?
>
> I need to return a boolean saying if an object is onloan.
>
> the loan table is as follows:
>
> loans
> -
> code_loan
> code_user
> typetable
>
>
> i want to check these three fields, the first two fields (the code ones)
are
> integer and the last a string.
>
> I tried
>
> create function check_loan (text,int,int)
> returns bool
> as
> 'select CAST(typetable AS text) from loans where typetable=$1 and
> code_user=$2 and code_loan=$3;'
> language 'sql';
>
>
> But I got that the parser cannot identify the =$ operator and requires me
to
> do the proper casting.
>
> How can I do it? Sorry for the questions, but I am new at creating
functions
> and I have to hand in this project tomorrow.
>
> Many thanks
>
> Miguel
>
>
>
>
>
>
> ---(end of broadcast)---
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
>
>


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



Re: [SQL] Registring a C function in PostgreSQL

2001-09-19 Thread Haller Christoph

Did you use the compiler option for generating 
position independent code (PIC) for use in building
shared libraries.
Did you use the linker option for creating 
a shared library - I think you did, the file 
suffix .so looks that way. 
I did it several times successfully using commands 
like 
CREATE FUNCTION byteatostr(bytea) RETURNS text
 AS './byteatostr.sl' LANGUAGE 'c';
and it worked. 
Maybe you should add some more information about 
what you did in detail. 
Regards, Christoph 

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



[SQL] Implicit v Explicit joins...

2001-09-19 Thread [EMAIL PROTECTED]

So I wasn't paying enough attention to postgres upgrades and missed that 7.1 actually 
has outer joins, so I'm currently happily rebuilding, but I had a few questions about 
the explicit join syntax and preformance issues.

1. Say i have a tables called 
"married" (marriedid, husband, wife), 
"people" (peopleid, firstname, lastname, townid), and 
"towns" (townid, townname)
(not the exact exaple, but should be close enough).  
I want to get a list of all couples (fullname of both husband/wife with hometown) 
where the hometown of one equals 'foo';
Would this be the proper way of setting up the query?
SELECT h.firstname, h.lastname, h.hometown, 
   w.firstname, w.lastname, w.hometown
  FROM married m 
  JOIN people h ON (m.husband=h.peopleid) 
  JOIN people w ON (m.wife=w.peopleid)
  LEFT OUTER JOIN towns ht (h.townid=ht.townid)
  LEFT OUTER JOIN towns wt (w.townid=wt.townid)
 WHERE ht.townname='foo' OR wt.townname='foo';

2.  In general is explicit outer join more efficient than the old union select syntax? 
Is the outer join syntax just syntacic sugar (does it decode into the union selects)?
3.  I think I saw someone that explicit joins occur in order, giving the planner less 
room to optimize, is this correct?  I've often heard that you want to preform your 
inner joins before the other joins in order to limit the size of the tables being 
used.  Will the planner consider putting implicit inner joins before the explicit 
outers or do all explicits occur first?

Thank you.
Eric Nielsen


mail2web - Check your email from the web at
http://mail2web.com/ .


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [SQL] group by weirdness

2001-09-19 Thread Carl van Tast

On Sat, 15 Sep 2001 00:26:01 +0200, I wrote:

> [...]
>CREATE VIEW mj1 (jid, cnt) AS
>SELECT jid, COUNT(mid) cnt FROM mj GROUP BY jid;

This should be COUNT(mid) AS cnt ...

> [...]
>I did not test this with PostgreSQL, but you get the idea.

Well, now I did test with PostgreSQL (thanks, Jason Tishler, for your
Cygwin PostgreSQL README!). PG does not support column aliases without
"AS". 

>Probably PG is even smart enough to handle it all in one:

Sure it is. So, Joseph, your solution is:

SELECT j.id, j.created, mj1.cnt, ml1.cnt, ml2.cnt
FROM j
LEFT JOIN (SELECT jid, COUNT(mid) AS cnt
   FROM mj
   GROUP BY jid) mj1
 ON (j.id = mj1.jid)
LEFT JOIN (SELECT jid, COUNT(*) AS cnt
   FROM ml
   WHERE state <> 11
   GROUP BY jid) ml1
 ON (j.id = ml1.jid)
LEFT JOIN (SELECT jid, COUNT(*) AS cnt
   FROM ml
   WHERE state IN (2, 5)
   GROUP BY jid) ml2
 ON (j.id = ml2.jid)
WHERE j.fkey = 1;

HTH,
 Carl van Tast

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



Re: [SQL] Registring a C function in PostgreSQL

2001-09-19 Thread Miguel González

Many thanks for your answers. The thing that in the Bruce´s book doesnt
explain how to compile this kind of functions, anyway I found how to compile
it.

 Now, I am still having problems. I want to create a function to send an
email. I pass to the function two arguments: the email to send, and the text
to send.

 First, I tried with pointers to char. It worked when I just create a
function called "sendemail()" with no arguments and set inside the text and
the email arguments.

 When I read some more documentation about how to use strings in PostgreSQL,
I discovered that I have to use the text type in my C program I just try it
but
although it worked before, now I doesnt work.

 This is what I have tried:


 #include 
 #include "postgres.h"

 int sendemail(text *email,text *message)
 {

 char string_tosend [300];

 sprintf(string_tosend,"echo \"%s\" >/tmp/mailtmp.txt
\n",VARDATA(message));

 system(string_tosend);

sprintf(string_tosend,"mail -s \"message from PostgreSQL\" %s

To: "Miguel González" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, September 19, 2001 12:24 PM
Subject: Re: [SQL] Registring a C function in PostgreSQL


> Did you use the compiler option for generating
> position independent code (PIC) for use in building
> shared libraries.
> Did you use the linker option for creating
> a shared library - I think you did, the file
> suffix .so looks that way.
> I did it several times successfully using commands
> like
> CREATE FUNCTION byteatostr(bytea) RETURNS text
>  AS './byteatostr.sl' LANGUAGE 'c';
> and it worked.
> Maybe you should add some more information about
> what you did in detail.
> Regards, Christoph
>


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [SQL] Holiday Calculations?

2001-09-19 Thread Brett Schwarz

I couldn't resist, so I went ahead and did all of them. I might be using
these in a future app anyways. Again these are Tcl procs, but you may be
able to transfer the logical to another language, if you want.



proc getTG {year} {
 
set di \
[clock format [clock scan $year-11-30] -format "%w"]
 
return [expr {30 - ((($di+1)%7)+2)}]
 
}
 
proc getMem {year} {
 
set di \
[clock format [clock scan $year-05-31] -format "%w"]
 
return [expr {31 - ((($di+6)%7))}]
 
}
 
 
proc getLabor {year} {
 
set di \
[clock format [clock scan $year-09-01] -format "%w"]
 
return [expr {(((8-$di)%7) + 1)}]
 
}





Josh Berkus wrote:
> 
> Folks,
> 
> I'm spec'ing a calendar app for PostgreSQL, and was wondering if anyone
> had already solved the following problem:
> 
> How can I calculate the dates of American holidays?
> 
> Obviously, Christmas & New Year's are easy.  As is July 4.
> 
> However, Thanksgiving is the last Thursday in November, unless the month
> ends on a Thursday or Friday, in which case it is the next-to-last.
> Memorial Day and Labor Day are simpler, but also use the "First or Last
> Monday in x month" idea.
> 
> I was wondering if anyone had already figured out these calculations, in
> any language (SQL would be terrific).
> 
> Thanks!
> 
> -Josh
> 
> __AGLIO DATABASE SOLUTIONS___
>Josh Berkus
>   Complete information technology  [EMAIL PROTECTED]
>and data management solutions   (415) 565-7293
>   for law firms, small businessesfax 621-2533
> and non-profit organizations.  San Francisco
> 
>   
>Name:
>Type: Plain Text (text/plain)
>Encoding: base64
> 
>Name:
>Type: Plain Text (text/plain)
>Encoding: base64
> 
>Name:
>Type: Plain Text (text/plain)
>Encoding: base64
> 
>   
> 
> ---(end of broadcast)---
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



Re: [SQL] Checking for table existence (fwd)

2001-09-19 Thread Kovacs Baldvin


Some of you may get this message for the second time, but as
I see there is some problem with one particular mail server
on the route, and this message didn't arrive back from the
list despite the fact that I sent it several days ago.

--
Subject: Re: [SQL] Checking for table existence

>
> CREATE FUNCTION my_function ( ...
>
> 
> IF NOT table_exists(''my_table'') THEN
>   CREATE TABLE ...
> END IF;
> 
>
>
> Got the idea?

Not bad... Well, I am not the person questioned... But let me
share a few ideas about it.

The solution what I gave was a "more SQL way" of doing it. So after
creating the function qexec, you could write a long file, x.sql, like

... sql blabla...
... sql blabla...

CASE WHEN ...the table not exests... THEN qexec('the creator sql command')
END;

... sql blabla...

My experience is this is a quite universal style, if a company
would like to create an sql-database structure for a certain job.

Your solution is also based on functions, so the realization is quite
similar. But you have either write a function for every table creation,
or write an intelligent function, which gets HOW to create WHAT table...

My first idea was something like this, but later I thougth it is
"politically more correct" if I use only a very universal function,
what I called qexec.

Moreover, I can imagine that I would see happily this sql-executor
function in the base distribution, not only int the documentation,
as an example. It is quite a good example...

However, your solution is naturally a good and usable solution, please
do not treat this letter as an offensive letter. I only tried to argue
a bit for my way of thinking...

Thanks for reading this, if you reached this pont, :-))

Regads,
Baldvin





---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



Re: [SQL] Holiday Calculations?

2001-09-19 Thread clayton cottingham

Brett Schwarz wrote:
> 
> I couldn't resist, so I went ahead and did all of them. I might be using
> these in a future app anyways. Again these are Tcl procs, but you may be
> able to transfer the logical to another language, if you want.
> 


if you need this in perl i think Data::Manip might hep:

 Date_IsHoliday
$name=&Date_IsHoliday($date);

   This returns undef if $date is not a holiday, or a
   string containing the name of the holiday otherwise.
   An empty string is returned for an unnamed holiday.


also there is a section on holidays in the 
config file where you can set up your own :
  1/1 = New Year's Day
  third Monday in Feb = Presidents' Day
  fourth Thu in Nov   = Thanksgiving


hope this is useful!

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



Re: [SQL] Out of free buffers... HELP!

2001-09-19 Thread Diehl, Jeffrey

I recently lost a hard drive and had to re-install, so the PG version I am
using is only about 3 weeks old.  However, as I said in my original post, I
have A LOT of data in this database.  Brick* implies 1334 tables, some of
which have 2.5M records...  All told, I have about 355G of data.  I don't
care if it takes DAYS to run queries like this, but I need them to finish.

Ok, you may be thinking that I am nuts to try to store this much data and to
break it up into so many tables.  Well, I used to have it all in one
table  It took several days to vacuum it, and because inserts are
happening all the time, I was unable to have the tables indexed and still be
able to keep up with the incoming data.  This new structure addresses these
and other issues.

Any help would be most appreciated.

Mike Diehl,
Network Monitoring Tool Devl.
Sandia National Laboratories.
(505) 284-3137
[EMAIL PROTECTED]

> -Original Message-
> From: Tom Lane [mailto:[EMAIL PROTECTED]]
> Sent: September 18, 2001 5:26 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: [SQL] Out of free buffers... HELP!
> 
> 
> [EMAIL PROTECTED] (D'Arcy J.M. Cain) writes:
> > Thus spake Diehl, Jeffrey
> >> psql ids -c 'select src,dst,count(*) from brick* where src_port=135
> >> group by src,dst' > /tmp/135.dat
> 
> > Hard to tell without knowing more but perhaps you need another table
> > instead of/in addition to this one that just tracks the counts.  You
> > can use a trigger to increment it.  If you only allow inserts this
> > should be easy.  Deletes are easy too.  Updates are a 
> little trickier.
> 
> The thing is, you shouldn't ever get "out of free buffers", period.
> Jeffrey must be running into some kind of buffer-leak bug ... but it's
> hard to think what, unless he's running an extremely old PG version.
> We haven't seen reports of buffer leaks in a long time.  So I'd like
> to run that down, quite independently of whether he should change his
> query for efficiency.
> 
>   regards, tom lane
> 
> ---(end of 
> broadcast)---
> TIP 4: Don't 'kill -9' the postmaster
> 


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [SQL] Out of free buffers... HELP!

2001-09-19 Thread Diehl, Jeffrey

Ok, can someone explain to me why this first query might run faster than the
second?

select src,dst,count(dst) from data;

select src,dst,count(*) from data;

I've always used the second form.  If the first is faster, I need to know.

Thanx,
Mike Diehl,
Network Monitoring Tool Devl.
Sandia National Laboratories.
(505) 284-3137
[EMAIL PROTECTED]

> -Original Message-
> From: Haller Christoph [mailto:[EMAIL PROTECTED]]
> Sent: September 18, 2001 7:18 AM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: [SQL] Out of free buffers... HELP!
> 
> 
> As long as there are no nulls allowed in column 'dst' the 
> select src,dst,count(dst) from ... 
> should retrieve the same result. 
> Try it. It should run faster anyway. 
> Maybe there are other ways to word your query, but without 
> more knowledge about your table structure and intentions 
> I can't tell you what. 
> Alternatively, you may want to report your error to the 
> [HACKERS] mailing list - there you might even find more
> detailed support. 
> Regards, Christoph 
> > 
> > Hi all.
> > 
> > I sent this once before, but didn't see it appear on the 
> list...  So here we
> > go again...
> > 
> > I have a large query that I'm trying to run, but it never 
> finishes.  I
> > get an error message and it quits.
> > 
> > I'm doing:
> > 
> > psql ids -c 'select src,dst,count(*) from brick* where src_port=135
> > group by src,dst' > /tmp/135.dat
> > 
> > and I get:
> > 
> > ERROR:  out of free buffers: time to abort !
> > 
> > Any ideas on how to get this query to run?
> > 
> > Thanx,
> > Mike Diehl.
> > 
> > 
> > ---(end of 
> broadcast)---
> > TIP 1: subscribe and unsubscribe commands go to 
> [EMAIL PROTECTED]
> > 
> 
> 
> ---(end of 
> broadcast)---
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to 
> [EMAIL PROTECTED])
> 


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [SQL] Creating a boolean function

2001-09-19 Thread Tom Lane

=?iso-8859-1?Q?Miguel_Gonz=E1lez?= <[EMAIL PROTECTED]> writes:
> But I got that the parser cannot identify the =$ operator

You need a space between = and $.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [SQL] Creating a boolean function

2001-09-19 Thread Kovacs Baldvin

> You need conditional logic, which suggests pl/pgsql is the way to go.

Maybe he could use simple sql function like this:

create function check_loan(text,int,int) returns boolean as '
select (
  select count(*) from kolcsonok where
 code_user=($2) and code_loan=($3) and typetable=($1)
) > 0;
' language 'sql';

The immediate benefit of it is that there's no need to install
a procedural languge for this simple task.

Regards,
Baldvin


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

http://archives.postgresql.org



Re: [SQL] Creating a boolean function

2001-09-19 Thread Stephan Szabo

On Wed, 19 Sep 2001, [iso-8859-1] Miguel González wrote:

> I tried
> 
> create function check_loan (text,int,int)
> returns bool
> as
> 'select CAST(typetable AS text) from loans where typetable=$1 and
> code_user=$2 and code_loan=$3;'
> language 'sql';
> 
> 
> But I got that the parser cannot identify the =$ operator and requires me to
> do the proper casting.
> 
> How can I do it? Sorry for the questions, but I am new at creating functions
> and I have to hand in this project tomorrow.

You can probably get away with just putting a space before the arguments,
so '= $1' rather than '=$1'.



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

http://archives.postgresql.org



Re: [SQL] Registring a C function in PostgreSQL

2001-09-19 Thread Peter Eisentraut

Miguel González writes:

>  ERROR:/load of file /home/postgres/ctof.so failed: /home/postgres/ctof.so
> ELF file´s phentsize not the expected size.

You probably didn't compile or link the code correctly.  See the
PostgreSQL Programmer's Guide for information.

-- 
Peter Eisentraut   [EMAIL PROTECTED]   http://funkturm.homeip.net/~peter


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [SQL] Stored prosedure last run

2001-09-19 Thread Josh Berkus

Pasha,

> I'm trying to find if anyone knows how to find out when the stored
> procedure was used last time (not created).

If you want to do this, you'd need to create your own log table, and
write to it at the beginning of your function:

CREATE TABLE function_log (
   run_id SERIAL NOT NULL PRIMARY KEY,
   function_name VARCHAR(100) NOT NULL,
   run_date TIMESTAMP NOT NULL DEFAULT current_timestamp);

CREATE FUNCTION my_function ( ...

... BEGIN
INSERT INTO function_log ( function_name )
VALUES ( 'my_function' );
...

Got it?

-Josh


__AGLIO DATABASE SOLUTIONS___
   Josh Berkus
  Complete information technology  [EMAIL PROTECTED]
   and data management solutions   (415) 565-7293
  for law firms, small businessesfax 621-2533
and non-profit organizations.  San Francisco

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]