<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Z tabeli do wielu plików]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=2302&amp;type=atom"/>
	<updated>2015-08-28T06:50:16Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=2302</id>
		<entry>
			<title type="html"><![CDATA[Odp: Z tabeli do wielu plików]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=5538#p5538"/>
			<content type="html"><![CDATA[zobacz na poniższy skrypt
create table export_data_t (pole1 text, pole2 text, username name);
insert into export_data_t values ('aa1','bb1','user1'),('aa2','bb2','user2');
create or replace function export_user () returns int as
$body$
declare
 r record;
 i int;
begin
  i := 0;
  for r in select distinct username from export_data_t loop
      raise notice 'Export user: %',r.username;
      execute 'copy (select * from export_data_t where username='''||r.username||''') to ''C:/Program Files/PostgreSQL/9.3/data/export/export_'||r.username||'.csv'' with csv;';
      i := i + 1;
  end loop;
  return i;
end;
$body$
language plpgsql; 
--wywolanie
select export_user();]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2015-08-28T06:50:16Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=5538#p5538</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Z tabeli do wielu plików]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=5537#p5537"/>
			<content type="html"><![CDATA[Mam tabelę: 

AA|BB|CC|USER1 
DE|CC|DE|USER1 
DE|FR|KG|USER2 
... 
DE|NN|KK|USERXX 

Poszukuje sposobu na eksport takiej długiej tabeli w wiele plików o nazwie USER1, USER2... w których będą małe części tabeli zawierające dane danego USER. tzn w pliku USER1 będzie tabelka: 
AA|BB|CC|USER1 
DE|CC|DE|USER1 
i nic więcej. 

Format eksportowanego pliku najlepszy byłby excel ale csv też byłby ok. w sumie cokolwiek było by ok.

Macie jakieś pomysły?]]></content>
			<author>
				<name><![CDATA[STRATOLINER]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1641</uri>
			</author>
			<updated>2015-08-27T12:08:36Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=5537#p5537</id>
		</entry>
</feed>
