[sqlalchemy] Re: Writing values to Postgresql type Float
Thanks for responding, I am using Postgresql 8.3.8 and Postgis 1.4. I have tried using both DOUBLE_PRECISION and DOUBLE_PRECISION(asdecimal=True), with the same errors. thanks On Jan 18, 3:50 pm, Michael Bayer mike...@zzzcomputing.com wrote: Here's a tested example of DOUBLE_PRECISION using both float and Decimal versions. Make sure you're on a recent release of psycopg2: from sqlalchemy import Column, create_engine, Integer from sqlalchemy.orm import Session from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION from decimal import Decimal Base = declarative_base() class dream4_eta_15km_pm10(Base): __tablename__='pm10_dream_rasters' id = Column(Integer, primary_key=True) # use float values max_pm10=Column(DOUBLE_PRECISION) # use Decimal values mean_pm10=Column(DOUBLE_PRECISION(asdecimal=True)) def __repr__(self): return dream4_eta_15km_pm10(%r, %r) % (self.max_pm10, self.mean_pm10) engine = create_engine('postgresql://scott:tiger@localhost/test', echo=True) Base.metadata.create_all(engine) sess = Session(engine) sess.add(dream4_eta_15km_pm10(max_pm10=76945.283959, mean_pm10=Decimal(7683.27835))) sess.commit() print sess.query(dream4_eta_15km_pm10).all() On Jan 18, 2011, at 3:24 PM, wilbur wrote: Hello, I am having problems using sqlalchemy to write values to Postgresq columns of type Float. I am getting sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt errors when I try to insert records. My Postgresql table is defined as: Column | Type | Modifiers + +-- max_pm25 | double precision | mean_pm25 | double precision | After importing the Postgresql dialect: from sqlalchemy.dialects.postgresql import * I define my sqlalchemy table as: class dream4_eta_15km_pm10(Base): __tablename__='pm10_dream_rasters' max_pm10=Column(DOUBLE_PRECISION) mean_pm10=Column(DOUBLE_PRECISION) Any help appreciated, Bill -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Writing values to Postgresql type Float
Thanks again, Your first script ran fine. I ended up doing something like this: session.add(test_floats(id=2,max_pm10=Decimal(str(76945.283959)), mean_pm10=Decimal(str(7683.27835 It was the only thing that eventually worked... On Jan 19, 10:37 am, Michael Bayer mike...@zzzcomputing.com wrote: I am assuming you ran the script that I sent previously, and it produced the same errors. If this is not the case, please run that script. If it runs without errors, then the solution is to ensure your program is passing numerical values in the identical fashion as the test script, and that your table was created in postgresql using DOUBLE PRECISION as the data type. Assuming you ran the script I gave you and it produces the same errors, here is a psycopg2 script. Run it on your environment - if it fails, please report the issue to the psycopg2 list, including psycopg2 and postgresql version information, at: http://mail.postgresql.org/mj/mj_wwwusr/domain=postgresql.org?func=li... import psycopg2 conn = psycopg2.connect(user='scott', password='tiger', host='localhost', database='test') cursor = conn.cursor() cursor.execute( CREATE TABLE double_prec_test ( double_value DOUBLE PRECISION ) ) cursor.execute(INSERT INTO double_prec_test VALUES (%(value)s), {'value':7684.4933}) cursor.execute(SELECT * FROM double_prec_test) print cursor.fetchall() cursor.close() conn.close() On Jan 19, 2011, at 12:11 PM, wilbur wrote: Thanks for responding, I am using Postgresql 8.3.8 and Postgis 1.4. I have tried using both DOUBLE_PRECISION and DOUBLE_PRECISION(asdecimal=True), with the same errors. thanks On Jan 18, 3:50 pm, Michael Bayer mike...@zzzcomputing.com wrote: Here's a tested example of DOUBLE_PRECISION using both float and Decimal versions. Make sure you're on a recent release of psycopg2: from sqlalchemy import Column, create_engine, Integer from sqlalchemy.orm import Session from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION from decimal import Decimal Base = declarative_base() class dream4_eta_15km_pm10(Base): __tablename__='pm10_dream_rasters' id = Column(Integer, primary_key=True) # use float values max_pm10=Column(DOUBLE_PRECISION) # use Decimal values mean_pm10=Column(DOUBLE_PRECISION(asdecimal=True)) def __repr__(self): return dream4_eta_15km_pm10(%r, %r) % (self.max_pm10, self.mean_pm10) engine = create_engine('postgresql://scott:tiger@localhost/test', echo=True) Base.metadata.create_all(engine) sess = Session(engine) sess.add(dream4_eta_15km_pm10(max_pm10=76945.283959, mean_pm10=Decimal(7683.27835))) sess.commit() print sess.query(dream4_eta_15km_pm10).all() On Jan 18, 2011, at 3:24 PM, wilbur wrote: Hello, I am having problems using sqlalchemy to write values to Postgresq columns of type Float. I am getting sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt errors when I try to insert records. My Postgresql table is defined as: Column | Type | Modifiers + +-- max_pm25 | double precision | mean_pm25 | double precision | After importing the Postgresql dialect: from sqlalchemy.dialects.postgresql import * I define my sqlalchemy table as: class dream4_eta_15km_pm10(Base): __tablename__='pm10_dream_rasters' max_pm10=Column(DOUBLE_PRECISION) mean_pm10=Column(DOUBLE_PRECISION) Any help appreciated, Bill -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Writing values to Postgresql type Float
Hello, I am having problems using sqlalchemy to write values to Postgresq columns of type Float. I am getting sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt errors when I try to insert records. My Postgresql table is defined as: Column | Type |Modifiers + +-- max_pm25 | double precision | mean_pm25 | double precision | After importing the Postgresql dialect: from sqlalchemy.dialects.postgresql import * I define my sqlalchemy table as: class dream4_eta_15km_pm10(Base): __tablename__='pm10_dream_rasters' max_pm10=Column(DOUBLE_PRECISION) mean_pm10=Column(DOUBLE_PRECISION) Any help appreciated, Bill -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Insert record error
Hi, I am getting an error trying to insert records into a PostgreSQL database with SQLAlchemy. My table definition: class dream4_eta_15km_pm10(Base): __tablename__='pm10_dream_rasters' gid=Column(Integer,Sequence('pm10_dream_rasters_gid_seq'),primary_key=True) rundate=Column(DateTime(timezone=True),nullable=False) datetime=Column(DateTime(timezone=True),nullable=False) location_raw=Column(VARCHAR,nullable=False) location_class=Column(VARCHAR,nullable=False) timezone=Column(DateTime(timezone=False),nullable=False) the_geom=GeometryColumn(Polygon(2),nullable=False) max_pm10=Column(Float,nullable=False) mean_pm10=Column(Float,nullable=False) and, my postgresql table definition: reason=# \d pm25_dream_rasters Table public.pm25_dream_rasters Column | Type |Modifiers + +-- gid| integer| not null default nextval('pm25_dream_rasters_gid_seq'::regclass) the_geom | geometry | rundate| timestamp with time zone | datetime | timestamp with time zone | location_raw | character varying | location_class | character varying | timezone | timestamp(6) without time zone | max_pm25 | double precision | mean_pm25 | double precision | Indexes: pm25_dream_rasters_pkey PRIMARY KEY, btree (gid) pm25_24hour_select btree (((datetime - rundate) '24:00:00'::interval)) pm25_dream_raster_timezone_idx btree (timezone) Check constraints: enforce_dims_the_geom CHECK (ndims(the_geom) = 2) enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL) enforce_srid_the_geom CHECK (srid(the_geom) = 4326) And I get the following error: sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt 'INSERT INTO pm10_dream_rasters (gid, rundate, datetime, location_raw, location_class, timezone, the_geom, max_pm10, mean_pm10) VALUES (% (gid)s, %(rundate)s, %(datetime)s, %(location_raw)s, % (location_class)s, %(timezone)s, GeomFromText(%(GeomFromText_1)s, % (GeomFromText_2)s), %(max_pm10)s, %(mean_pm10)s)' {'rundate': '2011-01-10 00:00:00Z', 'location_raw': '/geodata/edac_dream/ eta_dream4/dream_raw_tiff/20110110/D011011_t00_pm10.tif', 'GeomFromText_1': 'POLYGON((-120.000 43.833,-96.833 43.833,-96.833 26.000,-120.000 26.000,-120.000 43.833))', 'location_class': '/geodata/ edac_dream/eta_dream4/dream_reclass_tiff/20110110/ D011011_t00_pm10.tif', 'datetime': '2011-01-10 00:00:00Z', 'mean_pm10': 0.0, 'gid': 1372073L, 'timezone': '2011-01-10 00:00:00', 'GeomFromText_2': 4326, 'max_pm10': 0.0} I am a little concerned about the value that is being set for the 'gid' variable (e.g. 1372073L). Does this simply indicate some kind of long integer? Is it a possible source of my error? Thanks, Bill -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Insert record error
Thanks! On Jan 13, 1:32 pm, Michael Bayer mike...@zzzcomputing.com wrote: The gid is fine here, its the presence of GeoAlchemy objects sent as bind parameters where they're not able to be rendered as function calls inline with the SQL. You should check with the GeoAlchemy list (http://groups.google.com/group/geoalchemy) with a full example of your insert statement, they can show you the correct way to structure it. On Jan 13, 2011, at 2:58 PM, wilbur wrote: Hi, I am getting an error trying to insert records into a PostgreSQL database with SQLAlchemy. My table definition: class dream4_eta_15km_pm10(Base): __tablename__='pm10_dream_rasters' gid=Column(Integer,Sequence('pm10_dream_rasters_gid_seq'),primary_key=True) rundate=Column(DateTime(timezone=True),nullable=False) datetime=Column(DateTime(timezone=True),nullable=False) location_raw=Column(VARCHAR,nullable=False) location_class=Column(VARCHAR,nullable=False) timezone=Column(DateTime(timezone=False),nullable=False) the_geom=GeometryColumn(Polygon(2),nullable=False) max_pm10=Column(Float,nullable=False) mean_pm10=Column(Float,nullable=False) and, my postgresql table definition: reason=# \d pm25_dream_rasters Table public.pm25_dream_rasters Column | Type | Modifiers + +-- gid | integer | not null default nextval('pm25_dream_rasters_gid_seq'::regclass) the_geom | geometry | rundate | timestamp with time zone | datetime | timestamp with time zone | location_raw | character varying | location_class | character varying | timezone | timestamp(6) without time zone | max_pm25 | double precision | mean_pm25 | double precision | Indexes: pm25_dream_rasters_pkey PRIMARY KEY, btree (gid) pm25_24hour_select btree (((datetime - rundate) '24:00:00'::interval)) pm25_dream_raster_timezone_idx btree (timezone) Check constraints: enforce_dims_the_geom CHECK (ndims(the_geom) = 2) enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL) enforce_srid_the_geom CHECK (srid(the_geom) = 4326) And I get the following error: sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt 'INSERT INTO pm10_dream_rasters (gid, rundate, datetime, location_raw, location_class, timezone, the_geom, max_pm10, mean_pm10) VALUES (% (gid)s, %(rundate)s, %(datetime)s, %(location_raw)s, % (location_class)s, %(timezone)s, GeomFromText(%(GeomFromText_1)s, % (GeomFromText_2)s), %(max_pm10)s, %(mean_pm10)s)' {'rundate': '2011-01-10 00:00:00Z', 'location_raw': '/geodata/edac_dream/ eta_dream4/dream_raw_tiff/20110110/D011011_t00_pm10.tif', 'GeomFromText_1': 'POLYGON((-120.000 43.833,-96.833 43.833,-96.833 26.000,-120.000 26.000,-120.000 43.833))', 'location_class': '/geodata/ edac_dream/eta_dream4/dream_reclass_tiff/20110110/ D011011_t00_pm10.tif', 'datetime': '2011-01-10 00:00:00Z', 'mean_pm10': 0.0, 'gid': 1372073L, 'timezone': '2011-01-10 00:00:00', 'GeomFromText_2': 4326, 'max_pm10': 0.0} I am a little concerned about the value that is being set for the 'gid' variable (e.g. 1372073L). Does this simply indicate some kind of long integer? Is it a possible source of my error? Thanks, Bill -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] ProgrammingError: (ProgrammingError) can't adapt INSERT INTO
Hello, I am having problems inserting data into a postgres table. My model definition: * class dream8_eta_50km_pm25(Base): __tablename__='dream8_eta_50km_pm25' oid=Column(Integer,Sequence('dream8_eta_50km_pm25_oid_seq'),primary_key=True) rundate=Column(DateTime(timezone=True),nullable=False) datetime=Column(DateTime(timezone=True),nullable=False) location_raw=Column(VARCHAR,nullable=False) location_reclass=Column(VARCHAR,nullable=False) timezone=Column(DateTime(timezone=False),nullable=False) the_geom=GeometryColumn(Polygon(2),nullable=False) max_pm25=Column(Float,nullable=False) mean_pm25=Column(Float,nullable=False) GeometryDDL(dream8_eta_50km_pm25.__table__) *** PLUS MY POSTGRESQL TABLE DEFINITION.. enphasys=# \d dream8_eta_50km_pm25 Table public.dream8_eta_50km_pm25 Column |Type | Modifiers --+- + oid | integer | not null default nextval('dream8_eta_50km_pm25_oid_seq'::regclass) rundate | timestamp with time zone| not null datetime | timestamp with time zone| not null location_raw | character varying | not null location_reclass | character varying | not null timezone | timestamp without time zone | not null max_pm25 | double precision| not null mean_pm25| double precision| not null the_geom | geometry| not null Indexes: dream8_eta_50km_pm25_pkey PRIMARY KEY, btree (oid) idx_dream8_eta_50km_pm25_the_geom gist (the_geom) Check constraints: enforce_dims_the_geom CHECK (ndims(the_geom) = 2) enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POLYGON'::text OR the_geom IS NULL) enforce_srid_the_geom CHECK (srid(the_geom) = 4326) *** GIVES ME THE FOLLOWING ERROR: sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt INSERT INTO dream8_eta_50km_pm25 (oid, rundate, datetime, location_raw, location_reclass, timezone, the_geom, max_pm25, mean_pm25) VALUES (nextval('dream8_eta_50km_pm25_oid_seq'), % (rundate)s, %(datetime)s, %(location_raw)s, %(location_reclass)s, % (timezone)s, GeomFromText(%(GeomFromText_1)s, %(GeomFromText_2)s), % (max_pm25)s, %(mean_pm25)s) RETURNING dream8_eta_50km_pm25.oid {'location_reclass': '/geodata/arizona_dream/ eta_dream8/dream_reclass_tiff/20100901/ mcd12_aug0410_eta_dream8_pm25_50km_100901_f00.tif', 'GeomFromText_2': 4326, 'location_raw': '/geodata/arizona_dream/eta_dream8/ dream_raw_tiff/20100901/ mcd12_aug0410_eta_dream8_pm25_50km_100901_f00.tif', 'GeomFromText_1': 'POLYGON((-116.000 40.000,-103.000 40.000,-103.000 30.000,-116.000 30.000,-116.000 40.000))', 'mean_pm25': 4.7778698952101335, 'datetime': '2010-09-01 00:00:00Z', 'timezone': '2010-09-01 00:00:00', 'max_pm25': 29.3267301, 'rundate': '2010-09-01 00:00:00Z'} ANY INSIGHT WOULD BE GREATLY APPRECIATED THANKS, BILL -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.