Re: [SQL] plpgsql : adding record variable to table

2012-04-19 Thread Pavel Stehule
2012/4/19 thomas veymont : > that made it, thank you. > For other readers, here is what I finally did : > > CREATE TABLE mytable (...) > > CREATE FUNCTION (...) RETURNS SETOF  mytable AS $$ > DECLARE >  r mytable%rowtype > BEGIN > ... >  FOR r IN select * from mytable >     LOOP >       >

Re: [SQL] plpgsql : adding record variable to table

2012-04-19 Thread thomas veymont
that made it, thank you. For other readers, here is what I finally did : CREATE TABLE mytable (...) CREATE FUNCTION (...) RETURNS SETOF mytable AS $$ DECLARE r mytable%rowtype BEGIN ... FOR r IN select * from mytable LOOP RETURN next r; END LOOP; RETURN; END

Re: [SQL] plpgsql : adding record variable to table

2012-04-19 Thread Pavel Stehule
2012/4/19 thomas veymont : > hi Pavel, > > thanks for your answer, > > I don't understand exactly how "y" should be declared, and how it > should be returned by the function (as a table, > as a "set of record", or maybe as some kind of generic object, I don't > know exactly what's possible with pl

Re: [SQL] plpgsql : adding record variable to table

2012-04-19 Thread thomas veymont
hi Pavel, thanks for your answer, I don't understand exactly how "y" should be declared, and how it should be returned by the function (as a table, as a "set of record", or maybe as some kind of generic object, I don't know exactly what's possible with pl/psql.). cheers Tom 2012/4/18 Pavel Steh

Re: [SQL] plpgsql : adding record variable to table

2012-04-18 Thread Pavel Stehule
Hello please try: postgres=# create or replace function foo() returns void as $$ declare r x; begin for r in select * from x loop insert into y values(r.*); end loop; end; $$ language plpgsql; Regards Pavel 2012/4/18 thomas veymont : > (sorry my previous email was truncated) > > hi,

[SQL] plpgsql : adding record variable to table

2012-04-18 Thread thomas veymont
(sorry my previous email was truncated) hi, Here is what I want to do : I want to check each row of a table against some conditions (this check needs some processing stuff I can easily code with pl/pgsql). If the row is OK, I want to add it in a "resulting table", else I just ignore the current

[SQL] plpgsql : adding record variable to table

2012-04-18 Thread thomas veymont
hi, say I have the following (simplified for discussion) pl/pgsql function: FUNCTION myfunction ( ...) RETURNS TABLE ( elem1 integer, elem2 text, ...) DECLARE g RECORD BEGIN FOR g in SELECT colum1, column2 FROM someTable LOOP -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)

Re: [SQL] plpgsql: how to get the exception's detail information?

2011-12-01 Thread Filip Rembiałkowski
2011/11/29 Muiz : >    I write a function to execute a sql string. E.g. "update tableA set > field1='abc' where name='123'; deletee from tableB where id=333;" >    The following is my function: > ---

[SQL] plpgsql: how to get the exception's detail information?

2011-12-01 Thread Muiz
Dear all, I write a function to execute a sql string. E.g. "update tableA set field1='abc' where name='123'; deletee from tableB where id=333;" The following is my function: --

Re: [SQL] plpgsql function executed multiple times for each return value

2011-10-08 Thread Tom Lane
Steve Northamer writes: > So my questions are: 1) How do we cause the paymentcalc function to be > executed only once? In recent versions, I think marking it volatile would be sufficient. regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)

Re: [SQL] plpgsql function executed multiple times for each return value

