I feel quite stupid as I can't seem to import geopandas.
I am using Anaconda (miniconda3) and feel like I have successfully installed via:
(base) C:\Users\Jeremy>Conda create -n geopandas_env
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Users\Jeremy\miniconda3\envs\geopandas_env
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate geopandas_env
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) C:\Users\Jeremy>Conda activate geopandas_env
(geopandas_env) C:\Users\Jeremy>conda install python=3 geopandas
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Users\Jeremy\miniconda3\envs\geopandas_env
added / updated specs:
- geopandas
- python=3
The following packages will be downloaded:
package | build
---------------------------|-----------------
attrs-20.3.0 | pyhd3eb1b0_0 43 KB
blas-1.0 | mkl 6 KB
bzip2-1.0.8 | he774522_0 113 KB
cfitsio-3.470 | he774522_6 512 KB
click-7.1.2 | py_0 71 KB
click-plugins-1.1.1 | py_0 12 KB
cligj-0.7.1 | py38haa95532_0 14 KB
curl-7.67.0 | h2a8f88b_0 123 KB
expat-2.2.10 | h33f27b4_2 187 KB
fiona-1.8.13.post1 | py38hd760492_0 619 KB
freexl-1.0.6 | h2bbff1b_0 51 KB
gdal-3.0.2 | py38hdf43c64_0 1.0 MB
geopandas-0.8.1 | py_0 902 KB
geos-3.8.0 | h33f27b4_0 905 KB
geotiff-1.5.1 | h5770a2b_1 126 KB
hdf4-4.2.13 | h712560f_2 1.3 MB
hdf5-1.10.4 | h7ebc959_0 7.9 MB
icc_rt-2019.0.0 | h0cc432a_1 6.0 MB
icu-58.2 | ha925a31_3 9.4 MB
intel-openmp-2020.2 | 254 1.6 MB
jpeg-9b | hb83a4c4_2 245 KB
kealib-1.4.7 | h07cbb95_6 133 KB
krb5-1.16.4 | hc04afaa_0 693 KB
libboost-1.67.0 | hd9e427e_4 18.6 MB
libcurl-7.67.0 | h2a8f88b_0 269 KB
libgdal-3.0.2 | h1155b67_0 7.0 MB
libiconv-1.15 | h1df5818_7 626 KB
libkml-1.3.0 | he5f2a48_4 19.7 MB
libnetcdf-4.6.1 | h411e497_2 494 KB
libpng-1.6.37 | h2a8f88b_0 333 KB
libpq-11.2 | h3235a2c_0 2.6 MB
libspatialindex-1.9.3 | h33f27b4_0 351 KB
libspatialite-4.3.0a | h7ffb84d_0 2.3 MB
libssh2-1.9.0 | h7a1dbc1_1 215 KB
libtiff-4.1.0 | h56a325e_0 737 KB
libxml2-2.9.10 | hb89e7f3_3 1.5 MB
lz4-c-1.8.1.2 | h2fa13f4_0 176 KB
m2w64-expat-2.1.1 | 2 160 KB
m2w64-gcc-libgfortran-5.3.0| 6 340 KB
m2w64-gcc-libs-5.3.0 | 7 518 KB
m2w64-gcc-libs-core-5.3.0 | 7 213 KB
m2w64-gettext-0.19.7 | 2 4.2 MB
m2w64-gmp-6.1.0 | 2 689 KB
m2w64-libiconv-1.14 | 6 1.5 MB
m2w64-libwinpthread-git-5.0.0.4634.697f757| 2 30 KB
m2w64-xz-5.2.2 | 2 395 KB
mkl-2020.2 | 256 109.3 MB
mkl-service-2.3.0 | py38h196d8e1_0 47 KB
mkl_fft-1.2.0 | py38h45dec08_0 122 KB
mkl_random-1.1.1 | py38h47e9c7a_0 245 KB
msys2-conda-epoch-20160418 | 1 2 KB
munch-2.5.0 | py_0 15 KB
numpy-1.19.2 | py38hadc3359_0 22 KB
numpy-base-1.19.2 | py38ha3acd2a_0 3.8 MB
openjpeg-2.3.0 | h5ec785f_1 205 KB
pandas-1.2.0 | py38hf11a4ad_0 7.9 MB
pcre-8.44 | ha925a31_0 384 KB
pip-20.3.3 | py38haa95532_0 1.8 MB
postgresql-11.2 | h3235a2c_0 13.0 MB
proj-6.2.1 | h9f7ef89_0 7.9 MB
pyproj-2.6.1.post1 | py38hcfa1391_1 320 KB
python-dateutil-2.8.1 | py_0 215 KB
pytz-2020.5 | pyhd3eb1b0_0 182 KB
rtree-0.9.4 | py38h21ff451_1 49 KB
setuptools-51.0.0 | py38haa95532_2 741 KB
shapely-1.7.1 | py38h210f175_0 374 KB
tbb-2018.0.5 | he980bc4_0 150 KB
tiledb-1.6.3 | h7b000aa_0 1.3 MB
tk-8.6.10 | he774522_0 2.7 MB
vc-14.2 | h21ff451_1 8 KB
vs2015_runtime-14.27.29016 | h5e58377_2 1007 KB
wheel-0.36.2 | pyhd3eb1b0_0 33 KB
xerces-c-3.2.3 | ha925a31_0 2.8 MB
xz-5.2.5 | h62dcd97_0 244 KB
zstd-1.3.7 | h508b16e_0 337 KB
------------------------------------------------------------
Total: 249.7 MB
The following NEW packages will be INSTALLED:
attrs pkgs/main/noarch::attrs-20.3.0-pyhd3eb1b0_0
blas pkgs/main/win-64::blas-1.0-mkl
bzip2 pkgs/main/win-64::bzip2-1.0.8-he774522_0
ca-certificates pkgs/main/win-64::ca-certificates-2020.12.8-haa95532_0
certifi pkgs/main/win-64::certifi-2020.12.5-py38haa95532_0
cfitsio pkgs/main/win-64::cfitsio-3.470-he774522_6
click pkgs/main/noarch::click-7.1.2-py_0
click-plugins pkgs/main/noarch::click-plugins-1.1.1-py_0
cligj pkgs/main/win-64::cligj-0.7.1-py38haa95532_0
curl pkgs/main/win-64::curl-7.67.0-h2a8f88b_0
expat pkgs/main/win-64::expat-2.2.10-h33f27b4_2
fiona pkgs/main/win-64::fiona-1.8.13.post1-py38hd760492_0
freexl pkgs/main/win-64::freexl-1.0.6-h2bbff1b_0
gdal pkgs/main/win-64::gdal-3.0.2-py38hdf43c64_0
geopandas pkgs/main/noarch::geopandas-0.8.1-py_0
geos pkgs/main/win-64::geos-3.8.0-h33f27b4_0
geotiff pkgs/main/win-64::geotiff-1.5.1-h5770a2b_1
hdf4 pkgs/main/win-64::hdf4-4.2.13-h712560f_2
hdf5 pkgs/main/win-64::hdf5-1.10.4-h7ebc959_0
icc_rt pkgs/main/win-64::icc_rt-2019.0.0-h0cc432a_1
icu pkgs/main/win-64::icu-58.2-ha925a31_3
intel-openmp pkgs/main/win-64::intel-openmp-2020.2-254
jpeg pkgs/main/win-64::jpeg-9b-hb83a4c4_2
kealib pkgs/main/win-64::kealib-1.4.7-h07cbb95_6
krb5 pkgs/main/win-64::krb5-1.16.4-hc04afaa_0
libboost pkgs/main/win-64::libboost-1.67.0-hd9e427e_4
libcurl pkgs/main/win-64::libcurl-7.67.0-h2a8f88b_0
libgdal pkgs/main/win-64::libgdal-3.0.2-h1155b67_0
libiconv pkgs/main/win-64::libiconv-1.15-h1df5818_7
libkml pkgs/main/win-64::libkml-1.3.0-he5f2a48_4
libnetcdf pkgs/main/win-64::libnetcdf-4.6.1-h411e497_2
libpng pkgs/main/win-64::libpng-1.6.37-h2a8f88b_0
libpq pkgs/main/win-64::libpq-11.2-h3235a2c_0
libspatialindex pkgs/main/win-64::libspatialindex-1.9.3-h33f27b4_0
libspatialite pkgs/main/win-64::libspatialite-4.3.0a-h7ffb84d_0
libssh2 pkgs/main/win-64::libssh2-1.9.0-h7a1dbc1_1
libtiff pkgs/main/win-64::libtiff-4.1.0-h56a325e_0
libxml2 pkgs/main/win-64::libxml2-2.9.10-hb89e7f3_3
lz4-c pkgs/main/win-64::lz4-c-1.8.1.2-h2fa13f4_0
m2w64-expat pkgs/msys2/win-64::m2w64-expat-2.1.1-2
m2w64-gcc-libgfor~ pkgs/msys2/win-64::m2w64-gcc-libgfortran-5.3.0-6
m2w64-gcc-libs pkgs/msys2/win-64::m2w64-gcc-libs-5.3.0-7
m2w64-gcc-libs-co~ pkgs/msys2/win-64::m2w64-gcc-libs-core-5.3.0-7
m2w64-gettext pkgs/msys2/win-64::m2w64-gettext-0.19.7-2
m2w64-gmp pkgs/msys2/win-64::m2w64-gmp-6.1.0-2
m2w64-libiconv pkgs/msys2/win-64::m2w64-libiconv-1.14-6
m2w64-libwinpthre~ pkgs/msys2/win-64::m2w64-libwinpthread-git-5.0.0.4634.697f757-2
m2w64-xz pkgs/msys2/win-64::m2w64-xz-5.2.2-2
mkl pkgs/main/win-64::mkl-2020.2-256
mkl-service pkgs/main/win-64::mkl-service-2.3.0-py38h196d8e1_0
mkl_fft pkgs/main/win-64::mkl_fft-1.2.0-py38h45dec08_0
mkl_random pkgs/main/win-64::mkl_random-1.1.1-py38h47e9c7a_0
msys2-conda-epoch pkgs/msys2/win-64::msys2-conda-epoch-20160418-1
munch pkgs/main/noarch::munch-2.5.0-py_0
numpy pkgs/main/win-64::numpy-1.19.2-py38hadc3359_0
numpy-base pkgs/main/win-64::numpy-base-1.19.2-py38ha3acd2a_0
openjpeg pkgs/main/win-64::openjpeg-2.3.0-h5ec785f_1
openssl pkgs/main/win-64::openssl-1.1.1i-h2bbff1b_0
pandas pkgs/main/win-64::pandas-1.2.0-py38hf11a4ad_0
pcre pkgs/main/win-64::pcre-8.44-ha925a31_0
pip pkgs/main/win-64::pip-20.3.3-py38haa95532_0
postgresql pkgs/main/win-64::postgresql-11.2-h3235a2c_0
proj pkgs/main/win-64::proj-6.2.1-h9f7ef89_0
pyproj pkgs/main/win-64::pyproj-2.6.1.post1-py38hcfa1391_1
python pkgs/main/win-64::python-3.8.5-h5fd99cc_1
python-dateutil pkgs/main/noarch::python-dateutil-2.8.1-py_0
pytz pkgs/main/noarch::pytz-2020.5-pyhd3eb1b0_0
rtree pkgs/main/win-64::rtree-0.9.4-py38h21ff451_1
setuptools pkgs/main/win-64::setuptools-51.0.0-py38haa95532_2
shapely pkgs/main/win-64::shapely-1.7.1-py38h210f175_0
six pkgs/main/win-64::six-1.15.0-py38haa95532_0
sqlite pkgs/main/win-64::sqlite-3.33.0-h2a8f88b_0
tbb pkgs/main/win-64::tbb-2018.0.5-he980bc4_0
tiledb pkgs/main/win-64::tiledb-1.6.3-h7b000aa_0
tk pkgs/main/win-64::tk-8.6.10-he774522_0
vc pkgs/main/win-64::vc-14.2-h21ff451_1
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
wheel pkgs/main/noarch::wheel-0.36.2-pyhd3eb1b0_0
wincertstore pkgs/main/win-64::wincertstore-0.2-py38_0
xerces-c pkgs/main/win-64::xerces-c-3.2.3-ha925a31_0
xz pkgs/main/win-64::xz-5.2.5-h62dcd97_0
zlib pkgs/main/win-64::zlib-1.2.11-h62dcd97_4
zstd pkgs/main/win-64::zstd-1.3.7-h508b16e_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
intel-openmp-2020.2 | 1.6 MB | ############################################################################ | 100%
geotiff-1.5.1 | 126 KB | ############################################################################ | 100%
geopandas-0.8.1 | 902 KB | ############################################################################ | 100%
m2w64-expat-2.1.1 | 160 KB | ############################################################################ | 100%
rtree-0.9.4 | 49 KB | ############################################################################ | 100%
bzip2-1.0.8 | 113 KB | ############################################################################ | 100%
m2w64-gcc-libs-5.3.0 | 518 KB | ############################################################################ | 100%
blas-1.0 | 6 KB | ############################################################################ | 100%
freexl-1.0.6 | 51 KB | ############################################################################ | 100%
postgresql-11.2 | 13.0 MB | ############################################################################ | 100%
m2w64-gettext-0.19.7 | 4.2 MB | ############################################################################ | 100%
libtiff-4.1.0 | 737 KB | ############################################################################ | 100%
m2w64-libwinpthread- | 30 KB | ############################################################################ | 100%
libpq-11.2 | 2.6 MB | ############################################################################ | 100%
lz4-c-1.8.1.2 | 176 KB | ############################################################################ | 100%
mkl-service-2.3.0 | 47 KB | ############################################################################ | 100%
kealib-1.4.7 | 133 KB | ############################################################################ | 100%
libcurl-7.67.0 | 269 KB | ############################################################################ | 100%
hdf5-1.10.4 | 7.9 MB | ############################################################################ | 100%
icu-58.2 | 9.4 MB | ############################################################################ | 100%
krb5-1.16.4 | 693 KB | ############################################################################ | 100%
m2w64-libiconv-1.14 | 1.5 MB | ############################################################################ | 100%
tiledb-1.6.3 | 1.3 MB | ############################################################################ | 100%
vs2015_runtime-14.27 | 1007 KB | ############################################################################ | 100%
gdal-3.0.2 | 1.0 MB | ############################################################################ | 100%
mkl_random-1.1.1 | 245 KB | ############################################################################ | 100%
xz-5.2.5 | 244 KB | ############################################################################ | 100%
libpng-1.6.37 | 333 KB | ############################################################################ | 100%
mkl_fft-1.2.0 | 122 KB | ############################################################################ | 100%
cligj-0.7.1 | 14 KB | ############################################################################ | 100%
pyproj-2.6.1.post1 | 320 KB | ############################################################################ | 100%
cfitsio-3.470 | 512 KB | ############################################################################ | 100%
m2w64-xz-5.2.2 | 395 KB | ############################################################################ | 100%
pip-20.3.3 | 1.8 MB | ############################################################################ | 100%
libssh2-1.9.0 | 215 KB | ############################################################################ | 100%
zstd-1.3.7 | 337 KB | ############################################################################ | 100%
mkl-2020.2 | 109.3 MB | ############################################################################ | 100%
m2w64-gcc-libgfortra | 340 KB | ############################################################################ | 100%
m2w64-gcc-libs-core- | 213 KB | ############################################################################ | 100%
pcre-8.44 | 384 KB | ############################################################################ | 100%
expat-2.2.10 | 187 KB | ############################################################################ | 100%
libgdal-3.0.2 | 7.0 MB | ############################################################################ | 100%
libkml-1.3.0 | 19.7 MB | ############################################################################ | 100%
pytz-2020.5 | 182 KB | ############################################################################ | 100%
munch-2.5.0 | 15 KB | ############################################################################ | 100%
jpeg-9b | 245 KB | ############################################################################ | 100%
numpy-1.19.2 | 22 KB | ############################################################################ | 100%
fiona-1.8.13.post1 | 619 KB | ############################################################################ | 100%
setuptools-51.0.0 | 741 KB | ############################################################################ | 100%
curl-7.67.0 | 123 KB | ############################################################################ | 100%
hdf4-4.2.13 | 1.3 MB | ############################################################################ | 100%
wheel-0.36.2 | 33 KB | ############################################################################ | 100%
icc_rt-2019.0.0 | 6.0 MB | ############################################################################ | 100%
geos-3.8.0 | 905 KB | ############################################################################ | 100%
libxml2-2.9.10 | 1.5 MB | ############################################################################ | 100%
shapely-1.7.1 | 374 KB | ############################################################################ | 100%
libspatialite-4.3.0a | 2.3 MB | ############################################################################ | 100%
tbb-2018.0.5 | 150 KB | ############################################################################ | 100%
msys2-conda-epoch-20 | 2 KB | ############################################################################ | 100%
click-7.1.2 | 71 KB | ############################################################################ | 100%
proj-6.2.1 | 7.9 MB | ############################################################################ | 100%
vc-14.2 | 8 KB | ############################################################################ | 100%
libspatialindex-1.9. | 351 KB | ############################################################################ | 100%
m2w64-gmp-6.1.0 | 689 KB | ############################################################################ | 100%
xerces-c-3.2.3 | 2.8 MB | ############################################################################ | 100%
libboost-1.67.0 | 18.6 MB | ############################################################################ | 100%
pandas-1.2.0 | 7.9 MB | ############################################################################ | 100%
python-dateutil-2.8. | 215 KB | ############################################################################ | 100%
numpy-base-1.19.2 | 3.8 MB | ############################################################################ | 100%
libiconv-1.15 | 626 KB | ############################################################################ | 100%
attrs-20.3.0 | 43 KB | ############################################################################ | 100%
openjpeg-2.3.0 | 205 KB | ############################################################################ | 100%
libnetcdf-4.6.1 | 494 KB | ############################################################################ | 100%
tk-8.6.10 | 2.7 MB | ############################################################################ | 100%
click-plugins-1.1.1 | 12 KB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(geopandas_env) C:\Users\Jeremy>
I am getting a:
Traceback (most recent call last):
File "C:\Users\Jeremy.py", line 4, in
import geopandas as gpd
ModuleNotFoundError: No module named 'geopandas'
[Finished in 0.278s]
Not sure if relevant but I am using Atom 1.53.0 w/ pythong 3.8 on Windows Version 10.0
when I import sys and look if geopandas is there I get False
I have tried the solutions here: ImportError: No module named geopandas to no avail
Can someone please walk me through any potential solutions in the same way they would explain to a small child how to tie their shoes. Thank you
EDIT: After a night of sleep I have tried to uninstall via pip and get:
rosoft Windows [Version 10.0.19042.685]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\Users\Jeremy>pip uninstall geopandas
WARNING: Skipping geopandas as it is not installed.
C:\Users\Jeremy>pip install geopandas
Collecting geopandas
Using cached geopandas-0.8.1-py2.py3-none-any.whl (962 kB)
Requirement already satisfied: pandas>=0.23.0 in c:\users\jeremy\appdata\local\programs\python\python38-32\lib\site-packages (from geopandas) (1.1.4)
Requirement already satisfied: pytz>=2017.2 in c:\users\jeremy\appdata\local\programs\python\python38-32\lib\site-packages (from pandas>=0.23.0->geopandas) (2020.4)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\jeremy\appdata\local\programs\python\python38-32\lib\site-packages (from pandas>=0.23.0->geopandas) (2.8.1)
Requirement already satisfied: numpy>=1.15.4 in c:\users\jeremy\appdata\local\programs\python\python38-32\lib\site-packages (from pandas>=0.23.0->geopandas) (1.19.3)
Collecting pyproj>=2.2.0
Downloading pyproj-3.0.0.post1-cp38-cp38-win32.whl (12.1 MB)
|████████████████████████████████| 12.1 MB 6.8 MB/s
Requirement already satisfied: certifi in c:\users\jeremy\appdata\local\programs\python\python38-32\lib\site-packages (from pyproj>=2.2.0->geopandas) (2020.6.20)
Requirement already satisfied: six>=1.5 in c:\users\jeremy\appdata\local\programs\python\python38-32\lib\site-packages (from python-dateutil>=2.7.3->pandas>=0.23.0->geopandas) (1.15.0)
Collecting fiona
Using cached Fiona-1.8.18.tar.gz (1.3 MB)
ERROR: Command errored out with exit status 1:
command: 'c:\users\jeremy\appdata\local\programs\python\python38-32\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Jeremy\AppData\Local\Temp\pip-install-r7rq8ht_\fiona_8a53c4d23da14715a1f0fc69f0a79dab\setup.py'"'"'; file='"'"'C:\Users\Jeremy\AppData\Local\Temp\pip-install-r7rq8ht_\fiona_8a53c4d23da14715a1f0fc69f0a79dab\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Jeremy\AppData\Local\Temp\pip-pip-egg-info-rhdvy5yt'
cwd: C:\Users\Jeremy\AppData\Local\Temp\pip-install-r7rq8ht_\fiona_8a53c4d23da14715a1f0fc69f0a79dab
Complete output (1 lines):
A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
C:\Users\Jeremy>
For anyone struggling with my error above:
pip install wheel
pip install pipwin
pipwin install numpy
pipwin install pandas
pipwin install shapely
pipwin install gdal
pipwin install fiona
pipwin install pyproj
pipwin install six
pipwin install rtree
pipwin install geopandas
here are the source links: http://geopandas.org/install.html#installation https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Related
I have an issue with a database import. Basically, I am doing this on a postgres 9.6 (production):
/usr/bin/pg_dump mydb | /bin/gzip | /usr/bin/ssh root#1.2.3.4 "cat > /root/20210130.sql.gz"
And on a remote machine I am importing on Postgres 11 like this:
step 1: import schema from a beta machine with Postgres 11
step 2: import data from that export like this: time zcat 20210130.sql.gz | psql mydb
The issue that I have is that one of the tables has 0 rows even though it uses a lot of disk space.
In the original db:
table_schema | table_name | row_estimate | total | index | toast | table
--------------------+--------------------------+--------------+------------+------------+------------+------------
public | test | 5.2443e+06 | 18 GB | 13 GB | 8192 bytes | 4864 MB
In the new db:
table_schema | table_name | row_estimate | total | index | toast | table
--------------------+--------------------------+--------------+------------+------------+------------+------------
public | test | 0 | 4574 MB | 4574 MB | 8192 bytes | 16 kB
What is going on here? How can I fix it?
I can't import the entire DB again because it needed ~7 hours to do the import.
I am using postgresql and I have a table called accidents (state, total accidents) and another table called population. I want to get the top 3 state names with high total accidents and then get the population of those 3 states divided by total accidents in postgresql? How to write the query in the following way?
Explanation:
Population Table
rank| state | population
---+-----------------------------+------------
1 | Uttar Pradesh | 199581477
2 | Maharashtra | 112372972
3 | Bihar | 103804630
4 | West Bengal | 91347736
5 | Madhya Pradesh | 72597565
6 | Tamil Nadu | 72138958
7 | Rajasthan | 68621012
8 | Karnataka | 61130704
9 | Gujarat | 60383628
10 | Andhra Pradesh | 49665533
11 | Odisha | 41947358
12 | Telangana | 35193978
13 | Kerala | 33387677
14 | Jharkhand | 32966238
15 | Assam | 31169272
16 | Punjab | 27704236
17 | Haryana | 25753081
18 | Chhattisgarh | 25540196
19 | Jammu and Kashmir | 12548926
20 | Uttarakhand | 10116752
21 | Himachal Pradesh | 6856509
22 | Tripura | 3671032
23 | Meghalaya | 2964007
24 | Manipur*β* | 2721756
25 | Nagaland | 1980602
26 | Goa | 1457723
27 | Arunachal Pradesh | 1382611
28 | Mizoram | 1091014
29 | Sikkim | 607688
30 | Delhi | 16753235
31 | Puducherry | 1244464
32 | Chandigarh | 1054686
33 | Andaman and Nicobar Islands | 379944
34 | Dadra and Nagar Haveli | 342853
35 | Daman and Diu | 242911
36 | Lakshadweep | 64429
accident table:
state | eqto8 | eqto10 | mrthn10 | ntknwn | total
-----------------------------+-------+--------+---------+--------+--------
Andhra Pradesh | 6425 | 8657 | 8144 | 19298 | 42524
Arunachal Pradesh | 88 | 76 | 87 | 0 | 251
Assam | 0 | 0 | 0 | 6535 | 6535
Bihar | 2660 | 3938 | 3722 | 0 | 10320
Chhattisgarh | 2888 | 7052 | 3571 | 0 | 13511
Goa | 616 | 1512 | 2184 | 0 | 4312
Gujarat | 4864 | 7864 | 7132 | 8089 | 27949
Haryana | 3365 | 2588 | 4112 | 0 | 10065
Himachal Pradesh | 276 | 626 | 977 | 1020 | 2899
Jammu and Kashmir | 1557 | 618 | 434 | 4100 | 6709
Jharkhand | 1128 | 701 | 1037 | 2845 | 5711
Karnataka | 11167 | 14715 | 18566 | 0 | 44448
Kerala | 5580 | 13271 | 17323 | 0 | 36174
Madhya Pradesh | 15630 | 16226 | 19354 | 0 | 51210
Maharashtra | 4117 | 5350 | 10538 | 46311 | 66316
Manipur | 147 | 453 | 171 | 0 | 771
Meghalaya | 210 | 154 | 119 | 0 | 483
Mizoram | 27 | 58 | 25 | 0 | 110
Nagaland | 11 | 13 | 18 | 0 | 42
Odisha | 1881 | 3120 | 4284 | 0 | 9285
Punjab | 1378 | 2231 | 1825 | 907 | 6341
Rajasthan | 5534 | 5895 | 5475 | 6065 | 22969
Sikkim | 6 | 144 | 8 | 0 | 158
Tamil Nadu | 8424 | 18826 | 29871 | 10636 | 67757
Tripura | 290 | 376 | 222 | 0 | 888
Uttarakhand | 318 | 305 | 456 | 393 | 1472
Uttar Pradesh | 8520 | 10457 | 10995 | 0 | 29972
West Bengal | 1494 | 1311 | 974 | 8511 | 12290
Andaman and Nicobar Islands | 18 | 104 | 114 | 0 | 236
Chandigarh | 112 | 39 | 210 | 58 | 419
Dadra and Nagar Haveli | 40 | 20 | 17 | 8 | 85
Daman and Diu | 11 | 6 | 8 | 25 | 50
Delhi | 0 | 0 | 0 | 6937 | 6937
Lakshadweep | 0 | 0 | 0 | 3 | 3
Puducherry | 154 | 668 | 359 | 0 | 1181
All India | 88936 | 127374 | 152332 | 121741 | 490383
So that result should be
21.57
81.03
107.44
explanation:
Highest accidents states Tamilnadu, Maharashtra, Madhyapradesh.
Tamilnadu population/accidents = 21213/983 = 21.57 (Assumed values)
Maharasthra population/accidents = 10000/123 = 81.03
Madhyapradesh population/accidents = 34812/324 = 107.44
My query is:
SELECT POPULATION/
(SELECT TOTAL
FROM accidents
WHERE STATE NOT LIKE 'All %'
ORDER BY TOTAL DESC
LIMIT 3)
aVG FROM population
WHERE STATE IN
(SELECT STATE
FROM accidents
WHERE STATE NOT LIKE 'All %'
ORDER BY TOTAL DESC
LIMIT 3);
throwing ERROR: more than one row returned by a subquery used as an expression.
How to modify the query to get the required result or any other way to get the result in postgresql?
This ought to do it.
SELECT a.state, population.population/a.total FROM
(SELECT total, state FROM accidents WHERE state <> 'All India' ORDER BY total DESC LIMIT 3 ) AS a
INNER JOIN population on a.state = population.state
I have a table which contains data use Sql server 2008 r2
+-----+------+--------+-------+------+-------+
| ID | Kind | Date | Price | Type | Amount|
+-----+------+--------+-------+------+-------+
| 525 | 32 |1/1/2016| 240 | 0 | 3000 |
| 525 | 32 |1/1/2016| 380 | 1 | 3000 |
| 525 | 32 |1/1/2016| 240 | 0 | 4000 |
| 525 | 32 |1/1/2016| 380 | 1 | 4000 |
+-----+------+--------+-------+------+-------+
How can I get this result?
+-----+------+--------+-------+------+-------+
| ID | Kind | Date | Price | Type | Amount|
+-----+------+--------+-------+------+-------+
| 525 | 32 |1/1/2016| 240 | 0 | 3000 |
| 525 | 32 |1/1/2016| 380 | 1 | 4000 |
+-----+------+--------+-------+------+-------+
Will this not do?
SELECT DISTNCT ID, Kind, Date, Price, Type, Amount FROM dbo.yourTable
We are running on PostgreSQL version 9.1, previously we had over 1Billion rows in one table and has been deleted. However, it looks like the \l+ command still reports inaccurately about the actual database size (it reported 568GB but in reality it's much much less than).
The proof of that 568GB is wrong is that the individual table size tally didn't add up to the number, as you can see, top 20 relations has 4292MB in size, the remaining 985 relations are all well below 10MB. In fact all of them add up to about less than 6GB.
Any idea why PostgreSQL so much bloat? If confirmed, how can I debloat? I am not super familiar with VACUUM, is that what I need to do? If so, how?
Much appreciate it.
pmlex=# \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------
pmlex | pmlex | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 568 GB | pg_default |
pmlex_analytics | pmlex | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 433 MB | pg_default |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 5945 kB | pg_default | default administrative connection database
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 5841 kB | pg_default | unmodifiable empty database
| | | | | postgres=CTc/postgres | | |
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 5841 kB | pg_default | default template for new databases
| | | | | postgres=CTc/postgres | | |
(5 rows)
pmlex=# SELECT nspname || '.' || relname AS "relation",
pmlex-# pg_size_pretty(pg_relation_size(C.oid)) AS "size"
pmlex-# FROM pg_class C
pmlex-# LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
pmlex-# WHERE nspname NOT IN ('pg_catalog', 'information_schema')
pmlex-# ORDER BY pg_relation_size(C.oid) DESC;
relation | size
-------------------------------------+---------
public.page_page | 1289 MB
public.page_pageimagehistory | 570 MB
pg_toast.pg_toast_158103 | 273 MB
public.celery_taskmeta_task_id_key | 233 MB
public.page_page_unique_hash_uniq | 140 MB
public.page_page_ad_text_id | 136 MB
public.page_page_kn_result_id | 125 MB
public.page_page_seo_term_id | 124 MB
public.page_page_kn_search_id | 124 MB
public.page_page_direct_network_tag | 124 MB
public.page_page_traffic_source_id | 123 MB
public.page_page_active | 123 MB
public.page_page_is_referrer | 123 MB
public.page_page_category_id | 123 MB
public.page_page_host_id | 123 MB
public.page_page_serp_id | 121 MB
public.page_page_domain_id | 120 MB
public.celery_taskmeta_pkey | 106 MB
public.page_pagerenderhistory | 102 MB
public.page_page_campaign_id | 89 MB
...
...
...
pg_toast.pg_toast_4354379 | 0 bytes
(1005 rows)
Your options include:
1). Ensuring autovacuum is enabled and set aggressively.
2). Recreating the table as I mentioned in an earlier comment (create-table-as-select + truncate + reload the original table).
3). Running CLUSTER on the table if you can afford to be locked out of that table (exclusive lock).
4). VACUUM FULL, though CLUSTER is more efficient and recommended.
5). Running a plain VACUUM ANALYZE a few times and leaving the table as-is, to eventually fill the space back up as new data comes in.
6). Dump and reload the table via pg_dump
7). pg_repack (though I haven't used it in production)
it will likely look different if you use pg_total_relation_size instead of pg_relation_size
pg_relation_size doesn't give the total size of the table, see
https://www.postgresql.org/docs/9.5/static/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE
Sorry i know merge is something completely different in Sql Server but i couldn't think what else to call it.
I have a User-Defined Table Type which looks like
-------------------------------------------------------------------
| Id | Foreign Key | Height | Weight | Width | Length |
-------------------------------------------------------------------
| 01 | 1256 | 12.2 | 15.8 | 14.5 | 15 |
| 02 | 1256 | 18.2 | 15.8 | 25.8 | 28 |
| 03 | 1258 | 14.5 | 11.3 | 56.6 | 32 |
| 04 | 1258 | 14.5 | 1.85 | 32.9 | 64 |
| 05 | 1216 | 25.3 | 16.2 | 12.5 | 86 |
-------------------------------------------------------------------
And I want to be able to do a query or something that gives me the foreign key with the lowest Height, Weight, Width and Length associated with it so I'd have something like
------------------------------------------------------------
| Foreign Key | Height | Weight | Width | Length |
------------------------------------------------------------
| 1256 | 12.2 | 15.8 | 14.5 | 15 |
| 1258 | 14.5 | 1.85 | 32.9 | 32 |
| 1216 | 25.3 | 16.2 | 12.5 | 86 |
------------------------------------------------------------
Is there any functions in Sql Server to achieve this, or can any one point me to any resources that may help?
Thanks
Based on your expected output, this should do the trick:
SELECT [Foreign Key], MIN(Height) AS Height, MIN(Weight) AS Weight,
MIN(Length) AS Length
FROM #YourTableVar
GROUP BY [Foreign Key]
It is straightforward to select the minimum of a column:
select
[Foreign Key],
MIN(Height) AS MinHeight,
MIN(Weight) AS MinWeight,
MIN(Length) AS MinLength
FROM
Table
GROUP BY
[Foreign Key]