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
r all your responses. Tony On Wed, 2012-01-11 at 07:43 +0100, Brice André wrote: > Just my 2 cents... > > Why don't you use a date column type instead of a string ? In this > case, at insertion, you could simply do this : > > INERT INTO tablename (insertion_time, ...)

Re: [SQL] compare table names

2012-01-09 Thread Tony Capobianco
larger script where I want to dynamically select tablenames older than 10 days and drop them. The tables are created in a tmp_stagingMMDD format. I know postgres does not maintain object create times, how can I write this to select tables from pg_tables that are older than 10 days? Thanks. Tony

[SQL] compare table names

2012-01-09 Thread Tony Capobianco
this result: tablename tmp_staging1229 However, I'm receiving: tablename tmp_staging0109 tmp_staging1229 tmp_staging0108 How can I write this correctly? Thanks. Tony -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To

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
than 5 digits long. I'm able to perform this query on Oracle and would like something similar on postgres 8.4: delete from uniq_hits where sourceid in (select sourceid from uniq_hits where length(sourceid) > 5); I haven't had much luck with the length or char_length functions on pos

[SQL] create role

2010-12-30 Thread Tony Capobianco
|Type | Modifiers -+-+--- memberid| numeric | not null etc How can I get this so I don't have to preface the \d with the schema name every time? Thanks. Tony -- Sent via pgsql-sql mailing list (

[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 pgsq

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

Re: [SQL] Avoiding cycles in a directed graph

2010-03-17 Thread Tony Cebzanov
27;m sticking with the recursive query, because it seems to me the only way to ensure there are no cycles is to check the whole graph for cycles, and the only way I know how to do that is the recursive approach. Since "FOR UPDATE" isn't implemented for recursive queries, I'll ju

Re: [SQL] Avoiding cycles in a directed graph

2010-03-16 Thread Tony Cebzanov
On 3/16/10 4:34 PM, Tom Lane wrote: > The same kind of problem exists for unique and foreign key constraints, > both of which use low-level locking mechanisms to catch such cases. > There's no way that I can see to express the "no cycle" constraint as a > uniqueness constraint unfortunately. You c

[SQL] Avoiding cycles in a directed graph

2010-03-16 Thread Tony Cebzanov
having the non-recursive SELECT use NEW.parent, NEW.child, etc. but that isn't working. Is there any way to do this, or do I have to just insert the edge, check if it cycles, and delete it if it does? Thanks. -Tony -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make chan

Re: [SQL] Remote monitoring of Postgres w/minimal grants

2010-03-11 Thread Tony Wasson
like you could get around most of these cases by making a function or set returning function to return the data and making it "security definer" and then grant your monitoring user access to that. Tony

Re: [SQL] Performance problem with row count trigger

2009-04-03 Thread Tony Cebzanov
Greg Sabino Mullane wrote: > A few things spring to mind: > > 1) Use a separate table, rather than storing things inside of > dataset itself. This will reduce the activity on the dataset table. A separate table just for that one column? Would that really help, given that I'd have to add the fore

Re: [SQL] Performance problem with row count trigger

2009-04-02 Thread Tony Cebzanov
Hi Craig, thanks for your help. Craig Ringer wrote: > MVCC bloat from the constant updates to the assoc_count table, maybe? That's what a coworker suggested might be happening. The fact that a no-op trigger performs fine but the UPDATE trigger doesn't would seem to confirm that it's something in

[SQL] Performance problem with row count trigger

2009-04-02 Thread Tony Cebzanov
inconsistencies if another client does inserts without updating the count. I would really prefer to use the trigger solution recommended on the PGsql wiki, but can't do so until I solve this performance problem. I greatly appreciate any and all help. Thanks. -Tony -- Sent v

Re: [SQL] grouping/clustering query

2008-10-24 Thread Tony Wasson
On Fri, Oct 24, 2008 at 10:24 AM, Tony Wasson <[EMAIL PROTECTED]> wrote: > On Fri, Oct 24, 2008 at 8:04 AM, Steve Midgley <[EMAIL PROTECTED]> wrote: >> At 11:28 AM 10/23/2008, Joe wrote: >>> >>> Steve Midgley wrote: >>>>> >>>>> #

