Re: [GENERAL] Need query

2014-04-11 Thread David G Johnston
Gaurav Jindal wrote a has relation with b and b has relation with c Given this statement what specifically are you having difficulty with. You are allowed to perform multiple joins, whether explicit or via FROM/WHERE, in the same query. SELECT ... FROM a,b,c WHERE a=b and b=c OR SELECT ...

Re: [GENERAL] Problem with query

2014-04-11 Thread David G Johnston
Susan Cassidy-3 wrote I have a query with several joins, where I am searching for specific data in certain columns. While accurate as far as describing a typical query it doesn't really tell us its intent What is the first query doing wrong? No idea, though it may have something to do

Re: [GENERAL] Querying all documents for a company and its projects etc

2014-04-15 Thread David G Johnston
A couple of thoughts: 1) The union really only pertains to the entity table rows; once you union all those (duplicates should not matter and probably will not even be present so using all avoids an unnecessary sort) you can join that sub-query to the document_usage table. 2) Since every entity

Re: [GENERAL] [GENARAL] round() bug

2014-04-15 Thread David G Johnston
Willy-Bas Loos-3 wrote Hi, I ran into some strange behavior. Seems like a bug to me? wbloos=# select round(0.5::numeric), round(0.5::double precision); round | round ---+--- 1 | 0 (1 row) Not a bug; and likely to simple to have escaped notice this long so the first

Re: [GENERAL] [GENARAL] round() bug

2014-04-15 Thread David G Johnston
Raymond O'Donnell wrote On 15/04/2014 17:20, David G Johnston wrote: Willy-Bas Loos-3 wrote Hi, I ran into some strange behavior. Seems like a bug to me? wbloos=# select round(0.5::numeric), round(0.5::double precision); round | round ---+--- 1 | 0 (1 row) Not a bug

[GENERAL] Re: any way for a transaction to see inserts done earlier in the transaction?

2014-04-16 Thread David G Johnston
One possibility is that the INSERT is going to a different table (having the same name but existing in a different schema) that is visible/default to the function but not outside of it. Or the function on the server is not current and thus isn't doing what you think it is. I do an insert via

[GENERAL] Re: any way for a transaction to see inserts done earlier in the transaction?

2014-04-16 Thread David G Johnston
Susan Cassidy-3 wrote Nor can any regular SELECTs in the main program find it. Ever? If this is a same transaction visibility issue then when your Perl program stops you should be able to go find that ID manually to confirm it was inserted and committed properly. If you still cannot find the

[GENERAL] Re: any way for a transaction to see inserts done earlier in the transaction?

2014-04-16 Thread David G Johnston
I'm presuming the OP is using the typical model of: conn = getConnection() id = doInsert(conn) rst = doSelect(conn, id) doSomething(rst) conn.commit() conn.relrease() Robert DiFalco wrote Two common cases I can think of: 1. The PERL framework is only caching the insert and does not actually

[GENERAL] Re: any way for a transaction to see inserts done earlier in the transaction?

2014-04-17 Thread David G Johnston
Please note that everyone here but you is bottom-posting; please follow the convention and list standard. Susan Cassidy-3 wrote It is never committed, because the lookup for the insert fails. So, alter the code so only the first insert happens then stop further processing and go explore that

[GENERAL] Re: Altering array(composite-types) without breaking code when inserting them and similar questions

2014-04-20 Thread David G Johnston
Dorian Hoxha wrote Hi list, I have a create type thetype(width integer, height integer); create table mytable(thetype thetype[]); How can i make an insert statement so if i later add fields to the composite type, the code/query doesn't break ? Maybe by specifying the fields of the

Re: [GENERAL] Return and sql tuple descriptions are incompatible

2014-04-24 Thread David G Johnston
Hengky Lie wrote Select * from crosstab($$select produkid, warehouseid,onhand from vwtest order by 1,2$$) as t (produkid VARCHAR, warehouseid integer) The crosstab command didn't work with error : Return and sql tuple descriptions are incompatible. I have tried to change productid type

Re: [GENERAL] a row not deletes

2014-04-27 Thread David G Johnston
Andres Freund-3 wrote Hi, On 2014-04-27 10:23:18 +0200, Rafał Pietrak wrote: I've just experienced an unexpected (for me) loss of DELETE. Is this a feature or a bug (postgres v.s. SQL)? I guess you're using 9.2 or older? You are not allowed to update the deleted row in a BEFORE trigger.

[GENERAL] Re: Postgresql the right tool (queue using advisory_locks + long transactions)

