pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUsing variables in select
2+ messages / 2 participants
[nested] [flat]
* Using variables in select
@ 2011-08-12 11:05 tlund79 <thomas.lund@eniro.no>
2011-08-12 16:03 ` Re: Using variables in select Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
0 siblings, 1 reply; 2+ messages in thread
From: tlund79 @ 2011-08-12 11:05 UTC (permalink / raw)
To: pgsql-sql
Hi,
Firstly; I'm not a developer, but a business developer and statistics guy.
This means that I'm happy using "basic" selects to gather information for
analysis.
One thing that could really efficiate my work is using variables, let's say
I have a table with different orders;
|customer_id|productid|price|
What I really want is to create a general query where I could easily
substitute productid.
//
declare variable --> productid = 10
select count(distinct customer_id), avg(price) from customer_table where
productid=<insert variable>
\\
Is there a way of doing this without getting involved with heavy
programming?
Thank you and applogies if this is a ridicioulus question!
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Using-variables-in-select-tp4692865p4692865.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Using variables in select
2011-08-12 11:05 Using variables in select tlund79 <thomas.lund@eniro.no>
@ 2011-08-12 16:03 ` Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
0 siblings, 0 replies; 2+ messages in thread
From: Oliveiros d'Azevedo Cristina @ 2011-08-12 16:03 UTC (permalink / raw)
To: tlund79 <thomas.lund@eniro.no>; pgsql-sql
How do you access your database?
Through some client application like psql ? Through some other mean?
The query you included is the query you wanna perform against ur table?
Or was it just an example?
Do you wanna avoid having to write the complete query on the command line?
If so, you sound like you need a function
something
like
CREATE FUNCTION customer_table(int) RETURNS customer_table
AS $$ SELECT COUNT(DISTINCT costumer_id),AVG(price) FROM customer_table
WHERE productid = $1 $$
LANGUAGE SQL;
HTH
Best,
Oliveiros
----- Original Message -----
From: "tlund79" <thomas.lund@eniro.no>
To: <pgsql-sql@postgresql.org>
Sent: Friday, August 12, 2011 12:05 PM
Subject: [SQL] Using variables in select
> Hi,
>
> Firstly; I'm not a developer, but a business developer and statistics guy.
> This means that I'm happy using "basic" selects to gather information for
> analysis.
>
> One thing that could really efficiate my work is using variables, let's
> say
> I have a table with different orders;
>
> |customer_id|productid|price|
>
> What I really want is to create a general query where I could easily
> substitute productid.
>
> //
>
> declare variable --> productid = 10
>
> select count(distinct customer_id), avg(price) from customer_table where
> productid=<insert variable>
>
> \\
>
> Is there a way of doing this without getting involved with heavy
> programming?
>
>
>
> Thank you and applogies if this is a ridicioulus question!
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/Using-variables-in-select-tp4692865p4692865.html
> Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
>
> --
> 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] 2+ messages in thread
end of thread, other threads:[~2011-08-12 16:03 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-12 11:05 Using variables in select tlund79 <thomas.lund@eniro.no>
2011-08-12 16:03 ` Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
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