Cannot select from one table in postgresql database via pyodbc - how to debug

I have a postgresql database containing some tables made by drupal and others that I made myself. And then I have python api using pyodbc to query the database.

There is only one table that I cannot select from pyodbc. If I print the request and paste it into pgadminIII, it will give the expected result, and if I modify the table in python code, it will give the correct result.

Request

select id from a_company where name = 'somename' 

with the result

 7 8 9 

etc. (50 lines int id)

My python code

 sql = """select id from a_company where name = 'somename'""" curs = self._connection.cursor() sql = self._ConvertToPostGres(sql) #drops [] etc, as the initial code was for MSSQL curs.execute(sql) f = curs.fetchall() 

A call through pyodbc returns

 None 

(I can select from other tables using the same join, so the connection string doesn't matter?)

My best guess is that this is a permissions problem, and that I did something stupid with this particular table.

Can someone tell me how to debug this?

Create a table using pgadmin:

 -- Table: a_company -- DROP TABLE a_company; CREATE TABLE a_company ( id integer NOT NULL DEFAULT nextval('a_company_id_seq'::regclass), name character varying, abn character varying, url character varying, anzsic character varying(5), address character varying, area integer, sell_equipment boolean, recycling_provider boolean, monthly_matches boolean, user_id bigint, latitude double precision, longitude double precision, geography geography, CONSTRAINT a_company_pkey PRIMARY KEY (id), CONSTRAINT fk_a_company_a_anzsic_codes FOREIGN KEY (anzsic) REFERENCES a_anzsic_codes (code) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) WITH ( OIDS=FALSE ); ALTER TABLE a_company OWNER TO aspire; -- Index: fki_a_company_aspire_a_codes -- DROP INDEX fki_a_company_aspire_a_codes; CREATE INDEX fki_a_company_aspire_a_codes ON a_company USING btree (anzsic COLLATE pg_catalog."default"); 

If I change this enough to change the name of the table, I get another table that "works" correctly. But I changed the id line to just be the identifier of the serial number and not indicate the sequence.

+6
source share

Source: https://habr.com/ru/post/982882/


All Articles