Re: Format an Update with calculation

2018-12-17 Thread Pavel Stehule
út 18. 12. 2018 v 8:15 odesílatel Bret Stern < bret_st...@machinemanagement.com> napsal: > My statement below updates the pricing no problem, but I want it to be > formatted with 2 dec points eg (43.23). > > Started playing with to_numeric but can't figure it out. Lots of examples > with to_char

Format an Update with calculation

2018-12-17 Thread Bret Stern
My statement below updates the pricing no problem, but I want it to be formatted with 2 dec points eg (43.23). Started playing with to_numeric but can't figure it out. Lots of examples with to_char in the manual, but still searching for answer. Can it be done? I want suggested_retail_price to

Re: IF NOT EXIST

2018-12-17 Thread Pavel Stehule
Hi út 18. 12. 2018 v 7:11 odesílatel Igor Korot napsal: > Hi, ALL, > I have a following statement: > > IF NOT EXIST( SELECT 1 SELECT 1 FROM pg_proc AS proc, pg_namespace AS > ns ) CREATE FUNCTION(); > > Unfortunately trying to execute it thru the ODBC interface with: > > ret = SQLExecDirect(

IF NOT EXIST

2018-12-17 Thread Igor Korot
Hi, ALL, I have a following statement: IF NOT EXIST( SELECT 1 SELECT 1 FROM pg_proc AS proc, pg_namespace AS ns ) CREATE FUNCTION(); Unfortunately trying to execute it thru the ODBC interface with: ret = SQLExecDirect( m_hstmt, query, SQL_NTS ); gives syntax error near IF. What is the proper

Re: Creating 2D arrays for pg_copy_from, reading tab-delimited text file that contains comma and double quotes

2018-12-17 Thread s400t
Hello Rob, Thank you for your comments. As I wrote just a few minutes ago, using a tab delimiter inside the implode as suggested by Daniel (and specifying the read length ("0") for the fgetcsv has solved this problem. At one point, I had tried to use the last parameter - enclosure character -

Re: Creating 2D arrays for pg_copy_from, reading tab-delimted text file that contains comma and double quotes

2018-12-17 Thread s400t
>and now I can see my data saved in the database without those extra double >quotes. .. and with my comma intact as well. - Original Message - > From: "s4...@yahoo.co.jp" > To: Daniel Verite > Cc: "pgsql-general@lists.postgresql.org" > Date: 2018/12/18, Tue 14:15 > Subject: Re:

Re: Creating 2D arrays for pg_copy_from, reading tab-delimted text file that contains comma and double quotes

2018-12-17 Thread s400t
Hello Daniel! This afternoon, I tried it again, and yes, your suggestion that I use a tab delimited symbol ("\t") instead of a space for the implode works flawlessly. Yesterday, I reported I got "Warning: pg_copy_from(): Copy command failed: ERROR: extra data after last expected..". That was

Does idle sessions will consume more cpu and ram? If yes,how to control them

2018-12-17 Thread Raghavendra Rao J S V
In my application, the idle sessions are consuming cpu and ram. refer the ps command output. How idle session will consume more ram/cpu? How to control it? We are using Postgresql 9.2 with Centos 6 os. Please guide me. [image: image.png] -- Regards, Raghavendra Rao J S V Mobile- 8861161425

How to insert bulk data with libpq in C?

2018-12-17 Thread a
May I ask the proper (fast) way of inserting bulk data and if possible, an example would be very appreciated. Please note that the data I would like to insert contains arrays (float8[]). By the way, my environment is Windows 10, PostgreSQL 11 and compiling with Visual Studio 2017.

Re: Alter table column constraint [RESOLVED]

2018-12-17 Thread Rich Shepard
On Mon, 17 Dec 2018, Ron wrote: Melvin is saying to: 1. create a table named valid_industry, 2. populate it with the valid industries, 3. create an FK constraint on your main table's industry column to valid_industry.industry, and then 4. drop the constraint invalid_industry. Got it.

Re: NL Join vs Merge Join - 5 hours vs 2 seconds

2018-12-17 Thread David Rowley
On Tue, 18 Dec 2018 at 09:21, Kumar, Virendra wrote: > I tried query with function dependency statistics but it did not help. I > don't see we can create such statistics on table join. There's mention of why this is the case in the docs in [1]: "14.2.2.1.1. Limitations of Functional

Re: Alter table column constraint

2018-12-17 Thread Adrian Klaver
On 12/17/18 12:20 PM, Rich Shepard wrote: On Mon, 17 Dec 2018, Melvin Davidson wrote: Yes, you must drop then add the revised constraint. However, from your statement above, it sounds to me as if you would be better off using A FOREIGN kEY CONSTRAINT. It makes things a lot simpler. Melvin,

Re: Alter table column constraint

2018-12-17 Thread Melvin Davidson
See https://www.postgresql.org/docs/current/tutorial-fk.html On Mon, Dec 17, 2018 at 3:32 PM David G. Johnston < david.g.johns...@gmail.com> wrote: > On Mon, Dec 17, 2018 at 1:20 PM Rich Shepard > wrote: > > > > On Mon, 17 Dec 2018, Melvin Davidson wrote: > > > > > Yes, you must drop then add

Re: Alter table column constraint

2018-12-17 Thread Melvin Davidson
So CREATE a table eg: CREATE TABLE fks_for_tables ( fks_id serial fks_values varchar(20), CONSTRAINT fks_pkey PRIMARY KEY (fks_id), CONSTRAINT fks-unique UNIQUE fks_values ) Then INSERT INTO fks_for_tables (fks_values) VALUES ( 'Agriculture'), ('Business'), ('other))', 'Chemicals') ... ...

Re: Alter table column constraint

2018-12-17 Thread David G. Johnston
On Mon, Dec 17, 2018 at 1:20 PM Rich Shepard wrote: > > On Mon, 17 Dec 2018, Melvin Davidson wrote: > > > Yes, you must drop then add the revised constraint. However, from your > > statement above, it sounds to me as if you would be better off using A > > FOREIGN kEY CONSTRAINT. It makes things a

Re: Alter table column constraint

2018-12-17 Thread Ron
On 12/17/2018 02:20 PM, Rich Shepard wrote: On Mon, 17 Dec 2018, Melvin Davidson wrote: Yes, you must drop then add the revised constraint. However, from your statement above, it sounds to me as if you would be better off using A FOREIGN kEY CONSTRAINT. It makes things a lot simpler. Melvin,

RE: NL Join vs Merge Join - 5 hours vs 2 seconds

2018-12-17 Thread Kumar, Virendra
Thank you Tom for initial thoughts! I tried query with function dependency statistics but it did not help. I don't see we can create such statistics on table join. Regards, Virendra -Original Message- From: Tom Lane [mailto:t...@sss.pgh.pa.us] Sent: Monday, December 17, 2018 12:02 PM

Re: Alter table column constraint

2018-12-17 Thread Rich Shepard
On Mon, 17 Dec 2018, Melvin Davidson wrote: Yes, you must drop then add the revised constraint. However, from your statement above, it sounds to me as if you would be better off using A FOREIGN kEY CONSTRAINT. It makes things a lot simpler. Melvin, I don't follow. Here's the DDL for that

Re: Alter table column constraint

2018-12-17 Thread Melvin Davidson
>I want to alter a term in a column's constraint to allow only specified > strings as attributes Yes, you must drop then add the revised constraint. However, from your statement above, it sounds to me as if you would be better off using A FOREIGN kEY CONSTRAINT. It makes things a lot simpler. On

Re: Alter table column constraint

2018-12-17 Thread Joshua D. Drake
On 12/17/18 12:01 PM, Rich Shepard wrote: On Mon, 17 Dec 2018, Rich Shepard wrote: I want to alter a term in a column's constraint to allow only specified strings as attributes and have not found how to do this in the docs (using version 10 docs now). There is an alter table command that

Re: Alter table column constraint

2018-12-17 Thread Rich Shepard
On Mon, 17 Dec 2018, Rich Shepard wrote: I want to alter a term in a column's constraint to allow only specified strings as attributes and have not found how to do this in the docs (using version 10 docs now). There is an alter table command that allows renaming a constraint but I've not seen

Alter table column constraint

2018-12-17 Thread Rich Shepard
I want to alter a term in a column's constraint to allow only specified strings as attributes and have not found how to do this in the docs (using version 10 docs now). There is an alter table command that allows renaming a constraint but I've not seen how to modify the constraint itself.

Re: Creating 2D arrays for pg_copy_from, reading tab-delimted text file that contains comma and double quotes

2018-12-17 Thread s400t
Hi Daniel, Thank you for the comments. I changed my line 7 to this: $line = implode("\t",$line). "\n"; Now, I get the following. Warning: pg_copy_from(): Copy command failed: ERROR: extra data after last expected column CONTEXT: COPY test_table, line 1: "1    Denny's    orange juice     "1   

Re: NL Join vs Merge Join - 5 hours vs 2 seconds

2018-12-17 Thread Tom Lane
"Kumar, Virendra" writes: > We are using Postgers-XL based on PostgreSQL 10.5 on RHEL7. We have an > extreme case of one query which running in 4 hour 45 mins and 33 seconds with > Nested Loops Join vs 2.5 seconds when we disable enable_nestloop. The query > is given below. I would be happy to

Re: conditionally terminate psql script

2018-12-17 Thread Ron
On 12/17/2018 09:01 AM, Jerry Sievers wrote: haman...@t-online.de writes: Hi, many thanks -- too bad I am still using 9.3 Just because your server backend is 9.3 does not rule out using much newer clients, such as psql. While technically true, and is useful, many production servers

Re: conditionally terminate psql script

2018-12-17 Thread Jerry Sievers
haman...@t-online.de writes: > Hi, > > many thanks -- too bad I am still using 9.3 Just because your server backend is 9.3 does not rule out using much newer clients, such as psql. HTH > > Best regards > Wolfgang > >>> Hi >>> >> po 17. 12. 2018 v 13:14 odesílatel napsal: >>> >> > >>> > >>> >

NL Join vs Merge Join - 5 hours vs 2 seconds

2018-12-17 Thread Kumar, Virendra
We are using Postgers-XL based on PostgreSQL 10.5 on RHEL7. We have an extreme case of one query which running in 4 hour 45 mins and 33 seconds with Nested Loops Join vs 2.5 seconds when we disable enable_nestloop. The query is given below. I would be happy to share more information if

Re: Creating 2D arrays for pg_copy_from, reading tab-delimted text file that contains comma and double quotes

2018-12-17 Thread Daniel Verite
wrote: > When I save that Excel as a tab delimited text file, I get this:rec_no > item1item2item3item4item5 > 1Denny'sorange juice"1,500 yen""""Dear John""""32"" > TV"(As seen when I opened that file with Notepad) This looks good. Fields are

Re: REVOKE to an user that doesn't exist

2018-12-17 Thread Moreno Andreo
Il 12/12/2018 16:01, Tom Lane ha scritto: The safest way to clean it up manually would be to set the pg_proc.proacl field for that function to NULL. If there are other grants about the function, you could try removing the bad entry, but it would likely be safer to just re-grant after the

Re: Creating 2D arrays for pg_copy_from, reading tab-delimted text file that contains comma and double quotes

2018-12-17 Thread rob stone
Hello, On Mon, 2018-12-17 at 21:34 +0900, s4...@yahoo.co.jp wrote: > Hello Good People of the Forum! > > I am trying to insert some data into a PostgreSQL database using PHP > and struggling to create an array so that pg_copy_from function will > accept and process the data. > > I can insert

Re: [External] Re: simple query on why a merge join plan got selected

2018-12-17 Thread Vijaykumar Jain
Thanks a lot Tom, as always :) We generally do not have so many duplicates in production, so maybe this is an edge case but I am happy with the explanation and the code reference for the analysis. I’ll also play with default statistic target to see what changes by increasing the value. On Sun,

Re: conditionally terminate psql script

2018-12-17 Thread hamann . w
Hi, many thanks, I will give it a try tomorrow Best regards Wolfgang >> >> On 17.12.2018 16:07, haman...@t-online.de wrote: >> > Hi, many thanks -- too bad I am still using 9.3 >> >> In this case you can try ON_ERROR_STOP psql variable. >> Something like this: >> >> \set ON_ERROR_STOP on >> >>

Re: conditionally terminate psql script

2018-12-17 Thread Pavel Luzanov
On 17.12.2018 16:07, haman...@t-online.de wrote: Hi, many thanks -- too bad I am still using 9.3 In this case you can try ON_ERROR_STOP psql variable. Something like this: \set ON_ERROR_STOP on do $$ declare     total bigint; begin     select count(*) into total from pg_class where 1=1;    

Re: conditionally terminate psql script

2018-12-17 Thread hamann . w
Hi, many thanks -- too bad I am still using 9.3 Best regards Wolfgang >> Hi >> >> po 17. 12. 2018 v 13:14 odesílatel napsal: >> >> > >> > >> > Hi, >> > >> > is there a way to stop execution of a psql script if a select returns some >> > rows (or no rows) >> > The idea is to add a safety check

Re: conditionally terminate psql script

2018-12-17 Thread Pavel Luzanov
Hi is there a way to stop execution of a psql script if a select returns some rows (or no rows) The idea is to add a safety check on data, specifically to select all new rows that would conflict on a bulk insert, show them and stop Look at \if command in psql (since v10): select count(*)

Re: conditionally terminate psql script

2018-12-17 Thread Pavel Stehule
Hi po 17. 12. 2018 v 13:14 odesílatel napsal: > > > Hi, > > is there a way to stop execution of a psql script if a select returns some > rows (or no rows) > The idea is to add a safety check on data, specifically to select all new > rows that would conflict > on a bulk insert, show them and

Creating 2D arrays for pg_copy_from, reading tab-delimted text file that contains comma and double quotes

2018-12-17 Thread s400t
Hello Good People of the Forum! I am trying to insert some data into a PostgreSQL database using PHP and struggling to create an array so that pg_copy_from function will accept and process the data. I can insert data but not the way I want- my data this case contains comma, space, double quotes

conditionally terminate psql script

2018-12-17 Thread hamann . w
Hi, is there a way to stop execution of a psql script if a select returns some rows (or no rows) The idea is to add a safety check on data, specifically to select all new rows that would conflict on a bulk insert, show them and stop Best regards Wolfgang

Re: loading jdbc Driver in servlet

2018-12-17 Thread Dave Cramer
On Mon, 17 Dec 2018 at 02:28, Thomas Kellerer wrote: > Rob Sargent schrieb am 14.12.2018 um 19:28: > > Using java 1.8, postgresql-42.1.4.jar, embedded tomcat 9 > > > > It appears to me that I need to make the call > > "Class.forName("org.postgresql.Driver)" when the entry is in a > > servlet.