Return to site

Csv Query Tool

broken image


Microsoft recently updated the built-in tools for retrieving stock quotes into Excel. If you're typing closing prices into Excel manually, this article may be able to help you get it done faster. Specifically, we'll talk about how the Stock data type retrieves current quotes and related information, and how Power Query can retrieve historical stock quotes from the web. We'll take them one at a time.

  1. Csv Query Tools
  2. Python Csv Query Tool

Wiki CsvQuery is a query tool for CSV like data files. Queries are written in a pseudo SQL syntax. This tool is written in C language. This tool transforms text column data to Comma Separated Values (CSV). It also lets you customize CSV output. You can set custom field separator character, custom field quotation character and choose if you want to quote all fields. You can also skip empty lines and you can skip comments. You can also specify an SQL query as an argument to csvquery (which is more useful for scripts, where you can't use the interactive console): $ csvquery -q 'SELECT csv.surname, csv2.departmentname FROM csv NATURAL JOIN csv2' departments.csv The output of this command is CSV formatted, so it can be redirected to an output CSV file if required. Log parser is a powerful, versatile tool that provides universal query access to text-based data such as log files, XML files and CSV files, as well as key data sources on the Windows® operating system such as the Event Log, the Registry, the file system, and Active Directory®. The Query Tool toolbar uses context-sensitive icons that provide shortcuts to frequently performed tasks. If an icon is highlighted, the option is enabled; if the icon is grayed-out, the task is disabled.

Note: This article is presented with Excel O365 for Windows; not all versions of Excel include the features discussed.

Current Prices with the Stock Data Type

Let's say you have a handful of tickers and you want to view their current prices or related information. Perhaps your list is stored in a table (Insert > Table) and looks like Figure 1.

(Note: converting your ticker list into a Table isn't required, it just makes this feature easier to use).

You can select the tickers, then click the Data > Stocks command in the Data Types group. When you do, Excel attempts to convert those static text values into stocks (Figure 2).

The little icons indicate Excel has successfully found the ticker symbols and converted them into stocks. So, what is so special about the stock data type? It retrieves a rich collection of market data—including current price, volume, high, low, company name, company description, number of employees and much more. To reveal these additional attributes, just click the little stock icon to the left of the company name and you'll see a pop-up card that contains related data. Or, if you want to view the related data in cells, just click the little Add Data icon in the upper right. For example, we can select price, high and low from the list and Excel retrieves the corresponding values (Figure 3).

You can manually refresh the values any time by right-clicking any of the stock icons and selecting Data Type > Refresh. If you had previously used the MSN Money Central Investor Stock Quotes connection, this is the replacement feature and provides much more information.

But what if you want to retrieve historical quotes? For that, we can import data from a
corresponding web page with Power Query.

Historical Prices with Power Query

At the time of this article, the Stocks data type contains current quotes only. So, if we want historical quotes, we'll need to turn to the web. Pull up your favorite historical quotes web page or do a web search. In this article, we retrieve historical quotes from yahoo.com.

The Yahoo service works well with Power Query and has a logical URL structure that is easy to customize for your desired ticker symbol. It uses the format:

Since Microsoft's ticker is MSFT, we could type the following URL into any web browser to see the historical quotes:

  • https://finance.yahoo.com/quote/MSFT/history/

We test the URL for our desired ticker by entering it into a web browser. If the page works, we'll see a table full of daily prices. Now, there are a few ways to get data displayed on the web page into Excel. We could select the range on the web page, copy (Ctrl+C) the info, then open an Excel workbook and do a Paste or Paste Special.

Depending on the webpage formatting, this may or may not work well. If it does, this quick copy/paste method may be all we need.

Another option is to download a file from that webpage (if available) and then open it with Excel. This option typically avoids the formatting issues that can occur with copy/paste. In the case of the Yahoo page, there is a Download Data link that exports a CSV file that can be opened with Excel. And, if this was a one-time project, this option may be sufficient.

But, if this was something we needed to update on an ongoing basis, another option is to use Power Query. Going forward, rather than browse to the webpage to view and download or copy the data, we can just click Refresh from within Excel. To do so, click Data > From Web in the Get & Transform group (not the legacy Get External Data group). This will open Power Query's From Web dialog. You simply paste or type your desired URL (Figure 4).

This will display Power Query's Navigator dialog where you're provided a list of importable items, which are essentially various tables that appear on the web page. We click through the list of tables until we see the one we want to import. For example, in our case, Table 2 holds the historical quotes (Figure 5).

With the desired table selected, we just click the down arrow on the Load button and select Load To. In the resulting dialog, we select Table and … the results are loaded into the specified worksheet (Figure 6).

Now, the nice thing about using Power Query is that next time we need to retrieve updated historical quotes, we can simply right-click any cell in the results table and select Refresh. Power Query essentially retrieves updated values from the original URL. In Excel, we see the updated table rows.

I hope these methods provide an efficient way to retrieve current and historical stock quotes into your Excel file. And remember, Excel rules!

The Query Tool is a powerful, feature-rich environment that allows you toexecute arbitrary SQL commands and review the result set. You can access theQuery Tool via the Query Tool menu option on the Tools menu, or through thecontext menu of select nodes of the Browser tree control. The Query Toolallows you to:

  • Issue ad-hoc SQL queries.

  • Execute arbitrary SQL commands.

  • Edit the result set of a SELECT query if it isupdatable.

  • Displays current connection and transaction status as configured by the user. Miranda dies mass effect 2020.

  • Save the data displayed in the output panel to a CSV file.

  • Review the execution plan of a SQL statement in either a text, a graphicalformat or a table format (similar to https://explain.depesz.com).

  • View analytical information about a SQL statement.

You can open multiple copies of the Query tool in individual tabssimultaneously. To close a copy of the Query tool, click the X in theupper-right hand corner of the tab bar.

The Query Tool features two panels:

  • The upper panel displays the SQL Editor. You can use the panel to enter,edit, or execute a query. It also shows the History tab which can be usedto view the queries that have been executed in the session, and a Scratch Padwhich can be used to hold text snippets during editing. If the Scratch Pad isclosed, it can be re-opened (or additional ones opened) by right-clicking inthe SQL Editor and other panels and adding a new panel.

  • The lower panel displays the Data Output panel. The tabbed panel displaysthe result set returned by a query, information about a query's execution plan,server messages related to the query's execution and any asynchronousnotifications received from the server.

Toolbar¶

The toolbar is described in the following subsections.

  • Query Tool Toolbar

The SQL Editor Panel¶

The SQL editor panel is a workspace where you can manually provide a query,copy a query from another source, or read a query from a file. The SQL editorfeatures syntax coloring and autocompletion.

To use autocomplete, begin typing your query; when you would like the Queryeditor to suggest object names or commands that might be next in your query,press the Control+Space key combination. For example, type 'SELECT * FROM'(without quotes, but with a trailing space), and then press the Control+Spacekey combination to select from a popup menu of autocomplete options.

After entering a query, select the Execute/Refresh icon from the toolbar. Thecomplete contents of the SQL editor panel will be sent to the database serverfor execution. To execute only a section of the code that is displayed in theSQL editor, highlight the text that you want the server to execute, and clickthe Execute/Refresh icon.

The message returned by the server when a command executes is displayed on theMessages tab. If the command is successful, the Messages tab displaysexecution details. Mudrunner pc free download.

Options on the Edit menu offer functionality that helps with code formattingand commenting:

  • The auto-indent feature will automatically indent text to the same depth asthe previous line when you press the Return key.

  • Block indent text by selecting two or more lines and pressing the Tab key.

  • Implement or remove SQL style or toggle C style comment notation within yourcode.

You can also drag and drop certain objects from the treeview whichcan save time in typing long object names. Text containing the object name will befully qualified with schema. Double quotes will be added if required.For functions and procedures, the function name along with parameter names willbe pasted in the Query Tool.

The Data Output Panel¶

The Data Output panel displays data and statistics generated by the mostrecently executed query.

The Data Output tab displays the result set of the query in a table format.You can:

  • Select and copy from the displayed result set.

  • Use the Execute/Refresh options to retrieve query execution information andset query execution options.

  • Use the Download as CSV/TXT icon to download the content of the Data Outputtab as a comma-delimited file.

  • Edit the data in the result set of a SELECT query if it is updatable.

A result set is updatable if:

  • All columns are either selected directly from a single table, orare not table columns at all (e.g. concatenation of 2 columns).Only columns that are selected directly from the table areeditable, other columns are read-only.

  • All the primary key columns or OIDs of the table are selected in theresult set.

Csv Query Tools

Any columns that are renamed or selected more than once are also read-only.

Editable and read-only columns are identified using pencil and lock icons(respectively) in the column headers.

The psycopg2 driver version should be equal to or above 2.8 for updatablequery result sets to work.

An updatable result set is identical to the Data Grid inView/Edit Data mode, and can be modified in the same way.

If Auto-commit is off, the data changes are made as part of the ongoingtransaction, if no transaction is ongoing a new one is initiated. The datachanges are not committed to the database unless the transaction is committed.

If any errors occur during saving (for example, trying to save NULL into acolumn with NOT NULL constraint) the data changes are rolled back to anautomatically created SAVEPOINT to ensure any previously executed queries inthe ongoing transaction are not rolled back.

All rowsets from previous queries or commands that are displayed in the DataOutput panel will be discarded when you invoke another query; open anotherQuery Tool tab to keep your previous results available.

Explain Panel¶

To generate the Explain or Explain Analyze plan of a query, click onExplain or Explain Analyze button in the toolbar.

More options related to Explain and Explain Analyze can be selected fromthe drop down on the right side of Explain Analyze button in the toolbar.

Please note that pgAdmin generates the Explain [Analyze] plan in JSON format.

On successful generation of Explain plan, it will create three tabs/panelsunder the Explain panel.

  • Graphical

Please note that EXPLAIN VERBOSE cannot be displayed graphically. Hover overan icon on the Graphical tab to review information about that item; a popupwindow will display information about the selected object. For information onJIT statistics, triggers and a summary, hover over the icon on top-rightcorner; a similar popup window will be displayed when appropriate.

Use the download button on top left corner of the Explain canvas to downloadthe plan as an SVG file.

Note: Download as SVG is not supported on Internet Explorer.

Note that the query plan that accompanies the Explain analyze is available onthe Data Output tab.

  • Table

Table tab shows the plan details in table format, it generates table formatsimilar to explain.depsez.com. Each row of the table represent the data for aExplain Plan Node. It may contain the node information, exclusive timing,inclusive timing, actual vs planned rows differences, actual rows, plannedrows, loops.

background color of the exclusive, inclusive, and Rows X columns may vary based on thedifference between actual vs planned.

If percentage of the exclusive/inclusive timings of the total query time is:> 90 - Red color> 50 - Orange (between red and yellow) color> 10 - Yellow color

If planner mis-estimated number of rows (actual vs planned) by10 times - Yellow color100 times - Orange (between Red and Yellow) color1000 times - Red color

  • Statistics

Statistics tab shows two tables:1. Statistics per Plan Node Type2. Statistics per Table

Messages Panel¶

Use the Messages tab to view information about the most recently executedquery:

If the server returns an error, the error message will be displayed on theMessages tab, and the syntax that caused the error will be underlined in theSQL editor. If a query succeeds, the Messages tab displays how long thequery took to complete and how many rows were retrieved:

Query History Panel¶

Csv

Use the Query History tab to review activity for the current session:

The Query History tab displays information about recent commands:

  • The date and time that a query was invoked.

  • The text of the query.

  • The number of rows returned by the query.

  • The amount of time it took the server to process the query and return aresult set.

  • Messages returned by the server (not noted on the Messages tab).

  • The source of the query (indicated by icons corresponding to the toolbar).

You can show or hide the queries generated internally by pgAdmin (during‘View/Edit Data' or ‘Save Data' operations).

To erase the content of the Query History tab, select Clear history fromthe Clear drop-down menu.

Query History is maintained across sessions for each database on a per-userbasis when running in Query Tool mode. In View/Edit Data mode, history is notretained. By default, the last 20 queries are stored for each database. Thiscan be adjusted in config_local.py or config_system.py (see theconfig.py documentation) by overriding theMAX_QUERY_HIST_STORED value. See the Deployment sectionfor more information.

Python Csv Query Tool

Connection Status¶

Use the Connection status feature to view the current connection andtransaction status by clicking on the status icon in the Query Tool:

Change connection¶

Csv Query Tool

Use the Query History tab to review activity for the current session:

The Query History tab displays information about recent commands:

  • The date and time that a query was invoked.

  • The text of the query.

  • The number of rows returned by the query.

  • The amount of time it took the server to process the query and return aresult set.

  • Messages returned by the server (not noted on the Messages tab).

  • The source of the query (indicated by icons corresponding to the toolbar).

You can show or hide the queries generated internally by pgAdmin (during‘View/Edit Data' or ‘Save Data' operations).

To erase the content of the Query History tab, select Clear history fromthe Clear drop-down menu.

Query History is maintained across sessions for each database on a per-userbasis when running in Query Tool mode. In View/Edit Data mode, history is notretained. By default, the last 20 queries are stored for each database. Thiscan be adjusted in config_local.py or config_system.py (see theconfig.py documentation) by overriding theMAX_QUERY_HIST_STORED value. See the Deployment sectionfor more information.

Python Csv Query Tool

Connection Status¶

Use the Connection status feature to view the current connection andtransaction status by clicking on the status icon in the Query Tool:

Change connection¶

User can connect to another server or database from existing open session of query tool.

  • Click on the connection link next to connection status.

  • Now click on the option from the dropdown.

  • Now select server, database, user, and role to connect and click OK.

  • A newly created connection will now get listed in the options.

  • To connect, select the newly created connection from the dropdown list.

Macros¶

Query Tool Macros enable you to execute pre-defined SQL queries with a single key press. Pre-defined queries can contain the placeholder $SELECTION$. Upon macro execution, the placeholder will be replaced with the currently selected text in the Query Editor pane of the Query Tool.

To create a macro, select the Manage Macros option from the Macros menu on the Query Tool. Select the key you wish to use, enter the name of the macro, and the query, optionally including the selection placeholder, and then click the Save button to store the macro.

To clear a macro, select the macro on the Manage Macros dialogue, and then click the Clear button.

The server will prompt you for confirmation to clear the macro.

To clear all macros, click on the Clear button on left side of the key. The server will prompt you for confirmation to clear all the rows.

To execute a macro, simply select the appropriate shortcut keys, or select it from the Macros menu.





broken image