2011-10-08 Thread David Johnston
> So my questions are: 1) How do we cause the paymentcalc function to be > executed only once? and 2) How do we call a table returning function with > inputs from a table? > > Thank you very much! > > Steve > WITH func AS ( SELECT FUNC(...) AS func_result FROM ... ) SELECT (func.func_re

[SQL] plpgsql function executed multiple times for each return value

2011-10-08 Thread Steve Northamer
We have a plpgsql function called paymentcalc, which calculates the payment necessary to pay off a loan. It's defined like this: CREATE OR REPLACE FUNCTION paymentcalc(IN amount numeric, IN interestrate numeric, IN termmonths integer, IN paymentfreq integer, IN dueday1 integer, IN dueday2 i

Re: [SQL] PLpgSQL variables persistance between several functions calls

2011-05-03 Thread Viktor Bojović
the best way is to put all calls into one function and store values to variables.. if that is not suitable you can try the way (which im not sure if anyone uses) and it is to store values to sequences if value type is integer. for other formats you will have to do conversions. but im not sure if s

Re: [SQL] PLpgSQL variables persistance between several functions calls

2011-05-03 Thread Willy-Bas Loos
Hi, Maybe calling a function from within another function would be a solution to you. Cheers, WBL On Tue, May 3, 2011 at 4:10 AM, Pavel Stehule wrote: > Hello > > no, it's not possible > > Regards > > Pavel Stehule > > 2011/5/2 Charles N. Charotti : > > Hello everybody ! > > > > I want to know

Re: [SQL] PLpgSQL variables persistance between several functions calls

2011-05-02 Thread Pavel Stehule
Hello no, it's not possible Regards Pavel Stehule 2011/5/2 Charles N. Charotti : > Hello everybody ! > > I want to know if I could share PLpgSQL variables between different > functions and within different calls just using memory (not tables or other > methods). > > If it is really possible ? >

[SQL] PLpgSQL variables persistance between several functions calls

2011-05-02 Thread Charles N. Charotti
Hello everybody ! I want to know if I could share PLpgSQL variables between different functions and within different calls just using memory (not tables or other methods). If it is really possible ? Thanks in advance, Chuck

Re: [SQL] plpgsql exception handling

2011-03-10 Thread Uwe Bartels
stupid me. I edited a function with the same name, but different parameter types and tested with the other function. so everything works fine. thanks everybody for help. best regards, Uwe On 10 March 2011 11:53, Uwe Bartels wrote: > same same. > all errors including syntax_error match to othe

Re: [SQL] plpgsql exception handling

2011-03-10 Thread Samuel Gendler
On Thu, Mar 10, 2011 at 2:53 AM, Uwe Bartels wrote: > same same. > all errors including syntax_error match to others, but I checked it again. > and the exception remains. > I'm just guessing here, but is it throwing a new exception in the exception handler? I realize that the exception that is

Re: [SQL] plpgsql exception handling

2011-03-10 Thread Uwe Bartels
same same. all errors including syntax_error match to others, but I checked it again. and the exception remains. Uwe On 10 March 2011 10:56, Samuel Gendler wrote: > > > On Thu, Mar 10, 2011 at 12:45 AM, Uwe Bartels wrote: > >> Hi, >> >> Yes, of course is this sql producing an error. >> The po

Re: [SQL] plpgsql exception handling

2011-03-10 Thread Samuel Gendler
On Thu, Mar 10, 2011 at 12:45 AM, Uwe Bartels wrote: > Hi, > Yes, of course is this sql producing an error. > The point is, I want to trap the error and handle it. Here in this case I > set the variable l_state and l_message. > Doh! Of course. Sorry about that. What happens when you explicit

Re: [SQL] plpgsql exception handling

2011-03-10 Thread Uwe Bartels
yes, p_id is a variable in my code which is bigger. so ignore the update statement. Uwe On 10 March 2011 01:20, bricklen wrote: > On Wed, Mar 9, 2011 at 2:08 PM, Samuel Gendler > wrote: > > when I run 'select 1count(*) from table' in my postgres 8.4 installation, > I > > get the exact same err

Re: [SQL] plpgsql exception handling

2011-03-10 Thread Uwe Bartels
Hi, Yes, of course is this sql producing an error. The point is, I want to trap the error and handle it. Here in this case I set the variable l_state and l_message. But The function exits with an exception instead of returning. So the exception statement does not work as I think i would. And

Re: [SQL] plpgsql exception handling

2011-03-09 Thread bricklen
On Wed, Mar 9, 2011 at 2:08 PM, Samuel Gendler wrote: > when I run 'select 1count(*) from table' in my postgres 8.4 installation, I > get the exact same error message.  Assuming the '1count()' function does > exist, perhaps you need to full qualify it with a schema name? > It looks to me like the

Re: [SQL] plpgsql exception handling

2011-03-09 Thread Samuel Gendler
when I run 'select 1count(*) from table' in my postgres 8.4 installation, I get the exact same error message. Assuming the '1count()' function does exist, perhaps you need to full qualify it with a schema name? It looks to me like the query you are passing to the procedure is invalid and is gener

[SQL] plpgsql exception handling

2011-03-09 Thread Uwe Bartels
Hi, I'm trying to run an execute with a dynamic sql command within a function. I need a clean exception handling here, but my version does not work somehow. I want to trap a possible syntax error and write the error code, error message and the sql into a table. the function looks similar to this

Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Sergey Konoplev
2010/8/19 Tom Lane : >> 2010/8/18 Horváth Imre : >>> It don't work... > > A function returning a scalar type cannot control the column name > assigned to the scalar in the calling query.  To do that, you need to > return a composite type, which means there need to be at least two OUT > parameters i

Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Tom Lane
> 2010/8/18 Horváth Imre : >> It don't work... A function returning a scalar type cannot control the column name assigned to the scalar in the calling query. To do that, you need to return a composite type, which means there need to be at least two OUT parameters if you're trying to do it via OUT

Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Sergey Konoplev
What is your PG version? 2010/8/18 Horváth Imre : > It don't work... > > Only select into status * from... works. > > Imre Horvath > > 2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta: >> Hi, >> >> SELECT column_name >> INTO var_name >> FROM ... >> >> 2010/8/17 Horváth Imre : >>

Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Imre Horvath
It don't work... Only select into status * from... works. Imre Horvath 2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta: > Hi, > > SELECT column_name > INTO var_name > FROM ... > > 2010/8/17 Horváth Imre : > > Hi! > > > > My question is, how can I get the out

Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Horváth Imre
It don't work... Only select into status * from... works. Imre Horvath 2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta: > Hi, > > SELECT column_name > INTO var_name > FROM ... > > 2010/8/17 Horváth Imre : > > Hi! > > > > My question is, how can I get the out parameter from

Re: [SQL] plpgsql out parameter with select into

2010-08-17 Thread Sergey Konoplev
Hi, SELECT column_name INTO var_name FROM ... 2010/8/17 Horváth Imre : > Hi! > > My question is, how can I get the out parameter from a function with > SELECT INTO by name? > I mean: > > create function testfunc1(OUT _status integer) returns integer as > $BODY$ >        _status := 0; > $BODY$ > l

[SQL] plpgsql out parameter with select into

2010-08-17 Thread Horváth Imre
Hi! My question is, how can I get the out parameter from a function with SELECT INTO by name? I mean: create function testfunc1(OUT _status integer) returns integer as $BODY$ _status := 0; $BODY$ language plpgsql; create function testfunc2() as declare status integer; $BODY$

Re: [SQL] plpgsql out parameter with select into

2010-08-17 Thread Pavel Stehule
Hello It cannot work, you mix the sql with plpgsql language 2010/8/17 Imre Horvath : > Hi! > > My question is, how can I get the out parameter from a function with > SELECT INTO by name? > I mean: > > create function testfunc1(OUT _status integer) returns integer as > $BODY$ >        _status :=

[SQL] plpgsql out parameter with select into

2010-08-17 Thread Imre Horvath
Hi! My question is, how can I get the out parameter from a function with SELECT INTO by name? I mean: create function testfunc1(OUT _status integer) returns integer as $BODY$ _status := 0; $BODY$ language plpgsql; create function testfunc2() as declare status integer; $BODY$

Re: [SQL] Plpgsql: Iterating through a string of parameters

2010-03-26 Thread Jasen Betts
On 2010-03-25, Leif Biberg Kristensen wrote: > I'm struggling with how to make plpgsql iterate through a list of numbers > input as a text string, eg. "1438 2656 973 4208". I figure that I can use the > regexp_split_to_array() function to make an array of the string, but can I > iterate through

[SQL] Plpgsql: Iterating through a string of parameters

2010-03-25 Thread Leif Biberg Kristensen
I'm struggling with how to make plpgsql iterate through a list of numbers input as a text string, eg. "1438 2656 973 4208". I figure that I can use the regexp_split_to_array() function to make an array of the string, but can I iterate through an array with eg. a FOR loop? regards, -- Leif Bibe

Re: [SQL] Plpgsql: Iterating through a string of parameters

2010-03-25 Thread Leif Biberg Kristensen
On Thursday 25. March 2010 16.16.53 Leif Biberg Kristensen wrote: > I'm struggling with how to make plpgsql iterate through a list of numbers > input as a text string, eg. "1438 2656 973 4208". I figure that I can use the > regexp_split_to_array() function to make an array of the string, but can

Re: [SQL] plpgsql loop question

2010-02-10 Thread Adrian Klaver
On 02/10/2010 08:29 AM, Andrea Visinoni wrote: hi, i have a table called "zones": idzone, zone_name and several tables called zonename_records (same structure), where zonename is one of the zone_name in the "zones" table. What i want to do is a function that union all of this tables dinamically b

Re: [SQL] plpgsql loop question

2010-02-10 Thread Justin Graf
On 2/10/2010 11:29 AM, Andrea Visinoni wrote: > hi, > i have a table called "zones": idzone, zone_name > and several tables called zonename_records (same structure), where > zonename is one of the zone_name in the "zones" table. > What i want to do is a function that union all of this tables > di

[SQL] plpgsql loop question

2010-02-10 Thread Andrea Visinoni
hi, i have a table called "zones": idzone, zone_name and several tables called zonename_records (same structure), where zonename is one of the zone_name in the "zones" table. What i want to do is a function that union all of this tables dinamically based on "zones" table, this is what i've done

Re: [SQL] Plpgsql: Assign regular expression match to variable

2009-09-01 Thread Leif B. Kristensen
On Tuesday 1. September 2009, Ian Barwick wrote: >This seems to do what you want: > > my_int := (REGEXP_MATCHES(txt, E'^#(\\d+)'))[1]; Great! I had no idea that REGEXP_MATCHES() could do that kind of stuff. pgslekt=> select (REGEXP_MATCHES('#42 blabla', E'^#(\\d+)')) [1]::integer; regexp_match

Re: [SQL] Plpgsql: Assign regular expression match to variable

2009-09-01 Thread Ian Barwick
2009/9/1, Leif B. Kristensen : > In Plpgsql, I've got this problem of how to assign an integer extracted > from a regex to a variable. My approach so far feels kludgy: > > -- extract ^#(\d+) from txt > IF txt SIMILAR TO E'#\\d+%' THEN > my_int := SUBSTR(SUBSTRING(txt, E'#\\d+'), 2, > LE

[SQL] Plpgsql: Assign regular expression match to variable

2009-09-01 Thread Leif B. Kristensen
In Plpgsql, I've got this problem of how to assign an integer extracted from a regex to a variable. My approach so far feels kludgy: -- extract ^#(\d+) from txt IF txt SIMILAR TO E'#\\d+%' THEN my_int := SUBSTR(SUBSTRING(txt, E'#\\d+'), 2, LENGTH(SUBSTRING(txt, E'#\\d+')) -1)::INTEGER

Re: [SQL] plpgsql setof help

2009-01-28 Thread Frank Bax
Tom Lane wrote: "Matthew T. O'Connor" writes: I want the following: select column_to_english_list( select towns from towns_table ); to return: 'town1, town2 and town3' I wonder though if it wouldn't be better to recast the problem as an aggregate: select column_to_english_list(towns) from

Re: [SQL] plpgsql setof help

2009-01-28 Thread Tom Lane
"Matthew T. O'Connor" writes: > I want the following: > select column_to_english_list( select towns from towns_table ); > to return: > 'town1, town2 and town3' > In order to do this, I think I would have to create a pl/pgsql function > that accpts a setof text argument, but I'm not sure that's

[SQL] plpgsql setof help

2009-01-28 Thread Matthew T. O'Connor
Hello, I'm trying to write a pl/pgsql function that takes in a column (setof?) of text values and returns an english language list, for example: if "select towns from towns_table;" retuned town1 town2 town3 I want the following: select column_to_english_list( select towns from towns_table ); t

Re: [SQL] plpgsql language not aware of standard_conforming_strings ?

2007-11-12 Thread Sabin Coanda
"Sabin Coanda" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Sabin Coanda" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > ... >> >> How can I get my desired function that means when I call test( 'a\b' ) it >> will return 'a\\b' ? >> > ... > CREATE OR REPLACE

Re: [SQL] plpgsql language not aware of standard_conforming_strings ?

2007-11-12 Thread Sabin Coanda
"Sabin Coanda" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] ... > > How can I get my desired function that means when I call test( 'a\b' ) it > will return 'a\\b' ? > The problem seems to be the constant evaluation in plpgsql functions which is not aware of standard_conforming_

