Re: [GENERAL] plpgsql question: select into multiple variables ?

2015-06-30 Thread Day, David
problem was in casts that I was using were confusing the parser and were un-necessary. Appreciate your thought and effort. Regards Dave From: Yasin Sari [mailto:yasinsar...@googlemail.com] Sent: Tuesday, June 30, 2015 3:26 AM To: Day, David Subject: Re: [GENERAL] plpgsql question: select

[GENERAL] plpgsql question: select into multiple variables ?

2015-06-29 Thread Day, David
Hi, Postgres version 9.3.9 What is wrong with my usage of the plpgsql select into concept I have a function to look into a calendar table to find the first and Last weekend date of a month. In this simplified concept function I end up with a NULL for first or last weekend variable.

Re: [GENERAL] plpgsql question: select into multiple variables ?

2015-06-29 Thread Day, David
-Original Message- From: Adrian Klaver [mailto:adrian.kla...@aklaver.com] Sent: Monday, June 29, 2015 4:03 PM To: Day, David; pgsql-general@postgresql.org Subject: Re: [GENERAL] plpgsql question: select into multiple variables ? On 06/29/2015 12:07 PM, Day, David wrote: Hi

Re: [GENERAL] plpgsql question: select into multiple variables ?

2015-06-29 Thread David G. Johnston
On Mon, Jun 29, 2015 at 4:27 PM, Tom Lane t...@sss.pgh.pa.us wrote: Adrian Klaver adrian.kla...@aklaver.com writes: On 06/29/2015 12:07 PM, Day, David wrote: What is wrong with my usage of the plpgsql select into concept I have a function to look into a calendar table to find the first

Re: [GENERAL] plpgsql question: select into multiple variables ?

2015-06-29 Thread Tom Lane
Adrian Klaver adrian.kla...@aklaver.com writes: On 06/29/2015 12:07 PM, Day, David wrote: What is wrong with my usage of the plpgsql select into concept I have a function to look into a calendar table to find the first and Last weekend date of a month. create or replace function

Re: [GENERAL] plpgsql question: select into multiple variables ?

2015-06-29 Thread Tom Lane
David G. Johnston david.g.johns...@gmail.com writes: On Mon, Jun 29, 2015 at 4:27 PM, Tom Lane t...@sss.pgh.pa.us wrote: ... So what you wrote here is equivalent to SELECT MIN(CAL_DATE),MAX(CAL_DATE) ::date, last_weekend::date INTO first_weekend FROM sys.calendar ... ​Does it help to

Re: [GENERAL] plpgsql question: select into multiple variables ?

2015-06-29 Thread Adrian Klaver
On 06/29/2015 12:07 PM, Day, David wrote: Hi, Postgres version 9.3.9 What is wrong with my usage of the plpgsql select into concept I have a function to look into a calendar table to find the first and Last weekend date of a month. In this simplified concept function I end up with a NULL

[GENERAL] plpgsql question

2011-12-05 Thread Gauthier, Dave
v8.3.4 on linux Is there a way to set the query used in a for rec in (query) loop - end loop be a variable? Example if (foo = 'whatever') then sqlstmt := select x,y,z ...; else sqlstmt := select a,b,c ...; end if ; for therec in sqlstmt loop ... end loop; Thanks in Advance for any

Re: [GENERAL] plpgsql question

2011-12-05 Thread Adrian Klaver
On Monday, December 05, 2011 6:59:32 am Gauthier, Dave wrote: v8.3.4 on linux Is there a way to set the query used in a for rec in (query) loop - end loop be a variable? Example if (foo = 'whatever') then sqlstmt := select x,y,z ...; else sqlstmt := select a,b,c ...; end if ;

[GENERAL] plpgsql question

2010-08-27 Thread Jon Griffin
I am trying to calculate a value from a current record in a query and can't seem to get it working. Here is the shortened query; SELECT s.id, r.the_date_time, s.open_price, s.high_price, s.low_price, s.close_price, thesheet_onepair.symbol,

Re: [GENERAL] plpgsql question

2010-08-27 Thread Pavel Stehule
Hello you used a wrong syntax see http://www.pgsql.cz/index.php/PL/pgSQL_%28en%29#Usage_PL.2FpgSQL_function_with_parametres_of_type_table Regards Pavel Stehule 2010/8/28 Jon Griffin j...@jongriffin.com:  I am trying to calculate a value from a current record in a query and can't seem to

Re: [GENERAL] plpgsql question

2006-01-09 Thread Matthew Peter
snip WHERE my_tbl_id = $1AND CASE WHEN $2 IS NULL THEN TRUE ELSE $2 = username ENDor WHERE my_tbl_id = $1 AND COALESCE($2 = username, TRUE)or WHERE my_tbl_id = $1 AND COALESCE($2, username) = usernameWith predicates such as these you wouldn't need to use EXECUTE andyou could write the query

