Unix Technical Forum

Query Formulation Question

This is a discussion on Query Formulation Question within the pgsql Novice forums, part of the PostgreSQL category; --> consider the following simplified queries (php using heredoc): $sql_1 = <<<_EOSQL select count(inspect) from t_inspect, t_product, t_test_area where t_product.product_num ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:52 PM
operationsengineer1@yahoo.com
 
Posts: n/a
Default Query Formulation Question

consider the following simplified queries (php using
heredoc):

$sql_1 = <<<_EOSQL

select count(inspect)
from t_inspect, t_product, t_test_area
where t_product.product_num = 1
and t_test_area.id = 5

_EOSQL

$sql_2 = <<<_EOSQL

select count(inspect)
from t_inspect, t_product, t_test_area
where t_product.product_num = 1

_EOSQL

what is the best way to handle both of these cases in
one statement?

i know it would take the form of $sql_1, but what
value should i feed to t_test_area.id? is there
syntax that will just ignore it or do i need to send a
value of 'NOT NULL'? will NOT NULL slow down the
query when compared to $sql_2?

am i missing a better way to structure these queries?

as always, tia...

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

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

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:52 PM
Sean Davis
 
Posts: n/a
Default Re: Query Formulation Question

operationsengineer1@yahoo.com wrote:
> consider the following simplified queries (php using
> heredoc):
>
> $sql_1 = <<<_EOSQL
>
> select count(inspect)
> from t_inspect, t_product, t_test_area
> where t_product.product_num = 1
> and t_test_area.id = 5
>
> _EOSQL
>
> $sql_2 = <<<_EOSQL
>
> select count(inspect)
> from t_inspect, t_product, t_test_area
> where t_product.product_num = 1
>
> _EOSQL
>
> what is the best way to handle both of these cases in
> one statement?


You are using a programming language--why not construct the query on the
fly? Why the requirement to use the heredoc for the entire query string?

Sean

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 10:52 PM
operationsengineer1@yahoo.com
 
Posts: n/a
Default Re: Query Formulation Question

> operationsengineer1@yahoo.com wrote:
> > consider the following simplified queries (php

> using
> > heredoc):
> >
> > $sql_1 = <<<_EOSQL
> >
> > select count(inspect)
> > from t_inspect, t_product, t_test_area
> > where t_product.product_num = 1
> > and t_test_area.id = 5
> >
> > _EOSQL
> >
> > $sql_2 = <<<_EOSQL
> >
> > select count(inspect)
> > from t_inspect, t_product, t_test_area
> > where t_product.product_num = 1
> >
> > _EOSQL
> >
> > what is the best way to handle both of these cases

> in
> > one statement?

>
> You are using a programming language--why not
> construct the query on the
> fly?


the simple answer is i don't know how. btw, that's
the complex answer, too. ;-) can you share a quick
example?

> Why the requirement to use the heredoc for the
> entire query string?


that's not a requirement. i like the heredoc format
for readability and ease of c&p to pgadmin3's query
executer. however, i'm not married to it and will use
another option when i have a good reason.

based on your comments, i could use a heredoc for the
base query and then check to see if i need to
concatenate the where statement to it. i think that
will work.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

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

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 10:52 PM
Sean Davis
 
Posts: n/a
Default Re: Query Formulation Question

operationsengineer1@yahoo.com wrote:
>>operationsengineer1@yahoo.com wrote:
>>
>>>consider the following simplified queries (php

>>
>>using
>>
>>>heredoc):
>>>
>>>$sql_1 = <<<_EOSQL
>>>
>>>select count(inspect)
>>>from t_inspect, t_product, t_test_area
>>>where t_product.product_num = 1
>>>and t_test_area.id = 5
>>>
>>>_EOSQL
>>>
>>>$sql_2 = <<<_EOSQL
>>>
>>>select count(inspect)
>>>from t_inspect, t_product, t_test_area
>>>where t_product.product_num = 1
>>>
>>>_EOSQL
>>>
>>>what is the best way to handle both of these cases

>>
>>in
>>
>>>one statement?

>>
>>You are using a programming language--why not
>>construct the query on the
>>fly?

>
>
> the simple answer is i don't know how. btw, that's
> the complex answer, too. ;-) can you share a quick
> example?
>
>
>>Why the requirement to use the heredoc for the
>>entire query string?

>
>
> that's not a requirement. i like the heredoc format
> for readability and ease of c&p to pgadmin3's query
> executer. however, i'm not married to it and will use
> another option when i have a good reason.
>
> based on your comments, i could use a heredoc for the
> base query and then check to see if i need to
> concatenate the where statement to it. i think that
> will work.


That sounds reasonable. You might look at a database abstraction layer.
I'm not sure what is available for php, though.

Sean

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:51 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com