[SQL] plpgsql language not aware of standard_conforming_strings ?

2007-11-12 Thread Sabin Coanda
Hi there, Having standard_conforming_strings = 'on', I build the following scenario. I request SELECT replace( 'a\b', '\', '\\' ), which get me the result: replace - a\\b I'd like to build a function that give me the same result, as: CREATE OR REPLACE FUNCTION "test"(s varchar) RET

Re: [SQL] plpgsql array looping

2007-04-25 Thread Richard Albright
yeah i noticed that this morning, it used to be a while loop, for some reason (probably parser related) it keeps giving me an error on the exit when statement in the loop. On Wed, 2007-04-25 at 09:38 -0400, John DeSoi wrote: > One problem (unless you intend to only look at every other element) >

Re: [SQL] plpgsql array looping

2007-04-25 Thread John DeSoi
One problem (unless you intend to only look at every other element) is that you are incrementing idxptr explicitly in your loop. The FOR loop does that for you. This is the reason your output shows only even values. John On Apr 24, 2007, at 4:42 PM, Richard Albright wrote: for i

[SQL] plpgsql array looping

2007-04-24 Thread Richard Albright
I am attempting to create a moving average elements function that will return a set of elements in a particular moving average and am having difficulty iterating thrrough the passed in array properly. Any help would be greatly appreciated. code below... select getmovavgelements( aggarray(trade_d

Re: [SQL] plpgsql function question

2007-04-04 Thread John DeSoi
If you use a plpgsql function to select the row you want to validate, it will make life much easier. Something like ... $$ declare my_row a_row_type; is_ok integer; begin select into my_row * from a_row_type where is_ok := my_a_validate(my_row); return is_ok; $$ ... On Apr 4, 20

Re: [SQL] plpgsql function question

2007-04-03 Thread A. Kretschmer
am Tue, dem 03.04.2007, um 13:19:26 -0700 mailte Karthikeyan Sundaram folgendes: > Thank you very much. It works. I am not doing any insert or update hence I > cannot create a trigger. But my another question is > > How will I pass the values to Foo parameters. > > I mean > > I want to p

Re: [SQL] plpgsql function question

2007-04-03 Thread John DeSoi
It should work pretty much like you have it. You don't need a type; the table is already a type. Something like: create or replace function a_func (in p_row a) returns int as $$ if p_row.i ... if p_row.j ... $$ If it does not work, show the error and I'll try to dig up an example. John

Re: [SQL] plpgsql function question

2007-04-03 Thread A. Kretschmer
the table-structure. Than you can create your function. test=# create type a as ( i int, j varchar(20), k date); CREATE TYPE test=*# create function my_a (IN foo a) returns int as $$begin return 1; end; $$ language plpgsql; CREATE FUNCTION test=*# > > Date: Tue, 3 Apr 2007 20:18:43 +0200

Re: [SQL] plpgsql function question

2007-04-03 Thread Karthikeyan Sundaram
Date: Tue, 3 Apr 2007 20:18:43 +0200> From: [EMAIL PROTECTED]> To: > pgsql-sql@postgresql.org> Subject: Re: [SQL] plpgsql function question> > > Karthikeyan Sundaram <[EMAIL PROTECTED]> schrieb:> > > > > Hi,> > > > I am > having a requireme

Re: [SQL] plpgsql function question

2007-04-03 Thread Andreas Kretschmer
Karthikeyan Sundaram <[EMAIL PROTECTED]> schrieb: > > Hi, > > I am having a requirement here. > > 1) I need to write a plpgsql function where it takes the input > parameter of a structure of a table. Because? To build this table? You can pass an ascii-text

[SQL] plpgsql function question

2007-04-03 Thread Karthikeyan Sundaram
Hi, I am having a requirement here. 1) I need to write a plpgsql function where it takes the input parameter of a structure of a table. 2) The table has 15 columns 3) It does lots of validation based on the parameter and finally returns an integer as output parameters Q) Ho

