Search Postgresql Archives

Re: Insert Data Into Tables Linked by Foreign Key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From general point of view, having 3 SQL statement wrapped in a single stored procedure shall perform better due to reduced overhead to communicate with SQL server. Is that true? Or that is my false assumption?

Thanks and Regards
Yan Cheng CHEOK


--- On Mon, 1/4/10, Alban Hertroys <dalroi@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> From: Alban Hertroys <dalroi@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
> Subject: Re:  Insert Data Into Tables Linked by Foreign Key
> To: "Yan Cheng Cheok" <yccheok@xxxxxxxxx>
> Cc: pgsql-general@xxxxxxxxxxxxxx
> Date: Monday, January 4, 2010, 7:57 PM
> On 4 Jan 2010, at 9:53, Yan Cheng
> Cheok wrote:
> 
> > For example, "John" place "1.34" priced order.
> > 
> > (1) Get Customer_ID from Customer table, where name is
> "John"
> > (2) If there are no Customer_ID returned (There is no
> John), insert "John"
> > (3) Get Customer_ID from Customer table, where name is
> "John"
> > (4) Insert "Customer_ID" and "1.34" into Order table.
> > 
> > There are 4 SQL communication with database involved
> for this simple operation!!!
> > 
> > Is there any better way, which can be achievable using
> 1 SQL statement?
> 
> 
> You don't need the 3rd statement if you use INSERT ..
> RETURNING at step 2.
> 
> The one way you could achieve this by calling only one
> statement that I can think of is to wrap this in a stored
> procedure. Plain SQL doesn't provide any means to do what
> you want.
> 
> Alban Hertroys
> 
> --
> Screwing up is the best way to attach something to the
> ceiling.
> 
> 
> !DSPAM:737,4b41d7ac9957514533904!
> 
> 
> 
> -- 
> Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
> 


      


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux