Re: [SQL] pivot query with count

2013-04-13 Thread Tony Capobianco
Thank you very much for your response. However, I'm unclear what you want me to substitute for sum(...)? select '1' as "num_ads", sum(...) from (select a.userid from user_event_stg2 a, user_region b where a.userid = b.userid and b.region_code = 1000 and a.messagetype = 'impression' group by a.user

[SQL] pivot query with count

2013-04-12 Thread Tony Capobianco
The following is my code and results: select '1' "num_ads", (case when r.region_code = 1000 then ( select count(*) from ( select userid from user_event_stg2 where userid in ( select userid from user_region where region_code = 1000) and messagetyp

[SQL] pivot query with count

2013-04-12 Thread Tony Capobianco
The following is my code and results: select '1' "num_ads", (case when r.region_code = 1000 then ( select count(*) from ( select userid from user_event_stg2 where userid in ( select userid from user_region where region_code = 1000) and messagetyp

Re: [SQL] compare table names

2012-01-11 Thread Tony Capobianco
VALUES (now(), ...) > > and, for the select, you could simply write : > > SELECT * FROM tablename WHERE insertion_time >= (now() - interval '1 > day') > > > > 2012/1/9 Adrian Klaver > On Monday, January 09, 2012 8:28:43 am Tony Capobianco

Re: [SQL] compare table names

2012-01-09 Thread Tony Capobianco
On Mon, 2012-01-09 at 08:19 -0800, Adrian Klaver wrote: > On Monday, January 09, 2012 8:12:18 am Tony Capobianco wrote: > > I have these 3 tables: > > > > tablename > > > > tmp_staging0109 > > tmp_staging1229 > > tmp_staging

[SQL] compare table names

2012-01-09 Thread Tony Capobianco
I have these 3 tables: tablename tmp_staging0109 tmp_staging1229 tmp_staging0108 I'd like this query: select tablename from pg_tables where tablename like 'tmp_staging%' and tablename < 'tmp_staging1230'; To return this result: tablename

Re: [SQL] Add one column to another

2011-08-25 Thread Tony Capobianco
Use the concat || operator. On Thu, 2011-08-25 at 15:21 +0100, gvim wrote: > I have to deal with a table which contains: > > first_name > surname > email1 > email2 > > ... and I would like to create a view which combines both email columns thus: > > first_name > surname > email > > It looks s

Re: [SQL] replace " with nothing

2011-05-11 Thread Tony Capobianco
Ok, I think I found it: select translate(firstname,'"','') from members; gives me what I want. Thanks. On Wed, 2011-05-11 at 16:29 -0400, Tony Capobianco wrote: > We are converting from Oracle to Postgres. An Oracle script contains > this line: > > se

[SQL] replace " with nothing

2011-05-11 Thread Tony Capobianco
We are converting from Oracle to Postgres. An Oracle script contains this line: select replace(firstname,'"'), memberid, emailaddress from members; in an effort to replace the " with nothing. How can I achieve the same result with Postgres? Here's the Postgres error I get: select replace(fir

Re: [SQL] Determine length of numeric field

2011-02-15 Thread Tony Capobianco
Tom, That's a frighteningly easy solution. Thanks. Tony On Tue, 2011-02-15 at 16:10 -0500, Tom Lane wrote: > Tony Capobianco writes: > > I'm altering datatypes in several tables from numeric to integer. In > > doing so, I get the following error: > > &g

Re: [SQL] Determine length of numeric field

2011-02-15 Thread Tony Capobianco
Pavel, That's perfect! Thanks. Tony On Tue, 2011-02-15 at 22:04 +0100, Pavel Stehule wrote: > Hello > > probably you have to use a explicit cast > > postgres=# select length(10::numeric::text); > length > > 2 > (1 row) > > Regards

[SQL] Determine length of numeric field

2011-02-15 Thread Tony Capobianco
I'm altering datatypes in several tables from numeric to integer. In doing so, I get the following error: dw=# \d uniq_hits Table "support.uniq_hits" Column | Type | Modifiers +-+--- sourceid | numeric | hitdate| date| total | numeric |

[SQL] create role

2010-12-30 Thread Tony Capobianco
Hi, I'm successfully executing the below: create role developer login; alter role developer set default_tablespace=dev; alter role developer set search_path=dev,staging, esave, support, email, public; grant select on members to developer; grant create on schema dev to developer; However, when I

[SQL] concatenate question

2010-12-11 Thread Tony Capobianco
Here's my table: plsql_dw=# \d tmpsv_parent_master Table "staging.tmpsv_parent_master" Column |Type | Modifiers +-+--- memberid | numeric | addeddate | timestamp witho

[SQL] sqlplus reporting equivalent in postgres?

2010-12-09 Thread Tony Capobianco
We're in the process of porting our Oracle 10.2 datawarehouse over to PostGres 8.4. One thing we rely upon are daily/hourly reports that are run and formatted in sqlplus (break on report, compute sum, etc.). Is there an equivalent available in postgres? Thanks. Tony -- Sent via pgsql-sql mail

Re: [SQL] concatenate question

2010-12-08 Thread Tony Capobianco
r wrote: > I don't know what Postgres version you're using but check out the doc > related to String Functions and Operators. > Cheers, >Peter > > > On Tue, Dec 7, 2010 at 4:47 PM, Tony Capobianco > wrote: > Ok, that worked. Why did I need to cast

Re: [SQL] concatenate question

2010-12-07 Thread Tony Capobianco
4005943492010-11-16 19:35:22 4005943662010-11-16 19:35:37 (5 rows) Thanks. On Tue, 2010-12-07 at 16:43 -0500, Peter Steinheuser wrote: > I think the HINT is what you need to look at. > > Cast both columns to text. > > On Tue, Dec 7, 2010 at 4:37 PM, Tony Capobianco > wrote

[SQL] concatenate question

2010-12-07 Thread Tony Capobianco
Here's my table: plsql_dw=# \d tmpsv_parent_master Table "staging.tmpsv_parent_master" Column |Type | Modifiers +-+--- memberid | numeric