Re: [SQL] plpgsql function return array

2007-03-31 Thread Michael Fuhr
On Sat, Mar 31, 2007 at 12:43:44AM -0700, Karthikeyan Sundaram wrote: > Hi, I am using Postgres 8.1.0. I have a requirement. I will > create a function accepting few parameters. This will check into > various tables and give back an array of values. I want to use the > pgpsql block. I know

[SQL] plpgsql function return array

2007-03-30 Thread Karthikeyan Sundaram
Hi, I am using Postgres 8.1.0. I have a requirement. I will create a function accepting few parameters. This will check into various tables and give back an array of values. I want to use the pgpsql block. I know that we can create using language sql. Is it possible to return an ar

[SQL] PLPGSQL question

2006-11-06 Thread Sorin Schwimmer
Hi All,I have a stored procedure that fails and don't know how to fix it, so I hope to find some help here.I works on a table called 'locations' that looks like this:design=# \d locations   Table "public.locations" Column  | Type |  Modifiers-+---

Re: [SQL] plpgsql record as parameter ???

2006-10-26 Thread Aaron Bono
On 10/18/06, Andy <[EMAIL PROTECTED]> wrote: Hi, I have the following function:   CREATE OR REPLACE FUNCTION zahlavis_rech_list(int4, varchar(10)) RETURNS "varchar" AS$BODY$DECLAREavis_id ALIAS FOR $1;rech_type ALIAS FOR $2;rech_list text;sql text;rec RECORD;BEGIN   rech_list := '';sql :=

