From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?B?R2HDq3RhbiBBbmRyw6k=?= Subject: How-to use a source block output as code for another source block? Date: Fri, 6 Dec 2019 19:41:39 +0100 Message-ID: References: <16ebd54f-9f18-4c27-c667-8637ed6ee658@gaetanandre.eu> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:40353) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idIY3-0007vp-B4 for emacs-orgmode@gnu.org; Fri, 06 Dec 2019 13:41:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idIXz-0005zj-0S for emacs-orgmode@gnu.org; Fri, 06 Dec 2019 13:41:49 -0500 Received: from smtpout1.mo529.mail-out.ovh.net ([178.32.125.2]:40871) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idIXw-0005uT-Tt for emacs-orgmode@gnu.org; Fri, 06 Dec 2019 13:41:46 -0500 Received: from DAG2EX1.mxp2.local (unknown [10.109.143.158]) by mo529.mail-out.ovh.net (Postfix) with ESMTPS id BE2AD12F549D for ; Fri, 6 Dec 2019 19:41:40 +0100 (CET) In-Reply-To: <16ebd54f-9f18-4c27-c667-8637ed6ee658@gaetanandre.eu> Content-Language: en-US List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Hello, Yesterday I asked this question on IRC and the community kindly answered. I was also asked to send an email to the mailing list explaining my use case. Thus this email. So, in the scope of my current project at work I need to see if Neo4J wou= ld be a valid alternative to PostgreSQL to store our data. Were hoping to have better flexibility and better performance on some requests. In order to document the steps of my exploration I decided to use org-mode which I discovered a couple of weeks ago (I use it mainly to keep a diary of my work days). The first step in my investigation is to migrate the data from Postgres to Neo4j via CSV files. Since our schema contains quite a bit of tables and relations I decided to generate corresponding SQL COPY ... TO ... requests by first putting variable data in a array, second generating requests with a python source bloc and then feed it to a SQL bloc. Here is the result: #+tblname: rels-data | computer=C2=A0=C2=A0=C2=A0 | id | house=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= house_id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | EQUIPS=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 |=20 computer=C2=A0=C2=A0 | | house=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | id | block=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 | block_id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= IN=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=20 house=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | | block=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 | id | city=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 | city_id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 | IN | block=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | | city=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | id | country=C2=A0= =C2=A0=C2=A0=C2=A0 | country_id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | IN = | city=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | | city=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | id | city_group=C2= =A0=C2=A0 | city_group_id=C2=A0=C2=A0=C2=A0 | BELONGS_TO |=20 city=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | #+name: import-rels #+begin_src python :var rels=3Drels-data :results value verbatim res =3D ["""COPY ( =C2=A0=C2=A0 SELECT '{0}' || {1} as ":START_ID", '{2}' || {3} as ":END_I= D", '{4}'=20 as ":TYPE" =C2=A0=C2=A0 FROM "{5}" ) TO '/data/rels_{0}_{2}.csv' WITH CSV HEADER;""".format(*row) for row=20 in rels] return "\n".join(res) #+end_src #+name: export-data #+header: :engine postgresql #+header: :dbhost localhost #+header: :dbuser mrwho #+header: :database whatever #+header: :noweb no-export #+begin_src sql =C2=A0 <> #+end_src All the magic is in the use of noweb[1] feature. If you have any questions or remarks don't hesitate. Regards, [1] https://orgmode.org/manual/noweb.html