0

In postgresql we can get total row count without sending column.

select count(*) from mytable; -- returns count (total number of rows)

Is there any way to so similar thing in sqlalchemy without doing raw query

session.execute('select count(*) from mytable;')
Scott
  • 4,974
  • 6
  • 35
  • 62
rho
  • 771
  • 9
  • 24
  • That query does not select the count: http://sqlfiddle.com/#!17/60d91/1 and even throws an error in older postgresql versions – juergen d Aug 30 '19 at 06:36
  • 1
    Possible dublicate of https://stackoverflow.com/questions/12941416/how-to-count-rows-with-select-count-with-sqlalchemy – Scott Aug 30 '19 at 06:40

1 Answers1

1

That's a bad idea, because

  • lots of empty rows consume more space than a single one with a bigint

  • such a query does not conform to the SQL standard, so you lose portability for no good reason

Go with

SELECT count(*) FROM mytable;
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263