[SQL] plpgsql record as parameter ???

2006-10-18 Thread Andy
Hi, I have the following function:   CREATE OR REPLACE FUNCTION zahlavis_rech_list(int4, varchar(10)) RETURNS "varchar" AS$BODY$DECLAREavis_id ALIAS FOR $1;rech_type ALIAS FOR $2;rech_list text;sql text;rec RECORD;BEGIN   rech_list := '';sql := 'SELECT '|| rech_type ||' as xx FROM rechnung W

Re: [SQL] plpgsql triggers in rules

2006-01-12 Thread Markus Schaber
Hi, Chester, chester c young wrote: > is is possible for to have a "do instead" trigger on a view that is a > plpgsql function? Kinda. They're called "rules", not "triggers". See http://www.postgresql.org/docs/8.1/interactive/rules.html HTH, Schabi -- Markus Schaber | Logical Tracking&Tracing

[SQL] plpgsql triggers in rules

2006-01-01 Thread chester c young
is is possible for to have a "do instead" trigger on a view that is a plpgsql function? __ Yahoo! DSL – Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com ---(end of broadcast)---

Re: [SQL] plpgsql function not accepting NULL value

2005-09-16 Thread Kenneth Dombrowski
On 9/16/05, Michael Fuhr <[EMAIL PROTECTED]> wrote: > On Fri, Sep 16, 2005 at 07:04:39PM -0400, Kenneth Dombrowski wrote: > > create or replace function update_rate (integer, integer, integer, > > integer, numeric, integer) > > You've created a function with six arguments. > > > invoicer=

