pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
understanding select into
4+ messages / 3 participants
[nested] [flat]

* understanding select into
@ 2010-04-09 17:18  John <johnf@jfcomputer.com>
  0 siblings, 2 replies; 4+ messages in thread

From: John @ 2010-04-09 17:18 UTC (permalink / raw)
  To: pgsql-sql

Hi,
I am reviewing a function written by some xTuple guys.  What is interesting 
about it is it uses the "INTO" statement like

select something into _p from sometable where somecriteria.

The function contiunes and uses the data retreived 
_p.somefield_name

And then the function ends.


Ok my question:

I also thought the select "into" created a real table.  But after running the 
function the table does not exist.  I see no where that a 'drop' is issued.  
In fact the function uses lot's of select into's like (_test, _r, etc..).  So 
would some kind soul explain what is happening.

Could it be that "_p" is drop automaticly when the function ends?  Something 
to do with scope.

Could it have something to do with the fact the function returns only an 
integer?  And that causes the table to be drop.

As you can see I'm lost here!


Johnf



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: understanding select into
@ 2010-04-09 17:31  Plugge, Joe R. <JRPlugge@west.com>
  parent: John <johnf@jfcomputer.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Plugge, Joe R. @ 2010-04-09 17:31 UTC (permalink / raw)
  To: John <johnf@jfcomputer.com>; pgsql-sql

Johnf,



I would think that the _p, _test, _r etc are local variables within the procedure/function and this is the way that the value (from the select)  gets assigned to that local variable.



-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of John
Sent: Friday, April 09, 2010 12:19 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] understanding select into



Hi,

I am reviewing a function written by some xTuple guys.  What is interesting

about it is it uses the "INTO" statement like



select something into _p from sometable where somecriteria.



The function contiunes and uses the data retreived

_p.somefield_name



And then the function ends.





Ok my question:



I also thought the select "into" created a real table.  But after running the

function the table does not exist.  I see no where that a 'drop' is issued.

In fact the function uses lot's of select into's like (_test, _r, etc..).  So

would some kind soul explain what is happening.



Could it be that "_p" is drop automaticly when the function ends?  Something

to do with scope.



Could it have something to do with the fact the function returns only an

integer?  And that causes the table to be drop.



As you can see I'm lost here!





Johnf



--

Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)

To make changes to your subscription:

http://www.postgresql.org/mailpref/pgsql-sql

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: understanding select into
@ 2010-04-09 17:32  Pavel Stehule <pavel.stehule@gmail.com>
  parent: John <johnf@jfcomputer.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Pavel Stehule @ 2010-04-09 17:32 UTC (permalink / raw)
  To: John <johnf@jfcomputer.com>; +Cc: pgsql-sql

Hello

2010/4/9 John <johnf@jfcomputer.com>:
> Hi,
> I am reviewing a function written by some xTuple guys.  What is interesting
> about it is it uses the "INTO" statement like
>
> select something into _p from sometable where somecriteria.
>
> The function contiunes and uses the data retreived
> _p.somefield_name
>
> And then the function ends.
>
>
> Ok my question:
>
> I also thought the select "into" created a real table.  But after running the
> function the table does not exist.  I see no where that a 'drop' is issued.
> In fact the function uses lot's of select into's like (_test, _r, etc..).  So
> would some kind soul explain what is happening.
>

_p is record variable. See some lines before. There will be DECLARE part

DECLARE p RECORD;

There is plpgsql's SELECT INTO and SQL's SELECT INTO with little bit
different syntax. First - target is list of variables or record
variable, second - target is table.

> Could it be that "_p" is drop automaticly when the function ends?  Something
> to do with scope.
>

_p is just variable

regards
Pavel Stehule

> Could it have something to do with the fact the function returns only an
> integer?  And that causes the table to be drop.
>
> As you can see I'm lost here!
>
>
> Johnf
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: understanding select into
@ 2010-04-09 17:53  John <johnf@jfcomputer.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: John @ 2010-04-09 17:53 UTC (permalink / raw)
  To: pgsql-sql

Wow thanks to all that replied - you folks are correct.  The "_p" and the 
others are vars.
_p RECORD;

I won't forget that one for a long time (however, I do drink :-))

Johnf
On Friday 09 April 2010 10:32:51 am Pavel Stehule wrote:
> Hello
>
> 2010/4/9 John <johnf@jfcomputer.com>:
> > Hi,
> > I am reviewing a function written by some xTuple guys.  What is
> > interesting about it is it uses the "INTO" statement like
> >
> > select something into _p from sometable where somecriteria.
> >
> > The function contiunes and uses the data retreived
> > _p.somefield_name
> >
> > And then the function ends.
> >
> >
> > Ok my question:
> >
> > I also thought the select "into" created a real table.  But after running
> > the function the table does not exist.  I see no where that a 'drop' is
> > issued. In fact the function uses lot's of select into's like (_test, _r,
> > etc..).  So would some kind soul explain what is happening.
>
> _p is record variable. See some lines before. There will be DECLARE part
>
> DECLARE p RECORD;
>
> There is plpgsql's SELECT INTO and SQL's SELECT INTO with little bit
> different syntax. First - target is list of variables or record
> variable, second - target is table.
>
> > Could it be that "_p" is drop automaticly when the function ends?
> >  Something to do with scope.
>
> _p is just variable
>
> regards
> Pavel Stehule
>
> > Could it have something to do with the fact the function returns only an
> > integer?  And that causes the table to be drop.
> >
> > As you can see I'm lost here!
> >
> >
> > Johnf





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2010-04-09 17:53 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-04-09 17:18 understanding select into John <johnf@jfcomputer.com>
2010-04-09 17:31 ` Plugge, Joe R. <JRPlugge@west.com>
2010-04-09 17:32 ` Pavel Stehule <pavel.stehule@gmail.com>
2010-04-09 17:53   ` John <johnf@jfcomputer.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox