Re: [GENERAL] Partitioning and constraint exclusion

2015-03-03 Thread David G Johnston
Samuel Smith wrote > I noticed that I could get very nice partition elimination using > constant values in the where clause. > > Ex: > select * from > where > > between '2015-01-01' and > '2015-02-15' > > However, I could not get any partition elimination for queries that did > not have

Re: [GENERAL] Constraints and inheritance

2015-03-05 Thread David G Johnston
Steven Erickson wrote > My problem now is that SELECTs scan all child tables And what do these SELECTs look like - specifically the WHERE clauses? David J. -- View this message in context: http://postgresql.nabble.com/Constraints-and-inheritance-tp5840715p5840716.html Sent from the PostgreS

Re: [GENERAL] VACUUM FULL doesn't reduce table size

2015-03-06 Thread David G Johnston
Vick Khera wrote > On Fri, Mar 6, 2015 at 5:59 AM, pinker < > pinker@ > > wrote: > >> I have deleted a large number of records from my_table, which originally >> had >> 288 MB. Then I ran vacuum full to make the table size smaller. After this >> operation size of the table remains the same, desp

Re: [GENERAL] Creating composite keys from csv

2015-03-08 Thread David G Johnston
Eli Murray wrote > Basically, what we'd like to do is create a serial primary key but instead > of having it increment every row, it needs to check the name and total > salary columns and only increment if that person doesn't already exist. So you already have a PK, (Name, Total Salary), but the s

Re: [GENERAL] Strange security issue with Superuser access