Re: [SQL] plpgsql function not accepting NULL value

2005-09-16 Thread Michael Fuhr
On Fri, Sep 16, 2005 at 07:04:39PM -0400, Kenneth Dombrowski wrote: > create or replace function update_rate (integer, integer, integer, > integer, numeric, integer) You've created a function with six arguments. > invoicer=> select update_rate(1, 1, 10, NULL, numeric '90.00', 6, 216); > E

Re: [SQL] plpgsql function not accepting NULL value

2005-09-16 Thread Stephan Szabo
On Fri, 16 Sep 2005, Kenneth Dombrowski wrote: > I can't get this one to work at all: > > create or replace function update_rate (integer, integer, integer, > integer, numeric, integer) > returns void > as ' > declare > x_admin_id alias for $1; >

[SQL] plpgsql function not accepting NULL value

2005-09-16 Thread Kenneth Dombrowski
Hi, I'm using the postgresql 7.4.7-6sarge1 package from debian stable. I am confused about these two functions, and their behavior when being given NULL values in place of a parameter declared as integer: This one works as expected: create or replace function insert_rate (integer, integer, in

[SQL] plpgsql question

2005-08-30 Thread Postgres Admin
Can I do something like this: CREATE TABLE sample (id SERIAL, node INTEGER, parent INTEGER); INSERT INTO sample(node,parent) VALUES(1,0); INSERT INTO sample(node,parent) VALUES(2,0); INSERT INTO sample(node,parent) VALUES(3,1); INSERT INTO sample(node,parent) VALUES(4,3) CREATE OR REPLACE FUNCTIO

Re: [SQL] plpgsql dynamic record access

2005-06-08 Thread Rajesh Kumar Mallah
Ganesh, Did you have a look at example Example 35-2. A PL/pgSQL http://www.postgresql.org/docs/current/static/plpgsql-trigger.html Regds maLLAH ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] plpgsql and triggers

2005-06-05 Thread Michael Fuhr
On Thu, Jun 02, 2005 at 01:57:26PM +0200, Bart Degryse wrote: > > I'm looking for a way to use a parameter given to a trigger function as > fieldname. It should be something like > create function f_makeupper() returns trigger as ' > begin > NEW.TG_ARGV[0] := upper(NEW.TG_ARGV[0]); > RETURN

[SQL] plpgsql and triggers

2005-06-05 Thread Bart Degryse
I'm looking for a way to use a parameter given to a trigger function as fieldname. It should be something like create function f_makeupper() returns trigger as ' begin     NEW.TG_ARGV[0] := upper(NEW.TG_ARGV[0]);     RETURN NEW; end; ' language 'plpgsql'; create trigger "TRIG_tbltest" before inse

[SQL] plpgsql dynamic record access

2005-05-31 Thread Ganesh
Hello,    I have searched everywere  for a solution pls help me. I am building a trigger which would keep track of every modification to some table. here i am generlising the function. the following is the code in plpgsql.     --/* function for giving the field attributes of a given table */