Re: [GENERAL] plpgsql question

2006-01-09 Thread Michael Fuhr
On Mon, Jan 09, 2006 at 01:01:33PM -0800, Matthew Peter wrote: One other quick question, (figure it still applies to the subject line :) when returning a row from a function I'm trying to include an aggregate, but it's not showing up in the query result and I think it's because it's not

Re: [GENERAL] plpgsql question

2006-01-09 Thread Matthew Peter
Terminology point: you used the word "aggregate" but the function below doesn't have an aggregate. Aggregates are functions thatoperate on multiple rows, like count() and sum(); substr() doesn'tdo that so it's not an aggregate. ya. my mistake.[snip] 1. Create a composite type with

Re: [GENERAL] plpgsql question

2006-01-06 Thread Matthew Peter
Michael Fuhr [EMAIL PROTECTED] wrote: On Thu, Jan 05, 2006 at 12:50:34AM -0800, Matthew Peter wrote: Is it possible to skip the loop and just return all records in a single query and shove all those rows into a table variable?Not in PL/pgSQL -- you need to return each row with RETURN

Re: [GENERAL] plpgsql question

2006-01-06 Thread Michael Fuhr
On Fri, Jan 06, 2006 at 01:14:38AM -0800, Matthew Peter wrote: Michael Fuhr [EMAIL PROTECTED] wrote: On Thu, Jan 05, 2006 at 12:50:34AM -0800, Matthew Peter wrote: Is it possible to skip the loop and just return all records in a single query and shove all those rows into a table variable?

Re: [GENERAL] plpgsql question

2006-01-06 Thread Matthew Peter
Michael Fuhr [EMAIL PROTECTED] wrote: On Fri, Jan 06, 2006 at 01:14:38AM -0800, Matthew Peter wrote: Michael Fuhr wrote: On Thu, Jan 05, 2006 at 12:50:34AM -0800, Matthew Peter wrote: Is it possible to skip the loop and just return all records in a single query and shove all those rows into

Re: [GENERAL] plpgsql question

2006-01-05 Thread Matthew Peter
On 1/5/06, Matthew Peter wrote: I'm trying to do a simple SELECT * in plpgsql that returns a set of records as a row w/ columns, not a row into a variable, w/ some conditionals. The function below is semi-pseudo with what I'm trying to... If anyone could give me an example that works

Re: [GENERAL] plpgsql question

2006-01-05 Thread Michael Fuhr
On Thu, Jan 05, 2006 at 12:50:34AM -0800, Matthew Peter wrote: Is it possible to skip the loop and just return all records in a single query and shove all those rows into a table variable? Not in PL/pgSQL -- you need to return each row with RETURN NEXT, generally from within a loop. Why do you

[GENERAL] plpgsql question

2006-01-04 Thread Matthew Peter
I'm trying to do a simple SELECT * in plpgsql that returns a set of records as a row w/ columns, not a row into a variable, w/ some conditionals. The function below is semi-pseudo with what I'm trying to... If anyone could give me an example that works by returning it as a resultset

Re: [GENERAL] plpgsql question

2006-01-04 Thread Pandurangan R S
Assuming records is the name of a table... create or replace function getrecord(int,text) RETURNS SETOF records as $$ DECLARE row records%rowtype; BEGIN FOR row IN SELECT * FROM my_tbl WHERE ... LOOP RETURN NEXT row; END LOOP; RETURN; END; $$ LANGUAGE plpgsql; On 1/5/06, Matthew Peter [EMAIL

[GENERAL] plpgsql question

2003-11-25 Thread Brian Hirt
I'm looking to find out how many rows were effected during an update in a trigger. I ran across this message by jan talking about this feature possibly being added to postgresql 6.5, but I can't find any reference to such a feature in the current documentation. Did this ever make it into

Re: [GENERAL] plpgsql question

2003-11-25 Thread Michael A Nachbaur
DECLARE RowsAffected INTEGER; BEGIN -- DO your statement GET DIAGNOSTICS RowsAffected = ROW_COUNT; END On Tuesday 25 November 2003 02:56 pm, Brian Hirt wrote: I'm looking to find out how many rows were effected during an update in a trigger. I ran across this message by jan talking about

Re: [GENERAL] plpgsql question...

2000-06-07 Thread Tom Lane
Steve Wampler [EMAIL PROTECTED] writes: PostgreSQL 6.5.3 appdb= create function insert_or_update() returns opaque as ' appdb' begin appdb' insert into attributes_table values(new.id,new.name, appdb'new.units,new.value); appdb' return NULL; appdb' end;'