Expand Menu
-
Home / Documentation / Utilities / ReadSQL / Index
readSQL¶
In [ ]:
readSQL(query: str,
time_on: bool = False,
limit: int = 100)
Returns the Result of a SQL query as a tablesample object.
Parameters¶
Name | Type | Optional | Description |
---|---|---|---|
query | str | ❌ | SQL Query. |
time_on | bool | ✓ | If set to True, displays the query elapsed time. |
limit | int | ✓ | Number maximum of elements to display. |
Returns¶
tablesample : An object containing the result. For more information, see utilities.tablesample.
Example¶
In [17]:
from verticapy.utilities import *
readSQL("SELECT * FROM public.titanic")
123 pclassInteger | 123 survivedInteger | Abc Varchar(164) | Abc sexVarchar(20) | 123 ageNumeric(6,3) | 123 sibspInteger | 123 parchInteger | Abc ticketVarchar(36) | 123 fareNumeric(10,5) | Abc cabinVarchar(30) | Abc embarkedVarchar(20) | Abc boatVarchar(100) | 123 bodyInteger | Abc home.destVarchar(100) | |
1 | 1 | 0 | female | 2.000 | 1 | 2 | 113781 | 151.55000 | C22 C26 | S | [null] | [null] | Montreal, PQ / Chesterville, ON | |
2 | 1 | 0 | male | 30.000 | 1 | 2 | 113781 | 151.55000 | C22 C26 | S | [null] | 135 | Montreal, PQ / Chesterville, ON | |
3 | 1 | 0 | female | 25.000 | 1 | 2 | 113781 | 151.55000 | C22 C26 | S | [null] | [null] | Montreal, PQ / Chesterville, ON | |
4 | 1 | 0 | male | 39.000 | 0 | 0 | 112050 | 0.00000 | A36 | S | [null] | [null] | Belfast, NI | |
5 | 1 | 0 | male | 71.000 | 0 | 0 | PC 17609 | 49.50420 | [null] | C | [null] | 22 | Montevideo, Uruguay | |
6 | 1 | 0 | male | 47.000 | 1 | 0 | PC 17757 | 227.52500 | C62 C64 | C | [null] | 124 | New York, NY | |
7 | 1 | 0 | male | [null] | 0 | 0 | PC 17318 | 25.92500 | [null] | S | [null] | [null] | New York, NY | |
8 | 1 | 0 | male | 24.000 | 0 | 1 | PC 17558 | 247.52080 | B58 B60 | C | [null] | [null] | Montreal, PQ | |
9 | 1 | 0 | male | 36.000 | 0 | 0 | 13050 | 75.24170 | C6 | C | A | [null] | Winnipeg, MN | |
10 | 1 | 0 | male | 25.000 | 0 | 0 | 13905 | 26.00000 | [null] | C | [null] | 148 | San Francisco, CA | |
11 | 1 | 0 | male | 45.000 | 0 | 0 | 113784 | 35.50000 | T | S | [null] | [null] | Trenton, NJ | |
12 | 1 | 0 | male | 42.000 | 0 | 0 | 110489 | 26.55000 | D22 | S | [null] | [null] | London / Winnipeg, MB | |
13 | 1 | 0 | male | 41.000 | 0 | 0 | 113054 | 30.50000 | A21 | S | [null] | [null] | Pomeroy, WA | |
14 | 1 | 0 | male | 48.000 | 0 | 0 | PC 17591 | 50.49580 | B10 | C | [null] | 208 | Omaha, NE | |
15 | 1 | 0 | male | [null] | 0 | 0 | 112379 | 39.60000 | [null] | C | [null] | [null] | Philadelphia, PA | |
16 | 1 | 0 | male | 45.000 | 0 | 0 | 113050 | 26.55000 | B38 | S | [null] | [null] | Washington, DC | |
17 | 1 | 0 | male | [null] | 0 | 0 | 113798 | 31.00000 | [null] | S | [null] | [null] | [null] | |
18 | 1 | 0 | male | 33.000 | 0 | 0 | 695 | 5.00000 | B51 B53 B55 | S | [null] | [null] | New York, NY | |
19 | 1 | 0 | male | 28.000 | 0 | 0 | 113059 | 47.10000 | [null] | S | [null] | [null] | Montevideo, Uruguay | |
20 | 1 | 0 | male | 17.000 | 0 | 0 | 113059 | 47.10000 | [null] | S | [null] | [null] | Montevideo, Uruguay | |
21 | 1 | 0 | male | 49.000 | 0 | 0 | 19924 | 26.00000 | [null] | S | [null] | [null] | Ascot, Berkshire / Rochester, NY | |
22 | 1 | 0 | male | 36.000 | 1 | 0 | 19877 | 78.85000 | C46 | S | [null] | 172 | Little Onn Hall, Staffs | |
23 | 1 | 0 | male | 46.000 | 1 | 0 | W.E.P. 5734 | 61.17500 | E31 | S | [null] | [null] | Amenia, ND | |
24 | 1 | 0 | male | [null] | 0 | 0 | 112051 | 0.00000 | [null] | S | [null] | [null] | Liverpool, England / Belfast | |
25 | 1 | 0 | male | 27.000 | 1 | 0 | 13508 | 136.77920 | C89 | C | [null] | [null] | Los Angeles, CA | |
26 | 1 | 0 | male | [null] | 0 | 0 | 110465 | 52.00000 | A14 | S | [null] | [null] | Stoughton, MA | |
27 | 1 | 0 | male | 47.000 | 0 | 0 | 5727 | 25.58750 | E58 | S | [null] | [null] | Victoria, BC | |
28 | 1 | 0 | male | 37.000 | 1 | 1 | PC 17756 | 83.15830 | E52 | C | [null] | [null] | Lakewood, NJ | |
29 | 1 | 0 | male | [null] | 0 | 0 | 113791 | 26.55000 | [null] | S | [null] | [null] | Roachdale, IN | |
30 | 1 | 0 | male | 70.000 | 1 | 1 | WE/P 5735 | 71.00000 | B22 | S | [null] | 269 | Milwaukee, WI | |
31 | 1 | 0 | male | 39.000 | 1 | 0 | PC 17599 | 71.28330 | C85 | C | [null] | [null] | New York, NY | |
32 | 1 | 0 | male | 31.000 | 1 | 0 | F.C. 12750 | 52.00000 | B71 | S | [null] | [null] | Montreal, PQ | |
33 | 1 | 0 | male | 50.000 | 1 | 0 | PC 17761 | 106.42500 | C86 | C | [null] | 62 | Deephaven, MN / Cedar Rapids, IA | |
34 | 1 | 0 | male | 39.000 | 0 | 0 | PC 17580 | 29.70000 | A18 | C | [null] | 133 | Philadelphia, PA | |
35 | 1 | 0 | female | 36.000 | 0 | 0 | PC 17531 | 31.67920 | A29 | C | [null] | [null] | New York, NY | |
36 | 1 | 0 | male | [null] | 0 | 0 | PC 17483 | 221.77920 | C95 | S | [null] | [null] | [null] | |
37 | 1 | 0 | male | 30.000 | 0 | 0 | 113051 | 27.75000 | C111 | C | [null] | [null] | New York, NY | |
38 | 1 | 0 | male | 19.000 | 3 | 2 | 19950 | 263.00000 | C23 C25 C27 | S | [null] | [null] | Winnipeg, MB | |
39 | 1 | 0 | male | 64.000 | 1 | 4 | 19950 | 263.00000 | C23 C25 C27 | S | [null] | [null] | Winnipeg, MB | |
40 | 1 | 0 | male | [null] | 0 | 0 | 113778 | 26.55000 | D34 | S | [null] | [null] | Westcliff-on-Sea, Essex | |
41 | 1 | 0 | male | [null] | 0 | 0 | 112058 | 0.00000 | B102 | S | [null] | [null] | [null] | |
42 | 1 | 0 | male | 37.000 | 1 | 0 | 113803 | 53.10000 | C123 | S | [null] | [null] | Scituate, MA | |
43 | 1 | 0 | male | 47.000 | 0 | 0 | 111320 | 38.50000 | E63 | S | [null] | 275 | St Anne's-on-Sea, Lancashire | |
44 | 1 | 0 | male | 24.000 | 0 | 0 | PC 17593 | 79.20000 | B86 | C | [null] | [null] | [null] | |
45 | 1 | 0 | male | 71.000 | 0 | 0 | PC 17754 | 34.65420 | A5 | C | [null] | [null] | New York, NY | |
46 | 1 | 0 | male | 38.000 | 0 | 1 | PC 17582 | 153.46250 | C91 | S | [null] | 147 | Winnipeg, MB | |
47 | 1 | 0 | male | 46.000 | 0 | 0 | PC 17593 | 79.20000 | B82 B84 | C | [null] | [null] | New York, NY | |
48 | 1 | 0 | male | [null] | 0 | 0 | 113796 | 42.40000 | [null] | S | [null] | [null] | [null] | |
49 | 1 | 0 | male | 45.000 | 1 | 0 | 36973 | 83.47500 | C83 | S | [null] | [null] | New York, NY | |
50 | 1 | 0 | male | 40.000 | 0 | 0 | 112059 | 0.00000 | B94 | S | [null] | 110 | [null] | |
51 | 1 | 0 | male | 55.000 | 1 | 1 | 12749 | 93.50000 | B69 | S | [null] | 307 | Montreal, PQ | |
52 | 1 | 0 | male | 42.000 | 0 | 0 | 113038 | 42.50000 | B11 | S | [null] | [null] | London / Middlesex | |
53 | 1 | 0 | male | [null] | 0 | 0 | 17463 | 51.86250 | E46 | S | [null] | [null] | Brighton, MA | |
54 | 1 | 0 | male | 55.000 | 0 | 0 | 680 | 50.00000 | C39 | S | [null] | [null] | London / Birmingham | |
55 | 1 | 0 | male | 42.000 | 1 | 0 | 113789 | 52.00000 | [null] | S | [null] | 38 | New York, NY | |
56 | 1 | 0 | male | [null] | 0 | 0 | PC 17600 | 30.69580 | [null] | C | 14 | [null] | New York, NY | |
57 | 1 | 0 | female | 50.000 | 0 | 0 | PC 17595 | 28.71250 | C49 | C | [null] | [null] | Paris, France New York, NY | |
58 | 1 | 0 | male | 46.000 | 0 | 0 | 694 | 26.00000 | [null] | S | [null] | 80 | Bennington, VT | |
59 | 1 | 0 | male | 50.000 | 0 | 0 | 113044 | 26.00000 | E60 | S | [null] | [null] | London | |
60 | 1 | 0 | male | 32.500 | 0 | 0 | 113503 | 211.50000 | C132 | C | [null] | 45 | [null] | |
61 | 1 | 0 | male | 58.000 | 0 | 0 | 11771 | 29.70000 | B37 | C | [null] | 258 | Buffalo, NY | |
62 | 1 | 0 | male | 41.000 | 1 | 0 | 17464 | 51.86250 | D21 | S | [null] | [null] | Southington / Noank, CT | |
63 | 1 | 0 | male | [null] | 0 | 0 | 113028 | 26.55000 | C124 | S | [null] | [null] | Portland, OR | |
64 | 1 | 0 | male | [null] | 0 | 0 | PC 17612 | 27.72080 | [null] | C | [null] | [null] | Chicago, IL | |
65 | 1 | 0 | male | 29.000 | 0 | 0 | 113501 | 30.00000 | D6 | S | [null] | 126 | Springfield, MA | |
66 | 1 | 0 | male | 30.000 | 0 | 0 | 113801 | 45.50000 | [null] | S | [null] | [null] | London / New York, NY | |
67 | 1 | 0 | male | 30.000 | 0 | 0 | 110469 | 26.00000 | C106 | S | [null] | [null] | Brockton, MA | |
68 | 1 | 0 | male | 19.000 | 1 | 0 | 113773 | 53.10000 | D30 | S | [null] | [null] | New York, NY | |
69 | 1 | 0 | male | 46.000 | 0 | 0 | 13050 | 75.24170 | C6 | C | [null] | 292 | Vancouver, BC | |
70 | 1 | 0 | male | 54.000 | 0 | 0 | 17463 | 51.86250 | E46 | S | [null] | 175 | Dorchester, MA | |
71 | 1 | 0 | male | 28.000 | 1 | 0 | PC 17604 | 82.17080 | [null] | C | [null] | [null] | New York, NY | |
72 | 1 | 0 | male | 65.000 | 0 | 0 | 13509 | 26.55000 | E38 | S | [null] | 249 | East Bridgewater, MA | |
73 | 1 | 0 | male | 44.000 | 2 | 0 | 19928 | 90.00000 | C78 | Q | [null] | 230 | Fond du Lac, WI | |
74 | 1 | 0 | male | 55.000 | 0 | 0 | 113787 | 30.50000 | C30 | S | [null] | [null] | Montreal, PQ | |
75 | 1 | 0 | male | 47.000 | 0 | 0 | 113796 | 42.40000 | [null] | S | [null] | [null] | Washington, DC | |
76 | 1 | 0 | male | 37.000 | 0 | 1 | PC 17596 | 29.70000 | C118 | C | [null] | [null] | Brooklyn, NY | |
77 | 1 | 0 | male | 58.000 | 0 | 2 | 35273 | 113.27500 | D48 | C | [null] | 122 | Lexington, MA | |
78 | 1 | 0 | male | 64.000 | 0 | 0 | 693 | 26.00000 | [null] | S | [null] | 263 | Isle of Wight, England | |
79 | 1 | 0 | male | 65.000 | 0 | 1 | 113509 | 61.97920 | B30 | C | [null] | 234 | Providence, RI | |
80 | 1 | 0 | male | 28.500 | 0 | 0 | PC 17562 | 27.72080 | D43 | C | [null] | 189 | ?Havana, Cuba | |
81 | 1 | 0 | male | [null] | 0 | 0 | 112052 | 0.00000 | [null] | S | [null] | [null] | Belfast | |
82 | 1 | 0 | male | 45.500 | 0 | 0 | 113043 | 28.50000 | C124 | S | [null] | 166 | Surbiton Hill, Surrey | |
83 | 1 | 0 | male | 23.000 | 0 | 0 | 12749 | 93.50000 | B24 | S | [null] | [null] | Montreal, PQ | |
84 | 1 | 0 | male | 29.000 | 1 | 0 | 113776 | 66.60000 | C2 | S | [null] | [null] | Isleworth, England | |
85 | 1 | 0 | male | 18.000 | 1 | 0 | PC 17758 | 108.90000 | C65 | C | [null] | [null] | Madrid, Spain | |
86 | 1 | 0 | male | 47.000 | 0 | 0 | 110465 | 52.00000 | C110 | S | [null] | 207 | Worcester, MA | |
87 | 1 | 0 | male | 38.000 | 0 | 0 | 19972 | 0.00000 | [null] | S | [null] | [null] | Rotterdam, Netherlands | |
88 | 1 | 0 | male | 22.000 | 0 | 0 | PC 17760 | 135.63330 | [null] | C | [null] | 232 | [null] | |
89 | 1 | 0 | male | [null] | 0 | 0 | PC 17757 | 227.52500 | [null] | C | [null] | [null] | [null] | |
90 | 1 | 0 | male | 31.000 | 0 | 0 | PC 17590 | 50.49580 | A24 | S | [null] | [null] | Trenton, NJ | |
91 | 1 | 0 | male | [null] | 0 | 0 | 113767 | 50.00000 | A32 | S | [null] | [null] | Seattle, WA | |
92 | 1 | 0 | male | 36.000 | 0 | 0 | 13049 | 40.12500 | A10 | C | [null] | [null] | Winnipeg, MB | |
93 | 1 | 0 | male | 55.000 | 1 | 0 | PC 17603 | 59.40000 | [null] | C | [null] | [null] | New York, NY | |
94 | 1 | 0 | male | 33.000 | 0 | 0 | 113790 | 26.55000 | [null] | S | [null] | 109 | London | |
95 | 1 | 0 | male | 61.000 | 1 | 3 | PC 17608 | 262.37500 | B57 B59 B63 B66 | C | [null] | [null] | Haverford, PA / Cooperstown, NY | |
96 | 1 | 0 | male | 50.000 | 1 | 0 | 13507 | 55.90000 | E44 | S | [null] | [null] | Duluth, MN | |
97 | 1 | 0 | male | 56.000 | 0 | 0 | 113792 | 26.55000 | [null] | S | [null] | [null] | New York, NY | |
98 | 1 | 0 | male | 56.000 | 0 | 0 | 17764 | 30.69580 | A7 | C | [null] | [null] | St James, Long Island, NY | |
99 | 1 | 0 | male | 24.000 | 1 | 0 | 13695 | 60.00000 | C31 | S | [null] | [null] | Huntington, WV | |
100 | 1 | 0 | male | [null] | 0 | 0 | 113056 | 26.00000 | A19 | S | [null] | [null] | Streatham, Surrey |
Out[17]:
Rows: 1-100 of 1234 | Columns: 14
In [18]:
# Time ON
readSQL("SELECT pclass, AVG(survived) FROM public.titanic GROUP BY 1", time_on = True)
Execution: 0.01s
123 pclassInteger | 123 AVGFloat | |
1 | 1 | 0.612179487179487 |
2 | 2 | 0.416988416988417 |
3 | 3 | 0.227752639517345 |
Out[18]:
Rows: 3 | Columns: 2
In [19]:
# Changing the limit
readSQL("SELECT * FROM public.titanic", limit = 5)
123 pclassInteger | 123 survivedInteger | Abc Varchar(164) | Abc sexVarchar(20) | 123 ageNumeric(6,3) | 123 sibspInteger | 123 parchInteger | Abc ticketVarchar(36) | 123 fareNumeric(10,5) | Abc cabinVarchar(30) | Abc embarkedVarchar(20) | Abc boatVarchar(100) | 123 bodyInteger | Abc home.destVarchar(100) | |
1 | 1 | 0 | female | 2.000 | 1 | 2 | 113781 | 151.55000 | C22 C26 | S | [null] | [null] | Montreal, PQ / Chesterville, ON | |
2 | 1 | 0 | male | 30.000 | 1 | 2 | 113781 | 151.55000 | C22 C26 | S | [null] | 135 | Montreal, PQ / Chesterville, ON | |
3 | 1 | 0 | female | 25.000 | 1 | 2 | 113781 | 151.55000 | C22 C26 | S | [null] | [null] | Montreal, PQ / Chesterville, ON | |
4 | 1 | 0 | male | 39.000 | 0 | 0 | 112050 | 0.00000 | A36 | S | [null] | [null] | Belfast, NI | |
5 | 1 | 0 | male | 71.000 | 0 | 0 | PC 17609 | 49.50420 | [null] | C | [null] | 22 | Montevideo, Uruguay |
Out[19]:
Rows: 1-5 of 1234 | Columns: 14
(c) Copyright [2020-2022] Vertica