Re: [SQL] plpgsql & date-time functions

2005-03-13 Thread Stephan Szabo
On Tue, 8 Mar 2005, Fatih Cerit wrote: > I have a function and I want to update a table's two rows but having problem > with plpgsql & date-time functions. First field of the table must be now() > this is ok.. but the second field must be now() + '60 days' if the query > like this : SELECT INTO to

[SQL] plpgsql & date-time functions

2005-03-13 Thread Fatih Cerit
I have a function and I want to update a table's two rows but having problem with plpgsql & date-time functions. First field of the table must be now() this is ok.. but the second field must be now() + '60 days' if the query like this : SELECT INTO to_day now() + interval '60 days' ; it works bu

Re: [SQL] plpgsql functions to 'C' functions

2005-02-03 Thread Peter Manchev
x27;C' functions :/ Here is where I'd like to get your expert opinions (thank you very much in advance for all your efforts), so I can get started fast. Thanks, Peter From: Michael Fuhr <[EMAIL PROTECTED]> To: Peter Manchev <[EMAIL PROTECTED]> CC: pgsql-sql@postgresql.org

Re: [SQL] plpgsql functions to 'C' functions

2005-02-03 Thread Michael Fuhr
On Thu, Feb 03, 2005 at 05:31:47AM -0800, Peter Manchev wrote: > I believe the functionality I need (hiding the function code from users) Why do you want to hide the function code? Does it contain sensitive data? As I asked before, what problem are you trying to solve? -- Michael Fuhr http:/

Re: [SQL] plpgsql functions to 'C' functions

2005-02-02 Thread Michael Fuhr
On Wed, Feb 02, 2005 at 05:57:10AM -0800, Peter Manchev wrote: > I would like to convert all my plpgsql functions to their 'C' equivalent > coded functions. Why? What problem are you trying to solve? > Does anyone have experience in this matter? See "C-Language Functions" in the documentation

[SQL] plpgsql functions to 'C' functions

2005-02-02 Thread Peter Manchev
I would like to convert all my plpgsql functions to their 'C' equivalent coded functions. Does anyone have experience in this matter? Thank you, Peter ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archive

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Tom Lane
Don Drake <[EMAIL PROTECTED]> writes: > On Mon, 31 Jan 2005 16:32:02 -0800 (PST), Stephan Szabo > <[EMAIL PROTECTED]> wrote: >> Actually, now that I think about it, I wonder if that's a good thing to >> use because I don't think that'll use indexes to do the search. You may >> want to do some test

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Don Drake
I'm constraining on other columns as well and it's still picking up the index. Thanks again. -Don On Mon, 31 Jan 2005 16:32:02 -0800 (PST), Stephan Szabo <[EMAIL PROTECTED]> wrote: > On Mon, 31 Jan 2005, Don Drake wrote: > > > You learn something new everyday. I've never seen that syntax befo

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Stephan Szabo
On Mon, 31 Jan 2005, Don Drake wrote: > You learn something new everyday. I've never seen that syntax before, > and it works like a charm!! Actually, now that I think about it, I wonder if that's a good thing to use because I don't think that'll use indexes to do the search. You may want to do

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Don Drake
You learn something new everyday. I've never seen that syntax before, and it works like a charm!! Thanks a ton. -Don On Mon, 31 Jan 2005 13:31:34 -0800 (PST), Stephan Szabo <[EMAIL PROTECTED]> wrote: > > On Sun, 30 Jan 2005, Don Drake wrote: > > > OK, I have a function that finds records tha

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Stephan Szabo
On Sun, 30 Jan 2005, Don Drake wrote: > OK, I have a function that finds records that changed in a set of > tables and attempts to insert them into a data warehouse. > > There's a large outer loop of candidate rows and I inspect them to see > if the values really changed before inserting. > > My

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Thomas F . O'Connell
As far as I know, you didn't post your actual table definitions (or full queries) earlier, so I'm not exactly sure what you mean. -tfo -- Thomas F. O'Connell Co-Founder, Information Architect Sitening, LLC http://www.sitening.com/ 110 30th Avenue North, Suite 6 Nashville, TN 37203-6320 615-260-00

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Don Drake
My outer query to get the candidates has an outer join, that works just fine and I get the null OMCR_ID's. It's when I have to query the dimension table (no joins) to see if a row exists with a (sometimes) null OMCR_ID I'm forced to write 2 queries, when I think I should only have to write one. T

Re: [SQL] plpgsql functions and NULLs