2014-04-27 Thread David G Johnston
Dorian Hoxha wrote Hi list, I am trying to use postgresql as a queue for long-jobs (max ~4 hours) using advisory_locks. I can't separate the long-job into sub-jobs. 1. At ultimate-best-case scenario there will be ~100 workers, so no web-scale performance required. Is there a

Re: [GENERAL] xml question

2014-04-28 Thread David G Johnston
David Ekren wrote I am new to this forum. I need to return the value 1 between the orientationId tags in this xml string within the function below. I still get errors. I'm sure I am doing something wrong. Any help would be appreciated. CREATE FUNCTION Davidxml9(v_clipId integer,

Re: [GENERAL] Escape double-quotes in text[]?

2014-04-29 Thread David G Johnston
Raymond O'Donnell wrote Hi all, Probably a silly question, but I'm having trouble figuring out the answer... if I'm constructing an string representation of a value to go into a text[] column, and one of the text literals includes double-quotes, do I need to escape the literal? For

Re: [GENERAL] Escape double-quotes in text[]?

2014-04-29 Thread David G Johnston
Raymond O'Donnell wrote '{abc, def}' Or would I need to do this? - E'{abc, def}' Do you realize that both of the above expressions are effectively identical? David J. -- View this message in context:

Re: [GENERAL] Escape double-quotes in text[]?

2014-04-30 Thread David G Johnston
Raymond O'Donnell wrote On 29/04/2014 22:54, David G Johnston wrote: Raymond O'Donnell wrote Hi all, Probably a silly question, but I'm having trouble figuring out the answer... if I'm constructing an string representation of a value to go into a text[] column, and one of the text literals

Re: [GENERAL] arrays of rows and dblink

2014-04-30 Thread David G Johnston
Torsten Förtsch wrote Hi, we have the ROW type and we have arrays. We also can create arrays of rows like: select array_agg(r) from (values (1::int, 'today'::timestamp, 'a'::text), (2, 'yesterday', 'b')) r(a,b,c); array_agg

Re: [GENERAL] arrays of rows and dblink