Re: [SQL] grouping/clustering query

2008-10-24 Thread Tony Wasson
On Fri, Oct 24, 2008 at 8:04 AM, Steve Midgley <[EMAIL PROTECTED]> wrote: > At 11:28 AM 10/23/2008, Joe wrote: >> >> Steve Midgley wrote: # (invoiceid, txid) (A, 1) (A, 3) (B, 1) (B, 2) (C, 5) (D, 6) (D, 7) (E, 8) (F, 8) For journalli

Re: [SQL] Can COPY update or skip existing records?

2008-10-01 Thread Tony Wasson
On Tue, Sep 30, 2008 at 5:16 AM, Glenn Gillen <[EMAIL PROTECTED]> wrote: > Hey all, > > I've got a table with a unique constraint across a few fields which I > need to regularly import a batch of data into. Is there a way to do it > with COPY without getting conflicts on the unique contraint? I hav

Re: [SQL] accounting schema

2008-02-07 Thread Tony Wasson
r codebase to look at is http://www.sql-ledger.org/. It uses postgresql. Regards, Tony ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] How to pass array of values to a stored procedure

2006-07-18 Thread Tony Wasson
On 7/18/06, Tony Wasson <[EMAIL PROTECTED]> wrote: On 7/18/06, Curtis Scheer <[EMAIL PROTECTED]> wrote: > Does anyone have any examples of how I would make a stored procedure in > plpgsql that would allow for passing a list or arrays of values to be used > in an sql IN cla

Re: [SQL] How to pass array of values to a stored procedure

2006-07-18 Thread Tony Wasson
On 7/18/06, Curtis Scheer <[EMAIL PROTECTED]> wrote: Does anyone have any examples of how I would make a stored procedure in plpgsql that would allow for passing a list or arrays of values to be used in an sql IN clause? Like so: select * from table where field1 in (values). Here's a very sim

Re: [SQL] help..postgresql mulyiple return values

2006-05-18 Thread Tony Wasson
On 5/12/06, Michael Joseph Tan <[EMAIL PROTECTED]> wrote: hi, im new in postgresql, generally new in databases. im trying to make a function using PGAdminIII which returns several types, example, my query is: "select count(id) as requests, organization from connection_requests group by organiz

Re: [SQL] Function Dependency

2006-02-05 Thread Tony Wasson
I ended up writing a perl script to parse my SQL and make a graphviz dot file. I then used graphviz to make a function dependency chart. I can't promise it would catch every single case, but I can provide you with the code if you wish to give it a whirl. Tony Wasson -

Re: [SQL] psql client: technique for applying default values to :variables?

2006-01-11 Thread Tony Wasson
On 1/11/06, Jeff Boes <[EMAIL PROTECTED]> wrote: > Stumped: is there any way to set up default values for psql variables > within the .SQL file itself? Obviously, I can do something like: > > $ psql -f my_script -v MYVAR=${myvar:-mydefault} > > but I would prefer to have the value stored with the .

Re: [SQL] Multi-column returns from pgsql

2005-07-22 Thread Tony Wasson
On 7/22/05, Jim Buttafuoco <[EMAIL PROTECTED]> wrote: > Mark, > > Instead of RETURN NEXT rec.txt1; RETURN NEXT rec.txt2; just use RETURN NEXT > rec; > > then your select statement would be > select * from my_func() as (txt1 text,txt2 text); > > Jim Besides a simple RETURN NEXT, you'll need to

Re: [SQL] echo/printf function in plpgsql

2005-07-19 Thread Tony Wasson
TDERR for logging). > > I see. Can I make the ouput somehow less verbose? It spits out a lot of noise > for each "NOTICE": You can control the severity messages sent to your client by first setting client_min_message. Try SET client_min_messages = WARNING; http://www.postgresq

Re: [SQL] funstions for parsing words