2005-01-31 Thread Thomas F . O'Connell
This sounds like a perfect candidate for a LEFT OUTER JOIN. See: http://www.postgresql.org/docs/7.4/static/queries-table- expressions.html#QUERIES-FROM Yours would looks something like: SELECT * FROM ... LEFT JOIN candidate AS c ON <...>.omcr_id = c.omcr_id AND ... -tfo -- Thomas F. O'Connell Co-

[SQL] plpgsql functions and NULLs

2005-01-30 Thread Don Drake
OK, I have a function that finds records that changed in a set of tables and attempts to insert them into a data warehouse. There's a large outer loop of candidate rows and I inspect them to see if the values really changed before inserting. My problem is that when I look to see if the row exists

Re: [SQL] plpgsql select into with multiple target variables

2005-01-28 Thread PFC
Try removing the comma after varz SELECT into varx, vary, varz, colx, coly, colz, FROM I've tried parens and various other things but no luck. John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL ---(end of broadcast)--- TI

[SQL] plpgsql select into with multiple target variables

2005-01-28 Thread John DeSoi
The docs say: The result of a SELECT command yielding multiple columns (but only one row) can be assigned to a record variable, row-type variable, or list of scalar variables. This is done by: SELECT INTO target select_expressions FROM ...; where target can be a record variable, a row variab

Re: [SQL] plpgsql and for with integer loopvar error

2005-01-17 Thread Stephan Szabo
On Sat, 15 Jan 2005, Ari Kahn wrote: > CREATE FUNCTION gets_nooky() returns numeric AS > ' > DECLARE > i integer; > gt1cnt record; > gt1 record; > cluster record; > cluster_cnt integer; > slocus integer; > minmax record; > > BEGIN > SELECT INTO gt1 * FROM c

[SQL] plpgsql and for with integer loopvar error

2005-01-17 Thread Ari Kahn
I have a single column result that I want to loop through using an index. I also want to jump ahead in the result using the index (below: i:=i+cluster_cnt-1;) . However, I'm getting the following error. ERROR: syntax error at or near "SELECT" at character 9 CONTEXT: PL/pgSQL function "gets_noo

Re: [SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Christopher Browne
Oops! [EMAIL PROTECTED] ("Yudie") was seen spray-painting on a wall: > How in plpgsql use LIKE with a variable? > > let say I want to do this query: > SELECT INTO RS id FROM customer WHERE firstname LIKE keyword% LIMIT 1; > > keyword is a variable, in this case I want to find name like 'Jo%' >

Re: [SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Christopher Browne
Try: SELECT INTO RS ID FROM CUSTOMER WHERE FIRSTNAME LIKE KEYWORD || ''%'' LIMIT 1; You append KEYWORD and a '%' together using ||. You need to use doubled quotes inside the quoted environment; one gets stripped off so that the stored procedure will contain the query SELECT INTO RS ID FRO

Re: [SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Michael Fuhr
On Thu, Dec 16, 2004 at 05:53:43PM -0600, Yudie wrote: > How in plpgsql use LIKE with a variable? > > let say I want to do this query: > > SELECT INTO RS id FROM customer WHERE firstname LIKE keyword% LIMIT 1; > > keyword is a variable, in this case I want to find name like 'Jo%' Use the

[SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Yudie
How in plpgsql use LIKE with a variable?   let say I want to do this query:   SELECT INTO RS id FROM customer WHERE firstname LIKE keyword% LIMIT 1;   keyword is a variable, in this case I want to find name like 'Jo%'     Full functio

Re: [SQL] plpgsql: PERFORM vs. SELECT INTO (PERFORM not setting FOUND variable?)

2004-10-25 Thread Tom Lane
Marinos Yannikos <[EMAIL PROTECTED]> writes: > create function blup_unique2 (text,text) returns boolean as 'begin > perform (select 1 from blup where t1=$1 or t1=$2 or t2=$1 or t2=$2 or > $1=$2 limit 1); return NOT FOUND; end' LANGUAGE plpgsql; You've got a syntax problem. PERFORM is syntactica

Re: [SQL] plpgsql: PERFORM vs. SELECT INTO (PERFORM not setting FOUND

2004-10-25 Thread Edmund Bacon
Marinos Yannikos wrote: (btw.: I'm trying a few ways to ensure that all values in both t1 and t2 are unique: alter table blup add constraint check (blup_unique3(t1,t2)); - perhaps there are more elegant ways, any suggestions?) No doubt someone will tell me this is Very Wrong: create table blup_t

  1   2   3   >