2015-03-10 Thread David G. Johnston
On Tue, Mar 10, 2015 at 8:20 AM, Andrzej Pilacik wrote: > I see the issues that this person might be having. I am not doing a > restore or working on an existing issue. > > My setup is very vanilla, anyone can create these tables and test, will > get the same permission error... (I did it in a

Re: [GENERAL] regclass and format('%I')

2015-03-13 Thread David G. Johnston
On Fri, Mar 13, 2015 at 12:18 PM, Jason Dusek wrote: > Hi All, > > The difference in how format handles `regclass` and `name` seems like an > inconsistency: > > WITH conversions(casts, format, result) AS ( > VALUES (ARRAY['name']::regtype[], '%I', format('%I', > name('select')

Re: [GENERAL] regclass and format('%I')

2015-03-14 Thread David G. Johnston
On Saturday, March 14, 2015, Jason Dusek wrote: > It honestly seems far more reasonable to me that %s and %I should do > the exact same thing with regclass. My reasoning is as follows: > > ‘%I’ formats a something such that it is a valid identifier, > > regclass is already a valid identifier, > >

Re: [GENERAL] regclass and format('%I')

2015-03-14 Thread David G. Johnston
On Sat, Mar 14, 2015 at 8:29 AM, Tom Lane wrote: > Jason Dusek writes: > > It honestly seems far more reasonable to me that %s and %I should do > > the exact same thing with regclass. > > You're mistaken. The operation of format() is first to convert the > non-format arguments to text strings,

Re: [GENERAL] regclass and format('%I')

2015-03-15 Thread David G. Johnston
On Sunday, March 15, 2015, Tom Lane wrote: > "David G. Johnston" > writes: > > ​IOW, as long as the output string matches: ^"(?:"{2})*"$ I do not see > how > > it is possible ​for format to lay in a value at %I that is any more > > insecure tha

Re: [GENERAL] How do I calculate the sum of a field filtered by multiple windows defined by another field?

2015-03-15 Thread David G. Johnston
On Sunday, March 15, 2015, Robert James wrote: > How do I calculate the sum of a field filtered by multiple windows > defined by another field? > > I have table event with fields event_date, num_events, site_id. I can > easily use aggregate SQL to do SELECT SUM(num_events) GROUP BY > site_id. > >

Re: [GENERAL] Slow query with join

2015-03-16 Thread David G. Johnston
On Mon, Mar 16, 2015 at 11:50 AM, Marc Watson wrote: > Hello all, > I am using PostgreSQL 9.4.1, compiled by Visual C++ build 1800, 64-bit, as > downloaded from EnterpriseDB, and is running on my dev system under Win 7 > 64-bit. > ​[...]​ > > However, when I combine the two queries into one, th

[GENERAL] How does one make the following psql statement sql-injection resilient?

2015-03-16 Thread David G. Johnston
psql "$SERVICE" \ --echo-queries \ --set=string_input="${1:-ok_to_return}" \ --set=start="${2:-5}" \ --set=end="${3:-10}" \ <<'SQL' SELECT idx FROM generate_series(1, 20) gs (idx) WHERE 'short-circuit' != :'string_input' AND idx BETWEEN :start AND :en

Re: [GENERAL] How does one make the following psql statement sql-injection resilient?

2015-03-16 Thread David G. Johnston
On Mon, Mar 16, 2015 at 2:51 PM, Andy Colson wrote: > On 3/16/2015 4:45 PM, Andy Colson wrote: > >> On 3/16/2015 4:30 PM, David G. Johnston wrote: >> >>> psql "$SERVICE" \ >>> --echo-queries \ >>> --set=string_inp

Re: [GENERAL] Group by range in hour of day

2015-03-16 Thread David G. Johnston
On Mon, Mar 16, 2015 at 3:13 PM, Adrian Klaver wrote: > On 03/16/2015 02:57 PM, Israel Brewster wrote: > >> I have a table with two timestamp columns for the start time and end >> time of each record (call them start and end).I'm trying to figure out >> if there is a way to group these records by

Re: [GENERAL] Group by range in hour of day

2015-03-16 Thread David G. Johnston
On Mon, Mar 16, 2015 at 4:16 PM, Israel Brewster wrote: > On Mar 16, 2015, at 2:22 PM, David G. Johnston > wrote: > > > On Mon, Mar 16, 2015 at 3:13 PM, Adrian Klaver > wrote: > >> On 03/16/2015 02:57 PM, Israel Brewster wrote: >> >>> I have a tabl

Re: [GENERAL] How does one make the following psql statement sql-injection resilient?

2015-03-16 Thread David G. Johnston
On Monday, March 16, 2015, Alvaro Herrera wrote: > David G. Johnston wrote: > > > Thanks! I got the gist even with the typo. I actually pondered about > > prepare/execute after hitting send. Am I correct in remembering that > > "CREATE TEMP TABLE" cannot be

Re: [GENERAL] Group by range in hour of day

2015-03-17 Thread David G. Johnston
On Tuesday, March 17, 2015, Israel Brewster wrote: > > > > On Mar 17, 2015, at 8:09 AM, Paul Jungwirth > wrote: > > > >>> test=> select h, count(*) from start_end, generate_series(0, 23) as > s(h) where h between extract(hour from start_time) and extract(hour from > end_time) group by h order by

Re: [GENERAL] Name spacing functions and stored procedures

2015-03-18 Thread David G. Johnston
On Wednesday, March 18, 2015, WadeDare4703 wrote: > I don't understand. What is wrong with having a schema which holds no > data? Schemas are cheap. > > -- > *From: *"Tim Uckun" > > *To: *"pgsql-general" > > *Sent: *Wednesday, March 18, 2015 6:56:55 PM > *Subject:

Re: [GENERAL] Archeiving and Purging

2015-03-18 Thread David G. Johnston
On Wednesday, March 18, 2015, John R Pierce wrote: > On 3/18/2015 7:20 AM, adityagis wrote: > >> I have lots of data in my DB. I need to do archeiving and purging of my >> data. >> Can anyone please help me with step by step riles? >> > > like this? > > select * from table where datefield < cur

Re: [GENERAL] How does one make the following psql statement sql-injection resilient?

2015-03-19 Thread David G. Johnston
On Mon, Mar 16, 2015 at 9:31 PM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Monday, March 16, 2015, Alvaro Herrera > wrote: > >> David G. Johnston wrote: >> >> > Thanks! I got the gist even with the typo. I actually pondered about >> &

Re: [GENERAL] How does one make the following psql statement sql-injection resilient?

2015-03-19 Thread David G. Johnston
On Thu, Mar 19, 2015 at 12:43 PM, Alvaro Herrera wrote: > David G. Johnston wrote: > > > Except that server "COPY" only is documented to accept a "query" that > > begins with either SELECT or VALUES :( > > > > I hereby voice my desire for EXECU

Re: [GENERAL] How does one make the following psql statement sql-injection resilient?

2015-03-19 Thread David G. Johnston
On Thu, Mar 19, 2015 at 12:46 PM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Thu, Mar 19, 2015 at 12:43 PM, Alvaro Herrera > wrote: > >> David G. Johnston wrote: >> >> > Except that server "COPY" only is documented to accept a

Re: [GENERAL] Index corruption

2015-03-24 Thread David G. Johnston
On Tuesday, March 24, 2015, Bankim Bhavsar wrote: > Hello postgres experts, > > We are running a test that periodically abruptly kills postgres > process(equivalent to kill -9) and restarts it. > After running this test for 24 hrs or so, we see duplicate primary key > entries in postgres table. >

Re: [GENERAL] Populating missing dates in postgresql data

2015-03-25 Thread David G. Johnston
On Wed, Mar 25, 2015 at 5:25 PM, Lavrenz, Steven M wrote: > Alright everyone, this is a doozy of a problem. I am new to Postgres so > I appreciate patience/understanding. I have a database of hardware objects, > each of which has several different “channels”. Once per day, these > channels are s

Re: [GENERAL] Populating missing dates in postgresql data

2015-03-25 Thread David G. Johnston
On Wed, Mar 25, 2015 at 8:57 PM, Mitu Verma wrote: > Hi, > > > > We have a customer complaining about the time taken by one of the > application scripts while deleting older data from the log tables. > > During the deletion, customer reported that he often sees the below error > and because of w

Re: [GENERAL] Autovacuum query

2015-03-25 Thread David G. Johnston
On Wed, Mar 25, 2015 at 8:58 PM, Mitu Verma wrote: > Correcting the subject > ​And this is why it is considered good form to do "compose new message" instead of replying to an existing one. Injecting your new topic into an existing unrelated mail thread is mildly annoying. David J. ​

Re: [GENERAL] Populating missing dates in postgresql data

2015-03-27 Thread David G. Johnston
On Fri, Mar 27, 2015 at 3:41 AM, Vincent Veyron wrote: > On Thu, 26 Mar 2015 00:25:09 + > "Lavrenz, Steven M" wrote: > > > I have a second table (TABLE B) with all of the object_ids and channels > that are supposed to be reporting in each day. For cases where a certain > channel does not che

Re: [GENERAL] Building JSON objects

2015-03-27 Thread David G. Johnston
On Fri, Mar 27, 2015 at 11:31 AM, Jan de Visser wrote: > On March 27, 2015 01:12:52 PM Eli Murray wrote: > > ERROR: syntax error at or near "json_build_object" > > LINE 1: insert into json(data) json_build_object(SELECT DISTINCT dep... > > You may want to review the syntax of the INSERT command,

Re: [GENERAL] Building JSON objects

2015-03-27 Thread David G. Johnston
On Fri, Mar 27, 2015 at 12:30 PM, Eli Murray wrote: > Thanks to you all for the replies. Adrian, your solution is working for me > without errors but it's not actually inserting anything. I'll keep fiddling > with it and see if I can get what I want but I'm confident now that I'm on > the right p

Re: [GENERAL] Alias field names in foreign data wrapper?

2015-03-27 Thread David G. Johnston
On Fri, Mar 27, 2015 at 1:55 PM, Deven Phillips wrote: > Better example of the problem... My FDW table schema is: > > CREATE FOREIGN TABLE liquorstore_backendipaddress ( > id bigint NOT NULL, > backend_network_id bigint, > backend_virtual_interface_id bigint, > address character v

Re: [GENERAL] store and retrieve html in postgres from rails

2015-03-30 Thread David G. Johnston
On Mon, Mar 30, 2015 at 1:06 PM, john.tiger wrote: > want to include html text from newsletters into postgres - then retrieve > > have seen posts saying this is really difficult (?) and others just > sugesting pg_escape_string and pg entities - > tried to put into text field but it seems stripped

Re: [GENERAL] how to convert float to timestamp in single select query

2015-03-31 Thread David G. Johnston
On Sun, Mar 29, 2015 at 8:52 PM, Maulik Shah wrote: > Dear Sir/Madam > > > how to convert float to timestamp in single select query > > for exp. i have float as 1.251152515236 , > > i want to convert this to datetime and from datetime to timestamp... > i.e. 02:22:044456 > ​You imply that (float)

Re: [GENERAL] Strange behavior of insert CTE with trigger

2015-04-01 Thread David G. Johnston
On Fri, Mar 27, 2015 at 4:18 PM, Anil Menon wrote: > Hi, > > I am trying to wrap my head around a strange problem I am having. I have > double checked the documentation but I could not find anything on this. > > ​[...]​ > > However I get no rows returned from the select statement- looks the >

Re: [GENERAL] Creating a non-strict custom aggregate that initializes to the first value

2015-04-01 Thread David G. Johnston
On Thu, Mar 26, 2015 at 1:49 PM, Timothy Garnett wrote: > > but if that is declared strict then it would take the first non-null value > and return A in my second example, if declared non-strict then the initial > state would be fed as null rather then the first value. Is there a way to > declare

Re: [GENERAL] partitoning expert : Partitonning with specialization of one column type

2015-04-01 Thread David G. Johnston
On Wed, Apr 1, 2015 at 7:26 AM, Rémi Cura wrote: > pcpatch(n) are specialization of pcpatch type. > ​While this may be true PostgreSQL doesn't understand "specialization" of data types. If you cannot do as Steven suggested you do not get to leverage inheritance directly and will need to devise

Re: [GENERAL] Why doesn't `RAISE EXCEPTION` provide error context?

2015-04-02 Thread David G. Johnston
Adding "raw" content present on Nabble that gets filtered by the mailing list. On Wednesday, April 1, 2015, Taytay wrote: > We make heavy use of `GET STACKED DIAGNOSTICS` to determine where errors > happened. > However, I am trying to use RAISE EXCEPTION to report errors, and have > discovered t

Re: [GENERAL] Why doesn't `RAISE EXCEPTION` provide error context?

2015-04-02 Thread David G. Johnston
On Thursday, April 2, 2015, Pavel Stehule wrote: > > > 2015-04-02 9:13 GMT+02:00 David G. Johnston >: > >> Adding "raw" content present on Nabble that gets filtered by the mailing >> list. >> >> On Wednesday, April 1, 2015, Taytay > > wrot

Re: [GENERAL] now() vs 'epoch'::timestamp

2015-04-02 Thread David G. Johnston
On Thu, Apr 2, 2015 at 10:27 AM, James Cloos wrote: > > "SC" == Steve Crawford writes: > > SC> Very convoluted calculation as others have noted. As to why it is > SC> "off", you are casting one part of the statement to an integer thus > SC> truncating the microseconds but are not doing the s

Re: [GENERAL] The case of PostgreSQL on NFS Server (II)

2015-04-02 Thread David G. Johnston
On Thu, Apr 2, 2015 at 1:01 PM, Octavi Fors wrote: > I don't see how to migrate the databases from my desktop directory > determined in a) to my NAS. Could someone please provide the steps to > accomplish that? > ALTER DATABASE name SET TABLESPACE new_tablespace ​You are solely responsible for

Re: [GENERAL] The case of PostgreSQL on NFS Server (II)

2015-04-02 Thread David G. Johnston
On Thu, Apr 2, 2015 at 5:09 PM, Octavi Fors wrote: > Thanks John for your extensive and helpful response. > > I have a NAS box. But I would worry about responsiveness. What is >> better, IMO, is an external SATA connected DAS box. DAS is "Direct >> Attached Storage". Many PCs have a eSATA port on

Re: [GENERAL] ERROR: out of memory

2015-04-02 Thread David G. Johnston
On Thu, Apr 2, 2015 at 5:24 PM, Dzmitry Nikitsin wrote: > Hey folks, > I have 4 postgresql servers 9.3.6(on master I use 9.3.5) configured with > streaming replication - with 1 maser(30GB RAM, processor - Intel Xeon > E5-2680 v2) and 3 slaves(61 Intel Xeon E5-2670 v2), all on Ubuntu 14.04.1 > L

Re: [GENERAL] ERROR: out of memory

2015-04-02 Thread David G. Johnston
On Thursday, April 2, 2015, Melvin Davidson wrote: > Well right of the bat, if your master shared_buffers = 7GB and 3 slaves > shared_buffers = 10GB, that is 37GB total, which means you are guaranteed > to exceed the 30GB physical limit on your machine. > I don't get why you are adding these tog

Re: [GENERAL] Overlap function for hstore?

2015-04-03 Thread David G. Johnston
On Fri, Apr 3, 2015 at 5:37 PM, Stefan Keller wrote: > Hi, > > I'd like to get an overlap function similar to '&&' but for key-value > pairs of hstore! > > This underfits: > > postgres=# select hstore_to_array('a=>1,b=>2,c=>3'::hstore) && > hstore_to_array('a=>2,d=>4,b=>2'::hstore) > > ...because

Re: [GENERAL] Problems with casting

2015-04-07 Thread David G. Johnston
On Tue, Apr 7, 2015 at 3:09 PM, Jim Nasby wrote: > On 4/7/15 4:35 PM, Tom Lane wrote: > >> Jim Nasby writes: >> >>> On 4/7/15 4:17 PM, Tom Lane wrote: >>> I suspect that that's only the tip of the iceberg. Remember the mess we had with implicit casts to text? And those only existed f

Re: [GENERAL] Using array_agg in pgr_kdisjkstrpath() error

2015-04-10 Thread David G. Johnston
On Thursday, April 9, 2015, Marc-André Goderre wrote: > Hello all, > I hope someone will can help me. > > Then, where's the difference between the result of (select > array_agg(end_id::integer)::integer[] as id from n2) AND '{28411,25582}' > There isn't...though technically the former is an int

Re: [GENERAL] Limiting user from changing its own attributes

2015-04-11 Thread David G. Johnston
On Friday, April 10, 2015, Sameer Kumar wrote: > On Sat, Apr 11, 2015 at 12:57 AM David G. Johnston < > david.g.johns...@gmail.com > > wrote: > >> On Fri, Apr 10, 2015 at 9:01 AM, Sameer Kumar > > wrote: >> > > Yes either an upper bound to which users ca

Re: [GENERAL] Limiting user from changing its own attributes

2015-04-13 Thread David G. Johnston
On Sun, Apr 12, 2015 at 10:23 PM, Sameer Kumar wrote: > > On Mon, Apr 13, 2015 at 1:03 PM Jim Nasby > wrote: > >> >> No. I suspect the community would support at least a hook for GUC >> changes, if not a full-on permissions system. A hook would make it >> fairly easy to add event trigger support

Re: [GENERAL] bigserial continuity safety

2015-04-13 Thread David G. Johnston
On Mon, Apr 13, 2015 at 3:05 PM, Pawel Veselov wrote: > Hi. > > If I have a table created as: > > CREATE TABLE xq_agr ( > idBIGSERIAL PRIMARY KEY, > node text not null > ); > > and that multiple applications insert into. The applications never > explicitly specify

Re: [GENERAL] Help with slow table update

2015-04-13 Thread David G. Johnston
On Mon, Apr 13, 2015 at 5:01 PM, Pawel Veselov wrote: > > r_agrio_hourly - "good", r_agrio_total - "bad". > > Update on r_agrio_hourly (cost=0.42..970.32 rows=250 width=329) (actual > time=2.248..2.248 rows=0 loops=1) >-> Index Scan using u_r_agrio_hourly on r_agrio_hourly > (cost=0.42..9

[GENERAL] With Update From ... vs. Update ... From (With)

2015-04-13 Thread David G. Johnston
Hello! Is there any non-functional difference between these two forms of Update? WITH name AS ( SELECT ) UPDATE tbl SET ... FROM name WHERE tbl.id = name.id and UPDATE tbl SET ... FROM ( WITH qry AS ( SELECT ) SELECT * FROM qry ) AS name WHERE tbl.id = name.id They both better give the same re

Re: [GENERAL] bigserial continuity safety

2015-04-13 Thread David G. Johnston
On Mon, Apr 13, 2015 at 7:01 PM, Jim Nasby wrote: > On 4/13/15 7:45 PM, David G. Johnston wrote: > >> On Mon, Apr 13, 2015 at 3:05 PM, Pawel Veselov > <mailto:pawel.vese...@gmail.com>>wrote: >> >> >> Hi. >> >> If I have a table cr

Re: [GENERAL] On using doubles as primary keys

2015-04-17 Thread David G. Johnston
On Fri, Apr 17, 2015 at 8:45 AM, Melvin Davidson wrote: > ​ > On Fri, Apr 17, 2015 at 11:34 AM, Kynn Jones wrote: > >> >> One consideration that is complication the choice of primary key >> is wanting to have the ability to store chunks of the data >> table (not the metadata table), including th

Re: [GENERAL] "Cast" SRF returning record to a table type?

2015-04-17 Thread David G. Johnston
On Friday, April 17, 2015, Jim Nasby wrote: > I'm working on a function that will return a set of test data, for unit > testing database stuff. It does a few things, but ultimately returns SETOF > record that's essentially: > > RETURN QUERY EXECUTE 'SELECT * FROM ' || table_name; > > Because it's

Re: [GENERAL] "Cast" SRF returning record to a table type?

2015-04-17 Thread David G. Johnston
On Friday, April 17, 2015, Jim Nasby wrote: > On 4/17/15 7:39 PM, David G. Johnston wrote: > >> On Friday, April 17, 2015, Jim Nasby > <mailto:jim.na...@bluetreble.com>> wrote: >> >> I'm working on a function that will return a set of test data, f

Re: [GENERAL] [SQL] function to send email with query results

2015-04-17 Thread David G. Johnston
On Friday, April 17, 2015, Suresh Raja wrote: > Hi all: > > I'm looking to write a function to send email with result of a query. > Is it possible to send email with in a function. Any help is appreciated. > > Yes...though neither the neither the sql nor the plpgsql languages have the necessary

Re: [GENERAL] "Cast" SRF returning record to a table type?

2015-04-20 Thread David G. Johnston
On Mon, Apr 20, 2015 at 7:57 AM, Merlin Moncure wrote: > On Sat, Apr 18, 2015 at 5:37 PM, Jim Nasby > wrote: > > On 4/18/15 12:47 AM, David G. Johnston wrote: > >> > >> If you could find a way to pass a value of type some_table into the > >> function

Re: [GENERAL] "Cast" SRF returning record to a table type?

2015-04-20 Thread David G. Johnston
On Mon, Apr 20, 2015 at 9:40 AM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Mon, Apr 20, 2015 at 7:57 AM, Merlin Moncure > wrote: > >> On Sat, Apr 18, 2015 at 5:37 PM, Jim Nasby >> wrote: >> > On 4/18/15 12:47 AM, David G. Johnston wrote: &g

Re: [GENERAL] delete is getting hung when there is a huge data in table

2015-05-02 Thread David G. Johnston
On Saturday, May 2, 2015, Mitu Verma wrote: > > still this delete operation is not working and not a single row has been > deleted from the table. > > Because of MVCC other sessions are not able to see partial deletions...and as you aluded to knowing the data itself is not actually removed by a d

Re: [GENERAL] Errors using JDBC batchUpdate with plpgsql function

2015-05-03 Thread David G. Johnston
On Sun, May 3, 2015 at 2:33 PM, Nanker Phelge wrote: > inner ex 2 =A result was returned when none was expected. > > ​I don't know what is or is not allowed by JDBC but it is reasonable to assume that you cannot create batches of SELECT statements. The intent of batching is to repeatedly execute

Re: [GENERAL] Limiting user from changing its own attributes

2015-05-04 Thread David G. Johnston
On Mon, May 4, 2015 at 10:23 PM, Sameer Kumar wrote: > Sorry about the long silence on this. > > On Mon, Apr 13, 2015 at 3:34 PM David G. Johnston < > david.g.johns...@gmail.com> wrote: > >> On Sun, Apr 12, 2015 at 10:23 PM, Sameer Kumar >> wrote: >>

Re: [GENERAL] Unexpected function behaviour with NULL and/or default NULL parameters

2015-05-06 Thread David G. Johnston
On Wednesday, May 6, 2015, Gunnar "Nick" Bluth wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hello, > > I'm experiencing odd behaviour with a function I wrote yesterday. > > Background: function is supposed to deliver some "terms and > conditions" from a table; when the "locale" is

Re: [GENERAL] Unexpected function behaviour with NULL and/or default NULL parameters

2015-05-06 Thread David G. Johnston
Wednesday, May 6, 2015, Gunnar "Nick" Bluth wrote: > -BEGIN PGP SIGNED MESSAGE- > CREATE OR REPLACE FUNCTION > public.get_current_tac(userid bigint, sessionid uuid, locale character > varying, OUT current_tac json) > RETURNS json > LANGUAGE sql > IMMUTABLE STRICT SECURITY DEFINER > AS

Re: [GENERAL] detached query?

2015-05-06 Thread David G. Johnston
On Wed, May 6, 2015 at 3:37 PM, Yves Dorfsman wrote: > > On 9.3, is there any way to start a query, detach from the server and have > the > query keep going (long query that updates tables, but nothing is returned)? > ​No. Sessions require an external client to maintain its connection. David J

Re: [GENERAL] Why is there no object create date is the catalogs?

2015-05-12 Thread David G. Johnston
On Tue, May 12, 2015 at 6:33 PM, Melvin Davidson wrote: > I thank everyone for their feedback regarding the omission of object > creation date from the catalog. > > I do respect the various reasons for not including it, but I feel it is my > duty to draw out this issue a bit longer. > > I would

Re: [GENERAL] Dry run through input function for a given built-in data type

2015-05-12 Thread David G. Johnston
On Tue, May 12, 2015 at 11:23 PM, Fabio Ugo Venchiarutti wrote: > Is there any cleaner way to, say, only run the validation part of a type > input function > ​ [...]​ > ​This pre-supposes that said type input function has a distinct validation phase as opposed to simply performing its parse and

Re: [GENERAL] SELECT INTO and ON COMMIT

2015-05-13 Thread David G. Johnston
On Wed, May 13, 2015 at 4:38 PM, Bruce Momjian wrote: > On Wed, May 13, 2015 at 05:29:36PM -0600, Yves Dorfsman wrote: > > > > Is there any way to add an ON COMMIT clause to a SELECT INTO TEMP TABLE? > > Well CREATE TABLE has a ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } > clause, but I don'

Re: [GENERAL] Grouping By Similarity (using pg_trgm)?

2015-05-14 Thread David G. Johnston
On Thu, May 14, 2015 at 11:58 AM, Cory Tucker wrote: > [pg version 9.3 or 9.4] > > Suppose I have a simple table: > > create table data ( > my_value TEXT NOT NULL > ); > CREATE INDEX idx_my_value ON data USING gin(my_value gin_trgm_ops); > > > Now I would like to essentially do group by to get

Re: [GENERAL] Grouping By Similarity (using pg_trgm)?

2015-05-14 Thread David G. Johnston
On Thu, May 14, 2015 at 1:09 PM, Cory Tucker wrote: > That produces pretty much the same results as the CROSS JOIN I was using > before. Because each "my_value" in the table are different, if I group on > just their value then I will always have the full result set and a bunch of > essentially d

Re: [GENERAL] Consistent state for pg_dump and pg_dumpall

2015-05-20 Thread David G. Johnston
Yes. The entire dump is performed within a single transaction. On Wed, May 20, 2015 at 9:24 AM, Michael Nolan wrote: > The documentation for pg_dump says that dump files are created in a > consistent state. > > Is that true across multiple tables in the same pg_dump command? > (Obviously it wou

Re: [GENERAL] Replicate over pgbouncer?

2015-05-21 Thread David G. Johnston
On Thursday, May 21, 2015, Andomar wrote: > Hi, > > Today I installed pgbouncer. I added a second installation as a hot > standby. Before starting the standby, I configured "recovery.conf" to > connect to pgbouncer. > > This results in an error message: > > Pooler Error: Unsupported startup

Re: [GENERAL] date with month and year

2015-05-21 Thread David G. Johnston
On Thursday, May 21, 2015, Daniel Torres wrote: > I everybody, I'm new in the Postgresql world, and have an easy question: > Is it possible to have date type data that only contain month and year?, > how can I obtain that from a timestamp (without time zone) column? > > I've made this, but I thin

Re: [GENERAL] About COPY command (and probably file fdw too)

2015-05-21 Thread David G. Johnston
On Thu, May 21, 2015 at 1:33 PM, Nicolas Paris wrote: > Hi, > > To me this would be great. Why not the ability to restrict lines too > COPY stafflist (userid, username, staffid) > FROM 'myfile.txt' > WITH (FORMAT text, DELIMITER E'\t', COLUMNS (1, 2, 7), > LINES(2:1000,2000:3000), ENCODING 'windo

Re: [GENERAL] date with month and year

2015-05-21 Thread David G. Johnston
On Thu, May 21, 2015 at 2:10 PM, Paul Jungwirth wrote: > Anyway, I agree that you have to store the time zone *somewhere*, and I > suppose that's the reason Joshua remarked that you really shouldn't use > WITHOUT TIME ZONE. And often a time has one perspective that is "canonical" > or "preferred"

Re: [GENERAL] FW: Constraint exclusion in partitions

2015-05-22 Thread David G. Johnston
On Fri, May 22, 2015 at 10:21 AM, Daniel Begin wrote: > But how constraint exclusion would react with the following queries … > > b- Select * from parent_table where id between 2345 and 6789; -- > using a range of ids > ​Not sure... ​ These are constants but I'm not sure how smart the plann

Re: [GENERAL] PG and undo logging

2015-05-23 Thread David G. Johnston
On Sat, May 23, 2015 at 1:34 PM, Ravi Krishna wrote: > Is it true that PG does not log undo information, only redo. If true, > then how does it bring a database back to consistent state during > crash recovery. Just curious. > ​What does "undo" mean? David J.​

Re: [GENERAL] [NOVICE] Constraint exclusion in partitions

2015-05-23 Thread David G. Johnston
On Saturday, May 23, 2015, Daniel Begin wrote: > I am working with postgresql 9.3 and I understand from the documentation > that constraint_exclusion is set to “partition” by default. Looking at my > postgres.conf file, the concerned line is “#constraint_exclusion = > partition”. > > Furthermore,

Re: [GENERAL] PG and undo logging

2015-05-23 Thread David G. Johnston
On Saturday, May 23, 2015, Ravi Krishna wrote: > undo means that reading the WAL logs and able to rollback a row back > to its original state before the update. Typically it is used to > rollback a long running transaction which got aborted due to a crash. > Here is an example: > > Not an expert

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread David G. Johnston
On Saturday, May 30, 2015, Glen M. Witherington wrote: > Sorry about the horrendous subject, let me explain by example: > > Let's take this schema: > > > ``` > CREATE TABLE a ( > id bigserial PRIMARY KEY, > created_at timestamp with time zone NOT NULL DEFAULT NOW() > ); > > CREATE TABLE b(

Re: [GENERAL] Problem when temp_tablespace get full?

2015-06-03 Thread David G. Johnston
On Wed, Jun 3, 2015 at 11:14 AM, Daniel Begin wrote: > > A query > ​OK...​ But ma question is: What append the temp_tablespace drive get full? > ​The query, probably... "There is also a temp_tablespaces parameter, which determines the placement of temporary tables and indexes, as well as temp

Re: [GENERAL] pg_start_backup does not actually allow for consistent, file-level backup

2015-06-08 Thread David G. Johnston
On Mon, Jun 8, 2015 at 9:26 AM, otheus uibk wrote: > On Mon, Jun 8, 2015 at 3:13 PM, otheus uibk wrote: > >> Thank you, all. The manual for 9.4 is indeed clearer on this point than >> the 9.1 version. >> > > Just to nit-pick, I see nowhere in either version of the manual the > indication that i

Re: [GENERAL] user constructed where clause

2015-06-09 Thread David G. Johnston
On Tue, Jun 9, 2015 at 4:48 AM, Yelai, Ramkumar IN BLR STS < ramkumar.ye...@siemens.com> wrote: > Now, the requirement is if user provides filter information based on > every column from the web UI, this filter will let the user construct the > “where clause” and provide to postgresql. > In a mon

Re: [GENERAL] Random order by but first 3

2015-06-11 Thread David G. Johnston
On Thu, Jun 11, 2015 at 12:35 PM, Arup Rakshit wrote: > Hi, > > Suppose I have a column t1 for a table. Now t1 holds some numerice value > for each row. Say R1 to R5 records has values for the column t1 as : > > t1(2,5,8,10,32) > > I want the result to be printed as (10, 32, 8, 2, 5) means - Big,

Re: [GENERAL] support for ltree

2015-06-12 Thread David G. Johnston
On Friday, June 12, 2015, Michael Shapiro wrote: > Hi Melvin, > > Thanks for this response. It still leave my question unanswered. I should > rephrase it -- will become a native datatype in Postgres (as > opposed to remaining an extension). Are there any plans to make a > native datatype? > In

Re: [GENERAL] support for ltree

2015-06-12 Thread David G. Johnston
On Friday, June 12, 2015, Michael Shapiro wrote: > > The reason I am asking is that, although ltree seems to have been a > contributed module since at least 8.3, how can one know if it will always > be part of subsequent versions of Postgres? > Whether contrib, core, or an external extension you

[GENERAL] Suggested (or existing) way to parse currency into numeric?

2015-06-12 Thread David G. Johnston
Version 9.3 CREATE TABLE t ( field numeric NULL ); SELECT * FROM json_populate_record(null::t, '{ "field": "$18,665" }'::json); Error: invalid input syntax for type numeric: "$18,665" I can accept the type of field being something like "numeric_cleaned" which has a custom input function that would

Re: [GENERAL] Suggested (or existing) way to parse currency into numeric?

2015-06-12 Thread David G. Johnston
On Fri, Jun 12, 2015 at 12:57 PM, Adrian Klaver wrote: > On 06/12/2015 09:46 AM, David G. Johnston wrote: > >> Version 9.3 >> CREATE TABLE t ( field numeric NULL ); >> SELECT * FROM json_populate_record(null::t, '{ "field": "$18,665" >> }&#

Re: [GENERAL] Suggested (or existing) way to parse currency into numeric?

2015-06-12 Thread David G. Johnston
> > >> ​I wrote that type off as something I would never code into my own >> schema so basically forgot about its usability in other situations. >> > > Though if you do not want to use the money type in a table you could do: > > test=> select '$18,665'::money::numeric; > numeric > -- > 18

Re: [GENERAL] PL/pgSQL: How to return two columns and multiple rows

2015-06-18 Thread David G. Johnston
On Thursday, June 18, 2015, Sven Geggus wrote: > Hello, > > I supose this is simple, but I did not find a solution in the > documentation. > > I would like to be able to do something like this: > > select myfunc('foo','bar'); > or > select myfunc(foo, bar) from foobartable; > or even > select myf

Re: [GENERAL] PL/pgSQL: How to return two columns and multiple rows

2015-06-18 Thread David G. Johnston
On Thursday, June 18, 2015, Chris Travers wrote: > > > Select (myfunc('foo','bar')).*; > > > This should be avoided. Use lateral instead,or a cte a/o offset 0. My_func is evaluated twice (once per column) if called this way > > Or > Select * from myfunc('foo','bar'); > This is ok David J.

Re: [GENERAL] PL/pgSQL: How to return two columns and multiple rows

2015-06-18 Thread David G. Johnston
On Thu, Jun 18, 2015 at 9:32 AM, Sven Geggus wrote: > David G. Johnston wrote: > > > Look at the "returns table (col1 type, col2 type)" form. > > If I got this right "returns table" is not what I want as I need to select > from my function as a virtua

Re: [GENERAL] PL/pgSQL: How to return two columns and multiple rows

2015-06-18 Thread David G. Johnston
On Thu, Jun 18, 2015 at 9:52 AM, Sven Geggus wrote: > Raymond O'Donnell wrote: > > >> mydb=> select myfunc('foo','bar'); > > > > You need to do: > > > >select * from myfunc('foo','bar'); > > This has been a misguided example. Reality should more likely look like > this: > > select myfunc(col

Re: [GENERAL] PL/pgSQL: How to return two columns and multiple rows

2015-06-18 Thread David G. Johnston
On Thu, Jun 18, 2015 at 10:31 AM, Sven Geggus wrote: > David G. Johnston wrote: > > WITH exec_func AS ( SELECT myfunc(col1,col2) FROM mytable ) > > SELECT (exec_func.myfunc).* FROM exec_func; > > > > This relies on the fact that currently a CTE introduces an optim

Re: [GENERAL] PL/pgSQL: How to return two columns and multiple rows

2015-06-18 Thread David G. Johnston
On Thu, Jun 18, 2015 at 12:00 PM, Sven Geggus wrote: > David G. Johnston wrote: > > > Assuming you are on 9.3+ what you want to use is LATERAL > > OK, how is such a query supposed to look like? > > assuming "select myfunc(col1,col2) from mytable" wor

[GENERAL] Trying to avoid a simple temporary variable declaration in a pl/pgsql function

2015-06-20 Thread David G. Johnston
I know this could be written quite easily in sql but was wondering if it is possible in pl/pgsql. CREATE FUNCTION test_func() RETURNS text LANGUAGE 'plpgsql' AS $$ BEGIN SELECT 'text_to_return' INTO ; --with or without a cast RETURN ; END; $$; The goal is to return the value of text_to_return wit

Re: [GENERAL] Trying to avoid a simple temporary variable declaration in a pl/pgsql function

2015-06-20 Thread David G. Johnston
On Sat, Jun 20, 2015 at 10:56 AM, Tom Lane wrote: > "David G. Johnston" writes: > > I know this could be written quite easily in sql but was wondering if it > is > > possible in pl/pgsql. > > > CREATE FUNCTION test_func() > > RETURNS text > >

Re: [GENERAL] checking for NULLS in aggregate

2015-06-24 Thread David G. Johnston
On Wed, Jun 24, 2015 at 12:54 PM, Seb wrote: > Hello, > > I've defined a function to calculate standard deviation of angular > values: > > CREATE AGGREGATE public.stddev(angle_vectors) ( > SFUNC=array_append, > STYPE=angle_vectors[], > FINALFUNC=angle_vectors_stddev_yamartino > ); > > The t

Re: [GENERAL] INSERT a real number in a column based on other columns OLD INSERTs

2015-06-24 Thread David G. Johnston
On Wed, Jun 24, 2015 at 5:52 PM, Adrian Klaver wrote: > On 06/23/2015 11:20 PM, litu16 wrote: > >> >> So, this is what I have made so far... >> >> *CREATE OR REPLACE FUNCTION timelog() >>RETURNS trigger AS >> $BODY$ >> DECLARE >> t_ix real; >> n int; >> >> BEG

Re: [GENERAL] Correct place for feature requests

2015-06-25 Thread David G. Johnston
On Thu, Jun 25, 2015 at 3:29 PM, John R Pierce wrote: > On 6/25/2015 11:59 AM, Алексей Бережняк wrote: > >> I think that PostgreSQL is great RDBMS, but one important (for me) >> feature that it missing is case-insensitive identifier quotes >> ([table].[column]) like in Microsoft SQL Server. >> >

Re: [GENERAL] Functions, savepoints, autocommit = I am confused !

2015-06-26 Thread David G. Johnston
On Fri, Jun 26, 2015 at 9:38 AM, Tim Smith wrote: > I have a function that validates a web session is still active, so my > code looks something like this : > > BEGIN > perform app_security.cleanSessionTable(p_forcedTimeout,p_sessionTimeout); > SAVEPOINT sp_cleanedSessionTable; > select * into st

Re: [GENERAL] Functions, savepoints, autocommit = I am confused !

2015-06-26 Thread David G. Johnston
On Fri, Jun 26, 2015 at 10:48 AM, Tim Smith wrote: > Hi David, > > I should have perhaps made clear this was a saved function, so my > understanding is ROLLBACK can't be used as its implicit. > ​I am pretty certain "ROLLBACK" cannot be used but the "ROLLBACK TO SAVEPOINT" can - they are and do t

  1   2   3   4   5   6   7   8   9   10   >