2005-07-19 Thread Tony Wasson
sible? > > Thanks alot. > > Your Friend, > > John Kopanas You can do this by using array_to_string and using a space as your delimiter. If you need to trim the quotes use the trim function also. You can also see the split_on_commas example below -- you'd want to split on

Re: [SQL] left joins

2005-07-06 Thread Tony Wasson
h left join p on (h.r=p.r and h.pos=r.pos and p.r_order=1) where h.tn > 20 and h.tn < 30 Filtering within the join condition is very useful when doing a left outer join. Here's another example "from the book" doing this type of filter within the join: http://www.postgresql

Re: [SQL] 3 tables, slow count(*), order by Seq Scan in Query Plan

2005-05-27 Thread Tony Wasson
eriodic summarization you run. This sounds like a "top N" report so a periodic update out to work. http://jonathangardner.net/PostgreSQL/materialized_views/matviews.html Tony Wasson ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] Help: Function for splitting VARCHAR column and migrating its data to 2 new tables

2005-05-24 Thread Tony Wasson
le row by using something like SELECT build_keyword_table('123'); I also used this as my test data... It worked for me! CREATE TABLE user_data ( id SERIAL, user_id INTEGER, keywords VARCHAR(256) NOT NULL, add_date TIMESTAMP, PRIMARY KEY(id) ); INSERT

Re: [SQL] default value for select?

