Re: [GENERAL] #Personal#: Reg: Multiple queries in a transaction

2015-02-19 Thread David G Johnston
David G Johnston wrote Medhavi Mahansaria wrote Hi Bill, Thanks! But savepoint concept will not work for me as desired. Is there any other way apart from SAVEPOINT that can be incorporated. I am not using a script. I am writing a c++ program. My problem is that I have 2

[GENERAL] select where true, or select where input = '$var'

2015-02-19 Thread zach cruise
i want to select based on input, but if input is not provided or if input is empty, then i want to select all rows. 1 select * 2 from table 3 if input = '' then 4 where true 5 else 6 where input = '$sanitized_variable' 7 end if; (syntax error at 3) i also looked at 'case' but i don't think it

[GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Hello, i have created a function (in C) that receives an array that contains tuples of ID's and values. The function is to execute updates on each ID assigning the value, but if one of these operation fails (does not meet certain criteria) inside the function i would like to rollback and leave

Re: [GENERAL] select where true, or select where input = '$var'

2015-02-19 Thread Paul Jungwirth
i want to select based on input, but if input is not provided or if input is empty, then i want to select all rows. I think you can just use OR: SELECT * FROMtable WHERE (input = '' OR input = ?) This is assuming that `input` is a column in your table and ? is the user input, based

Re: [GENERAL] select where true, or select where input = '$var'

2015-02-19 Thread John R Pierce
On 2/19/2015 12:39 PM, zach cruise wrote: i want to select based on input, but if input is not provided or if input is empty, then i want to select all rows. (metalanguage) if input is provided, then query(SELECT stuff FROM table WHERE whatever = $INPUT)

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Chris Mair
The function is to execute updates on each ID assigning the value, but if one of these operation fails (does not meet certain criteria) inside the function i would like to rollback and leave everything untouched, in case other ID;s were already updated previously, and come back to the caller

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Hi Thanks Chris, yes i have already tested ereport and even made up my own sql state to report and error but from the application i can not access this error code directly (through the PQexec,PQresultErrorField,etc functions because the PGresult returns NULL) but i have to register a callback

Re: [GENERAL] select where true, or select where input = '$var'

2015-02-19 Thread Alban Hertroys
On 19 Feb 2015, at 21:39, zach cruise zachc1...@gmail.com wrote: i want to select based on input, but if input is not provided or if input is empty, then i want to select all rows. 1 select * 2 from table 3 if input = '' then 4 where true 5 else 6 where input =

Re: [GENERAL] Failure loading materialized view with pg_restore

2015-02-19 Thread Brian Sutherland
On Wed, Feb 18, 2015 at 10:34:33AM -0500, Tom Lane wrote: Brian Sutherland br...@vanguardistas.net writes: If I run this set of commands against PostgreSQL 9.4.1 I pg_restore throws an error with a permission problem. Why it does so is a mystery to me, given that the user performing the

Re: [GENERAL] #Personal#: Reg: Multiple queries in a transaction

2015-02-19 Thread Andrew Sullivan
On Thu, Feb 19, 2015 at 11:11:59AM +0530, Medhavi Mahansaria wrote: But savepoint concept will not work for me as desired. I don't see why not. Case 1: When Q2 fails (we delete the error), i want to continue to Q3 and commit changes done by Q1 and Q3 once Q3 has executed successfully.

Re: [GENERAL] #Personal#: Reg: Multiple queries in a transaction

2015-02-19 Thread Bill Moran
On Thu, 19 Feb 2015 11:12:38 +0530 Medhavi Mahansaria medhavi.mahansa...@tcs.com wrote: Hi Bill, Thanks! But savepoint concept will not work for me as desired. Why not? The scenerio you describe below can be perfectly implemented using savepoints. Describe in more detail, please, why

Re: [GENERAL] Some indexing advice for a Postgres newbie, please?

2015-02-19 Thread Rob Sargent
On 02/19/2015 10:19 AM, brian wrote: On Thu, 19 Feb 2015 09:30:57 -0700, you wrote: On 02/19/2015 09:10 AM, brian wrote: Hi folks, I have a single-user application which is growing beyond the fixed-format data files in which it currently holds its data, I need a proper database as the

Re: [GENERAL] postgresql93-9.3.5: deadlock when updating parent table expected?

2015-02-19 Thread Dmitry O Litvintsev
Thanks, Alvaro, Yes indeed. I have a test that causes the deadlock almost immediately. I have upgraded to 9.3.6 and have been running for a few hours now w/o deadlock errors observed. Dmitry From: Alvaro Herrera [alvhe...@2ndquadrant.com] Sent:

Re: [GENERAL] select where true, or select where input = '$var'

2015-02-19 Thread zach cruise
sorry, corrected below: 1 select * 2 from table 3 if '$sanitized_variable' = '' then -- $variable not provided or undefined or empty, 4 where true -- so select every row/record 5 else 6 where input = '$sanitized_variable' -- variable provided or defined or not-empty, so select only matching

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Alvaro Herrera
Juan Pablo L wrote: Hello, i have created a function (in C) that receives an array that contains tuples of ID's and values. Why are you writing a C function? Sounds like you could accomplish the same with a plpgsql function, with much less effort. The function is to execute updates on each

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Thank you Alvaro, i m afraid ereport seems to be the way, that it is complicated to catch this error code in the code of the caller. cause you have to use a callback etc etc On 19 February 2015 at 15:57, Alvaro Herrera alvhe...@2ndquadrant.com wrote: Juan Pablo L wrote: Hi, i want previous

Re: [GENERAL] select where true, or select where input = '$var'

2015-02-19 Thread John R Pierce
On 2/19/2015 12:39 PM, zach cruise wrote: i want to select based on input, but if input is not provided or if input is empty, then i want to select all rows. something unclear here, is INPUT a variable in your application program, or is it a field in the table? -- john r pierce

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Hi, i want previous updates to rollback ... like nothing happened (a normal begin/rollback behaviour) On 19 February 2015 at 15:34, Alvaro Herrera alvhe...@2ndquadrant.com wrote: Juan Pablo L wrote: Hello, i have created a function (in C) that receives an array that contains tuples of ID's

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Alvaro Herrera
Juan Pablo L wrote: Hi, i want previous updates to rollback ... like nothing happened (a normal begin/rollback behaviour) Ah, so ereport() is exactly what you want, like Chris Mair said. Assuming you wrote it correctly, you should see the ERROR line in the server logs (set

Re: [GENERAL] rollback in C functions

2015-02-19 Thread John R Pierce
On 2/19/2015 1:41 PM, Juan Pablo L wrote: Hi, i want previous updates to rollback ... like nothing happened (a normal begin/rollback behaviour) so thrown an exception. The actual rollback has to be invoked by the client application program, which should catch the error thrown by the query

Re: [GENERAL] rollback in C functions

2015-02-19 Thread John R Pierce
On 2/19/2015 2:02 PM, Juan Pablo L wrote: Thank you Alvaro, i m afraid ereport seems to be the way, that it is complicated to catch this error code in the code of the caller. cause you have to use a callback etc etc a query that triggers ereport(ERROR,) should return a PGresult* that you

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Thank you, i will try this, honestly i was checking if PGResult is NULL, when i trigger the exception i always get NULL so i did not any further but i will try this . On 19 February 2015 at 16:22, John R Pierce pie...@hogranch.com wrote: On 2/19/2015 2:02 PM, Juan Pablo L wrote: Thank you

Re: [GENERAL] select where true, or select where input = '$var'

2015-02-19 Thread David G Johnston
zach cruise wrote sorry, corrected below: 1 select * 2 from table 3 if '$sanitized_variable' = '' then -- $variable not provided or undefined or empty, 4 where true -- so select every row/record 5 else 6 where input = '$sanitized_variable' -- variable provided or defined or not-empty,

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
i tried this but the call to PQresultErrorField(PGresult, PG_DIAG_SQLSTATE) is returning NULL, this is what trigger the exception in the function code: ereport(ERROR,(errcode(ERRCODE_SQL_ROUTINE_EXCEPTION),errmsg(Plan with id %s does not allow balance with id %s,plan_id,in_balanceid))); and this

Re: [GENERAL] Array string casts with SELECT but not SELECT DISTINCT

2015-02-19 Thread David G Johnston
Ken Tanzer wrote ag_reach_test= INSERT INTO foo (my_array) SELECT DISTINCT '{TEST}'; ERROR: column my_array is of type character varying[] but expression is of type text LINE 1: INSERT INTO foo (my_array) SELECT DISTINCT '{TEST}'; ^ HINT:

Re: [GENERAL] stored procedure variable names

2015-02-19 Thread Pavel Stehule
2015-02-20 1:57 GMT+01:00 inspector morse inspectormors...@gmail.com: In all other DBMS, the variable names have a distinctive character to differentiate between variables and column names: Example: SQL Server uses @ MySql uses ? Oracle uses : Firebirdsql uses : It makes it easier to

[GENERAL] Array string casts with SELECT but not SELECT DISTINCT

2015-02-19 Thread Ken Tanzer
Hi. Here's a boiled down example of something that caught me by surprise: ag_reach_test= CREATE TEMP TABLE foo (my_array varchar[]); CREATE TABLE ag_reach_test= INSERT INTO foo (my_array) SELECT '{TEST}'; INSERT 0 1 ag_reach_test= SELECT my_array[1],array_length(my_array,1) FROM foo; my_array |

Re: [GENERAL] stored procedure variable names

2015-02-19 Thread Adrian Klaver
On 02/19/2015 04:57 PM, inspector morse wrote: In all other DBMS, the variable names have a distinctive character to differentiate between variables and column names: Example: SQL Server uses @ MySql uses ? Oracle uses : Firebirdsql uses : It makes it easier to write and manage queries

[GENERAL] Some indexing advice for a Postgres newbie, please?

2015-02-19 Thread brian
Hi folks, I have a single-user application which is growing beyond the fixed-format data files in which it currently holds its data, I need a proper database as the backend. The front end is written using Lazarus and FreePascal under Linux, should anyone feel that makes a difference. The

Re: [GENERAL] Some indexing advice for a Postgres newbie, please?

2015-02-19 Thread Brian Dunavant
You should consider a BitString. http://www.postgresql.org/docs/9.4/static/datatype-bit.html On Thu, Feb 19, 2015 at 11:10 AM, brian br...@meadows.pair.com wrote: Hi folks, I have a single-user application which is growing beyond the fixed-format data files in which it currently holds its

Re: [GENERAL] Some indexing advice for a Postgres newbie, please?

2015-02-19 Thread Rob Sargent
On 02/19/2015 09:10 AM, brian wrote: Hi folks, I have a single-user application which is growing beyond the fixed-format data files in which it currently holds its data, I need a proper database as the backend. The front end is written using Lazarus and FreePascal under Linux, should anyone

Re: [GENERAL] Some indexing advice for a Postgres newbie, please?

2015-02-19 Thread Arthur Silva
On Thu, Feb 19, 2015 at 2:14 PM, Brian Dunavant br...@omniti.com wrote: You should consider a BitString. http://www.postgresql.org/docs/9.4/static/datatype-bit.html On Thu, Feb 19, 2015 at 11:10 AM, brian br...@meadows.pair.com wrote: Hi folks, I have a single-user application which

Re: [GENERAL] Issue dumping schema using readonly user

2015-02-19 Thread Daniel LaMotte
Thank you all so much for the feedback. At this point, I'm convinced that the issue is more complicated than I originally thought :) FWIW, my use case is for a company internal database. I open the database up to all users by simply having a readonly user that anyone can use to connect to the

Re: [GENERAL] Fwd: Data corruption after restarting replica

2015-02-19 Thread Novák , Petr
Hi Adrian, On Wed, Feb 18, 2015 at 10:25 PM, Adrian Klaver adrian.kla...@aklaver.com wrote: On 02/16/2015 02:44 AM, Novák, Petr wrote: Hello, sorry for posting to second list, but as I've received no reply there, I'm trying my luck here. Thanks Petr -- Forwarded message

Re: [GENERAL] Fwd: Data corruption after restarting replica

2015-02-19 Thread Novák , Petr
Hi Dinesh On Wed, Feb 18, 2015 at 11:01 PM, dinesh kumar dineshkuma...@gmail.com wrote: Hi, On Mon, Feb 16, 2015 at 2:44 AM, Novák, Petr nov...@avast.com wrote: Hello, sorry for posting to second list, but as I've received no reply there, I'm trying my luck here. Thanks Petr

Re: [GENERAL] Issue dumping schema using readonly user

2015-02-19 Thread Adrian Klaver
On 02/19/2015 01:46 AM, Daniel LaMotte wrote: Thank you all so much for the feedback. At this point, I'm convinced that the issue is more complicated than I originally thought :) FWIW, my use case is for a company internal database. I open the database up to all users by simply having a

Re: [GENERAL] Some indexing advice for a Postgres newbie, please?

2015-02-19 Thread brian
On Thu, 19 Feb 2015 09:30:57 -0700, you wrote: On 02/19/2015 09:10 AM, brian wrote: Hi folks, I have a single-user application which is growing beyond the fixed-format data files in which it currently holds its data, I need a proper database as the backend. The front end is written using

Re: [GENERAL] Failure loading materialized view with pg_restore

2015-02-19 Thread Tom Lane
Brian Sutherland br...@vanguardistas.net writes: On Wed, Feb 18, 2015 at 10:34:33AM -0500, Tom Lane wrote: User nobody does not have permission to read table x, so the REFRESH fails, because the view's query executes as the view's owner. If you grant select permission for the user nobody on

Re: [GENERAL] BDR Monitoring, missing pg_stat_logical_decoding view

2015-02-19 Thread Steve Boyle
Thank you, that was helpful. In the pg_replication_slots view, I see that xmin is always NULL, is that expected? I'm not sure how to measure the BDR update latency without this xmin value. If I run pg_get_transaction_committime(catalog_xmin), sometimes I get what looks like a default time

Re: [GENERAL] stored procedure variable names

2015-02-19 Thread Jerry Sievers
inspector morse inspectormors...@gmail.com writes: In all other DBMS, the variable names have a distinctive character to differentiate between variables and column names: Example: SQL Server uses @ MySql uses ? Oracle uses : Firebirdsql uses : It makes it easier to write and manage

[GENERAL] stored procedure variable names

2015-02-19 Thread inspector morse
In all other DBMS, the variable names have a distinctive character to differentiate between variables and column names: Example: SQL Server uses @ MySql uses ? Oracle uses : Firebirdsql uses : It makes it easier to write and manage queries especially in stored procedures. Just compare the

Re: [GENERAL] stored procedure variable names

2015-02-19 Thread inspector morse
Yeah, I'm using plpgsql. Actually nevermind on this. I was able to patch my data access utility so it adds a prefix when calling the stored function and then remove it again before returning for front end processing. On Thu, Feb 19, 2015 at 8:44 PM, Adrian Klaver adrian.kla...@aklaver.com wrote:

Re: [GENERAL] stored procedure variable names

2015-02-19 Thread Tom Lane
inspector morse inspectormors...@gmail.com writes: Is there any plan to add a character to differentiate between variables? No. You're free to use a naming convention yourself, of course, but we're not going to break every stored procedure in sight in order to impose one.