[GENERAL] Postgresql - COPY TO - get number row inserted - from JDBC

2015-02-07 Thread Nicolas Paris
Hello !

My goal is to get the result from COPY TO ...  query, from JDBC. This
query returns : COPY X
(where X is number line inserted)
1) Can I can I consider it useless, since when no error, all lines are
suposed to be inserted ?
2) If not useless, how can I get the response COPY 10 (when 10 rows
inserted), I get with psql way, or with pgadmin.

I have tried the int Statement.executeUpdate() method, but it returns 0

Thanks for any help !

Nicolas PARIS


Re: [GENERAL] Postgresql - COPY TO - get number row inserted - from JDBC

2015-02-07 Thread Adrian Klaver

On 02/07/2015 06:14 AM, Nicolas Paris wrote:

Hello !

My goal is to get the result from COPY TO ...  query, from JDBC. This
query returns : COPY X
(where X is number line inserted)
1) Can I can I consider it useless, since when no error, all lines are
suposed to be inserted ?
2) If not useless, how can I get the response COPY 10 (when 10 rows
inserted), I get with psql way, or with pgadmin.

I have tried the int Statement.executeUpdate() method, but it returns 0

Thanks for any help !


I am not a Java programmer, but I think what you want is here:

https://jdbc.postgresql.org/documentation/publicapi/index.html

under org.postgresql.copy



Nicolas PARIS



--
Adrian Klaver
adrian.kla...@aklaver.com


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Postgresql - COPY TO - get number row inserted - from JDBC

2015-02-07 Thread Thomas Kellerer

Nicolas Paris wrote on 07.02.2015 15:14:

Hello !

My goal is to get the result from COPY TO ...  query, from JDBC. This query 
returns : COPY X
(where X is number line inserted)
1) Can I can I consider it useless, since when no error, all lines are suposed 
to be inserted ?
2) If not useless, how can I get the response COPY 10 (when 10 rows 
inserted), I get with psql way, or with pgadmin.

I have tried the int Statement.executeUpdate() method, but it returns 0

Thanks for any help !

Nicolas PARIS


I you are using COPY to import a file located on the server, I don't think 
you'll get that information from JDBC.

But you can use the equivalent to COPY .. FROM stdin through JDBC.
And when you do that, you can get the number of rows inserted:

https://jdbc.postgresql.org/documentation/publicapi/org/postgresql/copy/CopyManager.html





--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] How do I bump a row to the front of sort efficiently

2015-02-07 Thread Paul Jungwirth
 Or maybe instead of a view you could write a
 set-returning function, e.g. as described here:

I thought I'd see if I could make this work just for fun. Here is a
simple proof of concept (on 9.3):

-- DROP TABLE IF EXISTS topics;
CREATE TABLE topics (
  id INTEGER PRIMARY KEY,
  bumped_at INTEGER NOT NULL
);
INSERT INTO topics
SELECT a, a * 2
FROM   generate_series(1, 1000) s(a)
;

CREATE OR REPLACE FUNCTION topics_sorted_after_id(INT, INT)
RETURNS TABLE(id int, after_top int, bumped_at int)
AS $$
SELECT  id, 0 AS after_top, bumped_at
FROMtopics
WHERE   id = $1
UNION ALL
(SELECT id, 1 AS after_top, bumped_at
 FROM   topics
 WHERE  id IS DISTINCT FROM $1
 ORDER BY bumped_at DESC
 LIMIT $2 - 1)
ORDER BY after_top, bumped_at DESC
$$
LANGUAGE sql;

SELECT * FROM topics_sorted_after_id(45, 30);

That looks to me like it gives the right results. I'm curious if
RETURNS TABLE is the right approach to use here or if there is
something nicer.

What if the ORM insists on `FROM topics`? Is there any way to rewrite
the query or function to work around that?

Paul

-- 
_
Pulchritudo splendor veritatis.


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Postgresql - COPY TO - get number row inserted - from JDBC

2015-02-07 Thread Nicolas Paris
Thanks Adrian and Thomas. I get it worked with CopyIn(sql, inputstream)
method, and then with FROM STDIN.

If someone interested in ETL Talend software, I actually modified the
component tPostgresqlBulkExec. You can find it there :
https://github.com/parisni/tPostgresqlBulkExec.git
I guess this is faster to read from STDIN than export the file on the
remote server and then COPY FROM file exported on the remote server
isn'it ?



Nicolas PARIS

2015-02-07 16:40 GMT+01:00 Thomas Kellerer spam_ea...@gmx.net:

 Nicolas Paris wrote on 07.02.2015 15:14:

  Hello !

 My goal is to get the result from COPY TO ...  query, from JDBC. This
 query returns : COPY X
 (where X is number line inserted)
 1) Can I can I consider it useless, since when no error, all lines are
 suposed to be inserted ?
 2) If not useless, how can I get the response COPY 10 (when 10 rows
 inserted), I get with psql way, or with pgadmin.

 I have tried the int Statement.executeUpdate() method, but it returns 0

 Thanks for any help !

 Nicolas PARIS


 I you are using COPY to import a file located on the server, I don't think
 you'll get that information from JDBC.

 But you can use the equivalent to COPY .. FROM stdin through JDBC.
 And when you do that, you can get the number of rows inserted:

 https://jdbc.postgresql.org/documentation/publicapi/org/
 postgresql/copy/CopyManager.html





 --
 Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
 To make changes to your subscription:
 http://www.postgresql.org/mailpref/pgsql-general