{"id":968,"date":"2025-02-11T17:39:44","date_gmt":"2025-02-11T09:39:44","guid":{"rendered":"https:\/\/heoffice.com\/?p=968"},"modified":"2025-02-11T17:41:20","modified_gmt":"2025-02-11T09:41:20","slug":"vs-code-ipython-sql-use-sql-in-jupyter","status":"publish","type":"post","link":"https:\/\/heoffice.com\/?p=968","title":{"rendered":"VS CODE + ipython-sql use SQL in jupyter"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>pip install ipython-sql\n\nIn jupyter file:\n%reload_ext sql\n\n%sql oracle:\/\/RDF_CN_Q321:password@localhost:8521\/xe\n\n%config SqlMagic.style = '_DEPRECATED_DEFAULT'\nif no config , will got below errors:<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>KeyError                                  Traceback (most recent call last)\nCell In&#91;9], line 1\n----> 1 get_ipython().run_cell_magic('sql', '', 'select * from TABLE1\\n')\n\nFile c:\\Users\\heeeeguo\\AppData\\Local\\miniforge3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2541, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)\n   2539 with self.builtin_trap:\n   2540     args = (magic_arg_s, cell)\n-> 2541     result = fn(*args, **kwargs)\n   2543 # The code below prevents the output from being displayed\n   2544 # when using magics with decorator @output_can_be_silenced\n   2545 # when the last Python token in the expression is a ';'.\n   2546 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):\n\nFile c:\\Users\\heeeeguo\\AppData\\Local\\miniforge3\\lib\\site-packages\\sql\\magic.py:219, in SqlMagic.execute(self, line, cell, local_ns)\n    216     return\n    218 try:\n--> 219     result = sql.run.run(conn, parsed&#91;\"sql\"], self, user_ns)\n    221     if (\n    222         result is not None\n    223         and not isinstance(result, str)\n   (...)\n    226         # Instead of returning values, set variables directly in the\n    227         # user's namespace. Variable names given by column names\n    229         if self.autopandas:\n...\n--> 116     self.pretty = PrettyTable(self.field_names, style=prettytable.__dict__&#91;config.style.upper()])\n    117 else:\n    118     list.__init__(self, &#91;])\n\nKeyError: 'DEFAULT'\nOutput is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...<\/code><\/pre>\n\n\n\n<p>%%sql<\/p>\n\n\n\n<p>select * from TABLE1<\/p>\n\n\n\n<p>output : <\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>column1<\/th><\/tr><\/thead><tbody><tr><td>111<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>%%sql select * from TABLE1 output : column1 111<\/p>\n","protected":false},"author":1,"featured_media":971,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-968","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web"],"acf":[],"_links":{"self":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=968"}],"version-history":[{"count":2,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/968\/revisions"}],"predecessor-version":[{"id":970,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/968\/revisions\/970"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/media\/971"}],"wp:attachment":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}