2014-04-30 Thread David G Johnston
Torsten Förtsch wrote On 30/04/14 20:19, David G Johnston wrote: ISTM that you have to CREATE TYPE ... as appropriate then ... tb ( col_alias type_created_above[] ) There is only so much you can do with anonymous types (which is what the ROW construct creates; ROW is not a type

Re: [GENERAL] Revoke - database does not exist

2014-05-01 Thread David G Johnston
Prashanth Kumar wrote Hi, Do not seem to figure out what is wrong here. Why am I getting database does not exist. I just created the database and am able to connect to it as postgres user. I am trying to restrict testuser from connecting to myDB database. Thomas is likely correct about

Re: [GENERAL] Server continuously enters to recovery mode.

2014-05-03 Thread David G Johnston
DrakoRod wrote Hi everybody! I have a problem (really huge problem), I have one server of production, but yesterday in the night I saw this error: * ERROR: could not access status of transaction 2410303155 DETAIL: Could not open file pg_clog/08FA: No such file or directory *

Re: [GENERAL] Crosstab function

2014-05-05 Thread David G Johnston
Hengky Lie wrote The crosstab warehouse column name (OFFICE Store2) is taken from tblwarehouse so when user add warehouse, crosstab column name will change automatically. And also each row has total qty. In what programming language? The only way to do this is to dynamically construct the

Re: [GENERAL] SELECT with column specified by subquery

2014-05-05 Thread David G Johnston
webcoyote wrote I desire to create a SELECT statement where one of the column names comes from another table. Something like: SELECT id, (SELECT type FROM favorite_food_type WHERE user = 'ralph') FROM foods; If Ralph's favorite food type is fruit, ultimately I'd like the query to

Re: [GENERAL] Crosstab function

2014-05-05 Thread David G Johnston
Hengky Lie wrote Hi David, Are you sure that there is no pure sql solution for this ? I think (with my very limited postgres knowledge), function can solve this. Which is the column header I need but I really have no idea how to use this as column header. Anyway, If i can't do

[GENERAL] any psql \copy tricks for default-value columns without source data?

2014-05-06 Thread David G Johnston
So, I am trying to import a file into a table and want to assign a sequence value to each record as it is imported. I know that I can pre-process the input file and simply add the needed data but I am curious if maybe there is some trick to having defaults populate for missing columns WITHOUT

[GENERAL] Re: any psql \copy tricks for default-value columns without source data?

2014-05-06 Thread David G Johnston
On Tue, May 6, 2014 at 4:48 PM, John R Pierce [via PostgreSQL] ml-node+s1045698n5802802...@n5.nabble.com wrote: On 5/6/2014 1:22 PM, David G Johnston wrote: I know that I can pre-process the input file and simply add the needed data but I am curious if maybe there is some trick to having

[GENERAL] Re: any psql \copy tricks for default-value columns without source data?

2014-05-07 Thread David G Johnston
Thank you everyone; some good programs to check out but I just went ahead and used awk to add two additional columns of data to the input file before sending it onto psql. David J. -- View this message in context:

Re: [GENERAL] probable pg_hba.conf configuration issues

2014-05-07 Thread David G Johnston
Ravi Roy wrote But if I try to connect using pgadmin (from the same machine) it gives acess to database without password, i'm surprised as it does not seem to respect pg_hba.conf or i'm terribly wrong in the configuration somewhere. You likely told pgadmin to remember (store) passwords. If

Re: [GENERAL] How to fix lost synchronization with server

2014-05-07 Thread David G Johnston
Andrus Moor wrote Dump worked for years without issues when server was 32 bit Windows 2003 server and Postgres and pg_dump were earlier version 9 (but after upgrade new rows are added to attachme table). How to create backup copies or diagnose the issue ? I can change pg_dump execution

Re: [GENERAL] Enforce Symmetric Matrix

2014-05-07 Thread David G Johnston
SELECT l.id, u.id, func(l.id, u.id) FROM ids l CROSS JOIN ids u WHERE l.id u.id Depending on whether you always update a known pair, or instead invalidate all rows where either id is a given value, you can use various means to manage the resultant materialized view. Triggers or interface

Re: [GENERAL] Pgpool starting problem

2014-05-08 Thread David G Johnston
Jay at Verizon wrote Hi all, If I turn use_watchdog = off in the pgpool.conf file, then in spite of the system being configured as master-slave, a socket file is created in /tmp, and everything starts normally with no errors. If, however, I set use_watchdog = on, pgpool will abort on

Re: [GENERAL] Receiving many more rows than expected

2014-05-09 Thread David G Johnston
Vincent de Phily wrote On Friday 09 May 2014 06:52:33 Adrian Klaver wrote: On 05/09/2014 05:36 AM, Vincent de Phily wrote: On Friday 09 May 2014 07:01:32 Tom Lane wrote: Vincent de Phily lt; vincent.dephily@ gt; writes: In case it changes anything, this is the uncut (but still

[GENERAL] Re: Partitioning such that key field of inherited tables no longer retains any selectivity

2014-05-11 Thread David G Johnston
Tim Kane wrote The subject line may not actually describe what I want to illustrate… Basically, let’s say we have a nicely partitioned data-set. Performance is a net win and I’m happy with it. The partitioning scheme is equality based, rather than range based. That is, each partition

[GENERAL] Re: Partitioning such that key field of inherited tables no longer retains any selectivity

2014-05-11 Thread David G Johnston
On Sun, May 11, 2014 at 2:08 PM, Tim Kane [via PostgreSQL] ml-node+s1045698n5803574...@n5.nabble.com wrote: From: Tom Lane [hidden email]http://user/SendEmail.jtp?type=nodenode=5803574i=0 David G Johnston [hidden email]http://user/SendEmail.jtp?type=nodenode=5803574i=1 writes: Two

[GENERAL] Re: Creating a role with read only privileges but user is allowed to change password

2014-05-11 Thread David G Johnston
Adrian Klaver-4 wrote On 05/11/2014 10:17 AM, Ravi Roy wrote: Thanks a lot Tom, it worked by putting off the read only mode to off before changing the password and putting it on again. SET default_transaction_read_only = off; Worked for me.. It works but the point Tom was making is here:

[GENERAL] Re: Creating a role with read only privileges but user is allowed to change password

2014-05-11 Thread David G Johnston
​I​ suggest that you move the password to a separate table (my_role_password) with 2 columns: 1. my_role_id 2. password. This way you can make the my_role table totally unalterable by the user, yet they can change their own password. Actually, you should NOT be storing

Re: [GENERAL] XML validation of whitespace values

2014-05-11 Thread David G Johnston
Tim Kane wrote clone=# create temp table xml_test (document xml); CREATE TABLE If you know you need to use xpath on this content then you should do one of the following: SELECT CASE WHEN document IS DOCUMENT THEN xpath(...) ELSE default_value_for_missing_data END; CREATE TABLE xml_test (

Re: [GENERAL] 8.4 - 9.1 : ANALYSE VERBOSE; - out of shared memory

2014-05-12 Thread David G Johnston
Alvaro Herrera-9 wrote Souquieres Adam wrote: The solution must be to define a *better strategy for tables statistics*... we dont really need stats on all the tables because the most part of them is static... Tune autovacuum so that it does the analyses for you? And for those few tables

Re: [GENERAL] Receiving many more rows than expected

2014-05-12 Thread David G Johnston
Did you try rewriting the query to avoid using an IN expression? UPDATE foo SET processing = 't' FROM ( SELECT id FROM foo WHERE processing = 'f' ORDER BY id ASC LIMIT 5000 FOR UPDATE ) src WHERE foo.id = src.id; The workaround I mentioned above said that a CTE was needed but I'm thinking that a

[GENERAL] Re: TODO: Expose parser support for decoding unicode escape literals to user

2014-05-15 Thread David G Johnston
Adrian Klaver-4 wrote On 05/15/2014 01:31 AM, Craig Ringer wrote: Hi all I just noticed a Stack Overflow question (http://stackoverflow.com/q/20124393/398670) where someone's asking how to decode '\u` style escapes *stored in database text fields* into properly encoded text strings.

Re: [GENERAL] Force specific index disuse

2014-05-20 Thread David G Johnston
Steve Crawford wrote On 05/20/2014 10:44 AM, Alvaro Herrera wrote: Steve Crawford wrote: Is there a way to force a specific index to be removed from consideration in planning a single query? Specifically, on a 60-million-row table I have an index that is a candidate for removal. I have

Re: [GENERAL] Force specific index disuse

2014-05-20 Thread David G Johnston
On Tue, May 20, 2014 at 3:20 PM, Jeff Janes [via PostgreSQL] ml-node+s1045698n580459...@n5.nabble.com wrote: On Tue, May 20, 2014 at 11:48 AM, Steve Crawford [hidden email]http://user/SendEmail.jtp?type=nodenode=5804596i=0 wrote: On 05/20/2014 10:44 AM, Alvaro Herrera wrote: Steve

Re: [GENERAL] Question regarding DEALLOCATE pdo_stmt_00000001

2014-05-21 Thread David G Johnston
Laurentius Purba wrote Hello all, I've been seeing lots of this processes in my database DEALLOCATE pdo_stmt_0001 with idle state. Executing *select * from pg_stat_activity where query like 'DEALLOCATE%';*I can see some of them are idle for +/- 30 minutes, and there is one idle for

[GENERAL] Re: COPY TO returns ERROR: could not open file for writing: No such file or directory

2014-05-24 Thread David G Johnston
David Noel wrote COPY (SELECT * FROM page WHERE PublishDate between '2014-03-01' and '2014-04-01') TO '/home/ygg/sql/backup/pagedump.2014-03-01.to.2014-04-01.copy'; Is /home/ygg a client or server path? COPY != \copy David J. -- View this message in context:

Re: [GENERAL] Trouble running nested select - Join query

2014-05-26 Thread David G Johnston
Rushi wrote copy (select * from (select s1.head as h1,s1.tail as t1 ,s2.tail as neighbor from miami_2d s1, miami_directednetwork s2 where s1.tail=s2.head and s2.tail not in (select tail from miami_2d where head=s1.head)) as O where O.h1!=O.neighbor) to '/tmp/tmp.txt' Some thoughts: The O

Re: [GENERAL] Conversion from CHAR HEX

2014-05-27 Thread David G Johnston
saqibrafique wrote hi guys, I am trying to convert a simple char value to HEX but I am getting Error. * MyTable: * CREATE TABLE mytable (from_ip CHAR(20), to_ip CHAR(20)); * I have below values in the Table: * fm_db_Server1=# select * from operator; from_ip|

Re: [GENERAL] Postgresql service stopped automatically after restart

2014-05-29 Thread David G Johnston
Kalai R wrote I have checked no problem in pg_hba.conf file. Also I have disabled AV software checks for the Postgres Directories. But Problem remains Disabling AV won't magically make the system start working if it's already broken. You disable it to avoid breaking the system in the

Re: Fwd: [GENERAL] libpq: indefinite block on poll during network problems

2014-05-30 Thread David G Johnston
Tom Lane-2 wrote Dmitry Samonenko lt; shreddingwork@ gt; writes: Yeah, that will work. Looks simple to implement in the client. Question is: why don't you think it should be a part of the libpq's API? It's a must have feature in high availability environments where only several minutes

Re: [GENERAL] How is sorting work?

2014-05-30 Thread David G Johnston
Quang Thoi wrote Thanks Steve! Just want to get confirmation that postgres does not use any special rules When no sorting order specified. Didn't your testing prove that out sufficiently? I'd be more concerned, though, if you took random congruence between the two results (I.e. If they

Re: [GENERAL] Migrating from 9.2.4 to 9.3.0 with XML DOCTYPE

2014-06-04 Thread David G Johnston
Tim Kane wrote I suspect this might be resolved in a newer point release of 9.3, however I don’t have the luxury on this particular host right now. Any suggestions how I might convince 9.3.0 to accept the dump from 9.2.4? Given the history of 9.3 if you cannot use the most current point

[GENERAL] Re: PostgreSQL 9.3 XML parser seems not to recognize the DOCTYPE element in XML files

2014-06-04 Thread David G Johnston
Peter Eisentraut-2 wrote On 5/29/14, 11:59 AM, Bob Moyers wrote: When I try this update: UPDATE REPORT_STYLE SET JASPER_STYLE = XMLPARSE(DOCUMENT ?) WHERE (REPORT_STYLE_NAME = ?) I get: org.postgresql.util.PSQLException: ERROR: invalid XML content Detail: line 2: StartTag:

Re: [GENERAL] help with a procedure

2014-06-05 Thread David G Johnston
Have you read this chapter of the documentation? http://www.postgresql.org/docs/9.3/interactive/plpgsql.html Carlos Carcamo wrote What I need is some help with the procedure in postgres, I have searched in google, but I dont know how to do it, the goal is perform the first insert and then

Re: [GENERAL] help with a procedure

2014-06-05 Thread David G Johnston
Carlos Carcamo wrote SELECT myProcedure(product_id, p_description, price, qty, store_id, store_description ); waiting for a response from procedure, maybe true or false. Note that forcing the procedure to return false instead of simply throwing an error is going to degrade performance. If

Re: [GENERAL] Optimizer issue -- bad query plan?

2014-06-05 Thread David G Johnston
Moshe Jacobson wrote I have the following query: [...] The EXPLAIN ANALYZE for this query indicates that all of the tables in the query are being joined despite the fact that they are not needed at all. Why is this? Without definitions of all the tables involved, as well as knowing what

Re: [GENERAL] pg_attribute growing extremely

2014-06-05 Thread David G Johnston
hamann.w wrote Hi, on a server running 8.4 I observe that, since a while, the pg_attribute table is growing enormously. Soon after reloading I have one file ls -s 1249 1048580 1249 a day later this is 1048580 1249 1048580 1249.1 1048580 1249.10 1048580 1249.11 1048580 1249.12

Re: [GENERAL] How to select rows for which column has empty array ?

2014-06-06 Thread David G Johnston
Arup Rakshit wrote I have a below table : yelloday_development=# select id,workplace_ids,team_ids  from reporting_groups ;                                                                                                                                                                          

Re: [GENERAL] Application crashing due to idle connection

2014-06-18 Thread David G Johnston
itishree sukla wrote Our application is crashing... It really does help to be more specific with statements of this nature. In particular: 1) exactly how many idle connections (and are any of them idle in transaction)? You ran the queries - provide the numbers reported to you. 2) how many

Re: [GENERAL] if row has property X, find all rows that has property X

2014-06-24 Thread David G Johnston
Дмитрий Голубь wrote For example I have table addresses and usually I want 2 things: 1. Find id of bad addresses. 2. Check if this address is good or bad. For this I write two plpgsql functions 1. find_all_bad_addresses 2. is_bad_address(id) These functions will duplicate logic of each

Re: [GENERAL] Questions about daterange() function

2014-06-25 Thread David G Johnston
Ken Tanzer wrote Hi. I've got lots of tables with start and end dates in them, and I'm trying to learn how to work with them as date ranges (which seem fantastic!). I've noticed that the daterange() function seems to create ranges with an inclusive lower bound, and an exclusive upper bound.

Re: [GENERAL] Fast data, slow data

2014-06-27 Thread David G Johnston
Tim Uckun wrote The database is functioning fine now but I am anticipating a much higher workload in the future. The table in question is probably going to have a few million rows per day inserted into it when it gets busy, if it gets very busy it might be in the tens of millions per day but

[GENERAL] Re: collecting employees who completed 5 and 10 years in the current month

2014-06-30 Thread David G Johnston
Rebecca Clarke-2 wrote create view vw_employee as select * from employees where ((age(joining_date::date) like '5 years%') or (age(joining_date::date) like '10 years%') ) This does not give the correct answer to the poster's question - the LIKE with a trailing % will pick up non-round

Re: [GENERAL] Cannot query views with WHERE clause on renamed columns

2014-06-30 Thread David G Johnston
Alexander Reichstadt wrote Hi, I try to do what seems to be totally simple, but it fails. If I query a view that contains renamed columns without any qualifier like SELECT * FROM myview it displays everything. If however I do SELECT reanmedviewcolumn FROM myview It tells me

Re: [GENERAL] how to create a role with no privileges?

2014-07-01 Thread David G Johnston
Kynn Jones wrote On Tue, Jul 1, 2014 at 12:36 PM, Francisco Olarte lt; folarte@ gt; wrote: Without seeing your actual commands, it's difficult to know about the schema stuff... Well, the actual commands is what the original question was asking for, since I really don't know how to

Re: [GENERAL] Question About Roles

2014-07-02 Thread David G Johnston
Tom Lane-2 wrote Rich Shepard lt; rshepard@ gt; writes: ... my question is what do I need to do so when a user is added to the system the local administrator and the group specified during the createuser process, she or he can be granted that group's privileges? I might be

[GENERAL] Re: How can I replace the year of the created_at column with the current year dynamically ?

2014-07-02 Thread David G Johnston
Adrian Klaver-4 wrote On 07/02/2014 12:48 AM, Arup Rakshit wrote: What is the data at your disposal when trying to select the current year? If it is a timestamp, simply use date_part: =# select date_part('year', now()); date_part --- 2014 (1 row) -- Michael It is

Re: [GENERAL] Question About Roles

2014-07-02 Thread David G Johnston
Rich Shepard wrote On Wed, 2 Jul 2014, David G Johnston wrote: or if you want to do it as part of creating a new user: CREATE ROLE new_management_user [other stuff here] IN ROLE management; http://www.postgresql.org/docs/9.2/interactive/sql-createrole.html David, I'll have

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread David G Johnston
Steve Crawford wrote On 07/02/2014 09:55 AM, Arup Rakshit wrote: SELECT users.gender,count(*) as participant,avg(daily_action_answers.value) as value FROM users INNER JOIN daily_action_answers ON daily_action_answers.user_id = users.id INNER JOIN measures ON measures.id =

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread David G Johnston
afonit wrote genderparticipants answer1_avg answer2_avg n 3 12 3 m 5 4 12 f 71523 Are you sure this is

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread David G Johnston
Arup Rakshit wrote SELECT users.gender,count(*) as participant, case when daily_action_answers.measure_id = 1 then avg(daily_action_answers.value) end as cpd, case when daily_action_answers.measure_id = 2 then avg(daily_action_answers.value) end as other  FROM users INNER JOIN

Re: [GENERAL] Query top 10 and others

2014-07-04 Thread David G Johnston
Edson Richter wrote I would like to construct a query, to be used in graphics (Pie Chart, to be more precise), and to avoid having 500 slices, I would like to make a query that returns the top ten, and then all the rest summed. I know I can do it by using some repetition, like: a) Assume

Re: [GENERAL] conditional IF statements in postgresql

2014-07-06 Thread David G Johnston
madhu_d wrote Hi, I am writing a C program to access a PostgreSQL database, where I add a column if it doesn't exists in the table or, update the column, if the column already exits. Please suggest how to work with the conditional statements. Thanks! N.B. I wrote the following:

Re: [GENERAL] invalid connection type listen_addresses='*'

2014-07-10 Thread David G Johnston
Aram Fingal wrote listen_addresses='*' parameter doesn't belong in pg_hba.conf This parameter should be in postgresql.conf Thanks. That was really unclear, at least the way I followed the online documentation: http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html

Re: [GENERAL] invalid connection type listen_addresses='*'

2014-07-10 Thread David G Johnston
David G Johnston wrote Aram Fingal wrote listen_addresses='*' parameter doesn't belong in pg_hba.conf This parameter should be in postgresql.conf Thanks. That was really unclear, at least the way I followed the online documentation: http://www.postgresql.org/docs/9.1/static

Re: [GENERAL] Windows Installation User account - Correct database for us

2014-07-10 Thread David G Johnston
Don Brown wrote Thank you and appreciate any comments/suggestions Host the database in a shared-tenent arrangement and have your application remotely connect to it or to an intermediary application that will then perform the work and simply deal with input/output with the client. Dave --

Re: [GENERAL] Use of tsvector in array

2014-07-10 Thread David G Johnston
Huang, Suya wrote Hi, We have the requirement of using the data type tsvector [], however, I didn't find out how to: * Use array operator together with tsquery operator o I have to unnest the array and then do query like ts@@ to_tsquery('ipod') You will have to create some

Re: [GENERAL] Design ? table vs. view?

2014-07-15 Thread David G Johnston
John McKown wrote I have a table which has some raw data in it. By raw, I mean it is minimally processed from a log file. Every week, I update this table by processing the weekly log using awk to create a psql script file which looks similar to: COPY rawdata FROM STDIN; lines created

Re: [GENERAL] How can I group all children by their parent ?

2014-07-17 Thread David G Johnston
Arup Rakshit wrote ORDER BY parent_id, id ? François Beausoleil parent_id .. But why order_by.. I thought I need to group by parent child email  1      2         test1@                 3        email The word group as you have used it can mean: Generate a single record for each

Re: [GENERAL] Watching Views

2014-07-17 Thread David G Johnston
Nick Guenther wrote Dear List, I am interested in replicating views of my data in real time to a frontend visualizer. I've looked around, and it seems that most applications in this direction write some ad-hoc json-formatter that spits out exactly the columns it is interested in. I

Re: [GENERAL] [ADMIN] Editable Views

2014-07-18 Thread David G Johnston
Ferrell, Denise CTR NSWCDD, Z11 wrote Using PostgreSQL 9.3 on Linux Red-Hat platform. Does PostgreSQL allow editable views? Please do not cross-post, even within these mailing lists. In almost all cases it is sufficient to post to -general. And besides, this is not really a server

Re: [GENERAL] Petition: Treat #!... shebangs as comments

2014-07-18 Thread David G Johnston
Frank Pinto wrote I personally like Francisco Olarte's approach. Hashbang's don't support arguments well ( http://stackoverflow.com/questions/4303128/how-to-use-multiple-arguments-with-a-shebang-i-e) and being able to put JUST psql as the command to execute the script doesn't scale across

Re: [GENERAL] statement_timeout doesn't work

2014-07-18 Thread David G Johnston
Sergey Konoplev-2 wrote Hi, PostgreSQL 9.2.7, Linux 2.6.32 Several days ago I found one of my servers out of connections, pg_stat_activity showed that everything was waiting for the DROP/ALTER INDEX transaction (see the record 2 below), that, as I guess, was waiting for the function call

Re: [GENERAL] statement_timeout doesn't work

2014-07-21 Thread David G Johnston
Sergey Konoplev-2 wrote On Fri, Jul 18, 2014 at 6:15 PM, David G Johnston lt; david.g.johnston@ gt; wrote: query | BEGIN; SET LOCAL statement_timeout TO 1000; DROP INDEX public.idx1; ALTER INDEX public.idx2 RENAME TO idx1; END; If I read this correctly you sent the entire

Re: [GENERAL] cursor return null

2014-07-21 Thread David G Johnston
rameshparnanditech wrote Hello, in postgres function (id bigint ),the following code not return any value with artNums ,But when i do select statement ony it's output the values with out include cursor i.e,cursor problem ..? please let me know what should i do to getvalues

Re: [GENERAL] Why would I need to explicitly cast a string literal to text?

2014-07-21 Thread David G Johnston
Derek Poon-2 wrote As an exercise, I've written the following query to implement [FizzBuzz][1]. SELECT COALESCE(fizz || buzz, fizz, buzz, '' || n) AS fizzbuzz FROM ( SELECT n0 + 3 * n3 + 9 * n9 + 27 * n27 + 81 * n81 AS n FROM

Re: [GENERAL] Question regarding log files in postgresql

2014-07-21 Thread David G Johnston
lucas.g...@gmail.com wrote I've rolled postgres to 'production', so box is in prod, but the applications aren't active yet. When I rolled the new box I'm seeing 2 log files: postgresql--MM-dd_hhmmss.log AND postgresql-9.3-main.log The 'main' log doesn't appear to be used, however

Re: [GENERAL] Referencing serial col's sequence for insert

2014-07-22 Thread David G Johnston
Albe Laurenz *EXTERN* wrote Also, I think that your method is vulnerable to race conditions: If somebody else increments the sequence between the INSERT and SELECT lastval() you'd get a wrong value. Uh, no. It returns that last value issued in the same session - which is race-proof.

Re: [GENERAL] Referencing serial col's sequence for insert

2014-07-22 Thread David G Johnston
On Tuesday, July 22, 2014, rob stone-2 [via PostgreSQL] ml-node+s1045698n5812384...@n5.nabble.com wrote: On Tue, 2014-07-22 at 13:32 +, Albe Laurenz wrote: rob stone wrote: I have a question on the right/correct practice on using the serial col's sequence for insert. Best

[GENERAL] Re: Why is unique constraint needed for upsert? (treat atomicity as optional)

2014-07-23 Thread David G Johnston
seamusabshere wrote At READ COMMITTED isolation level, you should always get an atomic insert or update [1] I just think there are a lot of non-concurrent bulk loading and processing workflows that could benefit from the performance advantages of upsert (one trip to database). Bulk load

[GENERAL] Re: Why is unique constraint needed for upsert? (treat atomicity as optional)

2014-07-23 Thread David G Johnston
seamusabshere wrote On 7/23/14 6:03 PM, John R Pierce wrote: On 7/23/2014 1:45 PM, Seamus Abshere wrote: What if we treat atomicity as optional? atomicity is not and never will be optional in PostgreSQL. I'm wondering what a minimal definition of upsert could be - possibly separating

[GENERAL] Re: Why is unique constraint needed for upsert? (treat atomicity as optional)

2014-07-23 Thread David G Johnston
hi David, My argument lives and dies on the assumption that UPSERT would be useful even if it was (when given with no options) just a macro for UPDATE db SET b = data WHERE a = key; IF NOT found THEN INSERT INTO db(a,b) VALUES (key, data); END IF; Adding things like

Re: [GENERAL] Watching Views

2014-07-23 Thread David G Johnston
Nick Guenther wrote As you said, attaching the trigger to a view is useless (for BEFORE/AFTER, which I'm interested in, also only works on statement level changes, which I would rather not have to deal with). I tried attaching my trigger to a materialized view and found that postgres

Re: [GENERAL] Regular expression question with Postgres

2014-07-24 Thread David G Johnston
Mike Christensen-2 wrote I'm curious why this query returns 0: SELECT 'AAA' ~ '^A{,4}$' Yet, this query returns 1: SELECT 'AAA' ~ '^A{0,4}$' Is this a bug with the regular expression engine? Apparently since {,#} is not a valid regexp expression the engine simply interprets it as a

Re: [GENERAL] Index usage with slow query

2014-07-25 Thread David G Johnston
Rebecca Clarke-2 wrote Thanks for the reply. Here's the EXPLAIN output of a couple of the queries: Typically you want to provide EXPLAIN ANALYZE output so that comparisons between planner estimates and reality can be made. David J. -- View this message in context:

Re: [GENERAL] Index usage with slow query

2014-07-25 Thread David G Johnston
Bill Moran wrote On Fri, 25 Jul 2014 17:20:57 +0100 Rebecca Clarke lt; r.clarke83@ gt; wrote: Note that this is speculation on my part, but the point being that if those columns are usually as narrow as your examples you might want to try changing them to VARCHAR(50) or something and

Re: [GENERAL] Pairwise array sum aggregate function?

2014-07-28 Thread David G Johnston
François Beausoleil wrote Hi all, NOTE: Also posted to StackOverflow: http://stackoverflow.com/questions/24997131/pairwise-array-sum-aggregate-function I have a table with arrays as one column, and I want to sum the array elements together: create table regres(a int[] not null);

Re: [GENERAL] tab_to_sting

2014-07-29 Thread David G Johnston
Ramesh T wrote Hi, when i ran below statement its working fine.. select string_agg(part_id::text,':') from part; But, SELECT tab_to_largeStringcheck(cast(string_agg(part_id::text,':')as t_varchar2_tab)) FROM part [image: Inline image 1] when i ran like SELECT

Re: [GENERAL] Joining on CTE is unusually slow?

2014-07-29 Thread David G Johnston
Jon Rosebaugh wrote This takes over eight minutes to run. Is this the expected behavior when joining on CTE expressions? I realize I haven't given the full schema/metadata/explain output as explained in the Slow Query Questions wiki page You should at least provide some explain a/o explain

Re: [GENERAL] How can I create null value from function call with no results?

2014-07-30 Thread David G Johnston
Seref Arikan wrote select 1,test_empty_row(1); SELECT 1, (SELECT test_empty_row(1)) AS func_result You can also adjust the function to either return the result of the query OR RETURN NULL if no results were found. i.e., do not use RETURN QUERY David J. -- View this message in context:

Re: [GENERAL] Inconsistent results postgresql

2014-07-30 Thread David G Johnston
Emir Ibrahimbegovic wrote Hello all, I've got two queries which should produce the same results but they don't for some reason, please consider these : SELECT date_trunc('day', payments.created_at) day, SUM(payments.amount) AS sum_id FROM payments INNER JOIN users ON users.id =

[GENERAL] Re: User-defined operator function: what parameter type to use for uncast character string?

2014-07-31 Thread David G Johnston
Adam Mackler-5 wrote (Cross-posted to StackOverflow: http://stackoverflow.com/questions/25041100/postgresql-user-defined-operator-function-what-parameter-type-to-use-for-uncast ) I'm defining my own domain and a equality operator. Next I create an equality operator to do case-insensitive

  1   2   3   4   5   6   7   8   9   10   >