2005-05-09 Thread Tony Wasson
rom your subquery. This is not elegant at all, but it should do what you are wanting. update myTable set myColumn = (CASE WHEN (Select altColumn from altTable where altColumn != 'XXX' limit 1) IS NULL THEN 'some default value' ELSE (Select altColumn from altTable where

Re: [SQL] Looking for a way to sum integer arrays....

2005-04-29 Thread Tony Wasson
um_integer_array(somearr) FROM arraytest ; sum_integer_array --- {1,3,5} (1 row) Tony Wasson ---(end of broadcast)--- TIP 8: explain analyze is your friend

[SQL] Looking for a way to sum integer arrays....

2005-04-22 Thread Tony Wasson
x_sum example in the docs. - CREATE OR REPLACE FUNCTION sum_intarray(INTEGER[],INTEGER[]) RETURNS INTEGER[] LANGUAGE 'plpgsql' AS ' /* || Author: Tony Wasson || || Overview: Experiment with arrays and aggregates || 3,2,1 ||+ 0,2,2 || --- || 3,4,3 || || Revisions

[SQL] help with scheme changes to live system.

2004-08-25 Thread Tony Yang
Hi Gurus, Please forgive this naive question: Say, I have a table (containerId, itemId) where for each containerId there are several rows (different itemId value) in that table. Now I want to give those rows (with same containerId) a sequence, so add one colum there to make it become (containerI

Re: [SQL] best method to copy data across databases

2004-07-02 Thread Tony Reina
inserts. >From the pg_dump manpage, --attribute-inserts Dump data as INSERT commands with explicit column names (INSERT INTO table (column, ...) VALUES ...). This will make restoration very slow, but it is necessary if you desire to rearrange the

[SQL] SELECTing part of a matrix

2004-04-27 Thread Tony Reina
Any way to do this? -Tony ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] Help with COPY command

2004-04-14 Thread Tony and Bryn Reina
Thanks for the reply. -Tony - Original Message - From: "Christoph Haller" <[EMAIL PROTECTED]> To: "Tony Reina" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, April 14, 2004 5:42 PM Subject: Re: [SQL] Help with COPY command > >

Re: [SQL] Help with COPY command

2004-04-09 Thread Tony Reina
tline(conn,"\\.\n"); PQendcopy(conn); 1. I'm assuming that I can put in as many PQputline statements as I want to between the PQexec("COPY ... FROM ...") and the terminator line. Is that correct? No limit? 2. Do any of these lines need to be followed by a PQclear(res)? Wha

[SQL] Help with COPY command

2004-04-09 Thread Tony Reina
t be broken up into separate lines? For example, res = PQexec(conn, "COPY testtable FROM stdin WITH DELIMITER ',';"); res = PQexec(conn, "1, 2, 'a', 3, 4"); res = PQexec(conn, "5, 6, 'b', 7, 8"); res = PQexec(conn, "9, 10, 'c',

Re: [SQL] Trouble porting a Oracle PL/SQL procedure to PL/pgSQL--THANKS!

2003-06-18 Thread Tony G. Harris
On Tue, 17 Jun 2003 00:42:54 -0400 Tom Lane <[EMAIL PROTECTED]> writes: > Stephan Szabo <[EMAIL PROTECTED]> writes: > > On Mon, 16 Jun 2003, Tony G. Harris wrote: > >> The problem is, when I call the function, I get: > >> sql-practice=# select update_pay();

Re: [SQL] help

2003-06-17 Thread Tony Simbine
Josh, thanks for your help. Josh Berkus wrote: Tony, I've a query which needs too many time ca. 12-15 sec. how can i get a better perfomance? First of all, please take this to the PGSQL-PERFORMANCE list. Second, see this web page: http://techdocs.postgresql.org/g

[SQL] Trouble porting a Oracle PL/SQL procedure to PL/pgSQL

2003-06-16 Thread Tony G. Harris
Hello. I'm using PostgreSQL to learn SQL and SQL-based languages. The text I'm using (SAMS Teach Yourself SQL in 21 Days, 3rd.ed.) references Oracle in its examples, though I can usually get PostgreSQL to work almost as well. Well, I'm almost to the end of the book and I'm trying to port some of

[SQL] help

2003-06-12 Thread Tony Simbine
hello, I've a query which needs too many time ca. 12-15 sec. how can i get a better perfomance? my table have less than 2300 rows. thanks in advance tony explain select o.id from ioobeject o,dist_vertron v where macro_lid=1123 and (o.id=v.id) and (o.deleted<>'1&

Re: [SQL] help: triggers

2003-01-30 Thread Tony Simbine
empo" integer DEFAULT 0 NOT NULL, "deleted" character(1) DEFAULT '0', Constraint "pk_iobjects" Primary Key ("id") ); GRANT ALL on "iobjects" to "jantos"; Wei - Original Message - From: "Tony Simbine&q

[SQL] help: triggers

2003-01-29 Thread Tony Simbine
hello, I'm trying to update a columm on a table with a trigger but it don't work on PostgreSQL 7.2 (i686-pc-linux-gnu, compiled by GCC 2.96). when I update a row the trigger does nothing. what can I do? thanks in advance tony here is

Re: [GENERAL] [SQL] Database Design tool

2002-11-05 Thread tony
e page that is mentionned on the postgresql web site??? nuff said? Tony ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] Foreign character struggles

2002-10-28 Thread Tony Grant
turned the to_ascii stuff off. See www.3continents.com/base_de_donnees.htm and search for "Amnésie" if you want the english search to work you search for "Amnesia"... The client wants the user to check spelling... Before it worked just the way you wanted _but_ I am using a JDBC reque

Re: [SQL] Combine query views into one SQL string

2001-09-14 Thread Tony Hunt
I don't get it? What's the difference between an inner-join and an equijoin? "Nils Zonneveld" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > > Maik wrote: > > > > Its clear, union concat the two results. > > > > But he can also use this join version, if its

[SQL] (No Subject)

2001-01-19 Thread Tony Mantana
Hello, I have visited your web site and found very interesting and informative. I would like to know: What is a BLOB Field and can you give a example of one? I hope to hear from you soon Get your small business started at Lycos Small Business at http://www.lycos.com/business/mail.html

Re: [SQL] Supported Encoding

2000-07-11 Thread Toshihide Tony Nakamura
Volker, Thank you, I was using UTF8 because I am accessing the database via JDBC, and Java's default encoding is UTF8. I wasn't sure about whether it was a right thing to do or not. Thank you very much. I really appreciate your help! Tony Nakamura - Original Message

[SQL] Supported Encoding

2000-07-10 Thread Tony Nakamura
I am using PHP to insert/retrieve data without any encoding conversions. I think my Postgresql was not specified any special encoding at the time of make. Do I need to convert everything EUC before I store data, and do why would I need to do that? Thanks in advance!! Tony