[orm-devel] No such attribute or function 'oid'
Eric Walstad
orm-devel@mailman.tux4web.de
Tue, 14 Jan 2003 21:01:05 -0800
Hi Mike,
This is an interesting idea. The view I'm working on uses multiple
tables, none of which, in this query, will provide a unique oid in the
result set. I wonder if PostgreSQL has a function that will give me the
equivilent of a SERIAL in the query results(?). I could then add that
column to the query and name it oid, perhaps. In the mean time, I've
implemented Diedrich's solution of using ds.runSelect(), which is
working nicely.
Thanks for the lead.
Eric.
--
_________________________
Eric Walstad
222 Winfield Street
San Francisco, CA 94110
415-643-0812 voice & fax
eric@ericwalstad.com
_________________________
Mike Watkins wrote:
> Yes, you can... a little trick - add "oid" into your select statement.
> Its a hidden column in each table.
>
> For example the view:
>
> create view v_published_docs as
> select d.oid, d.id, d.references_id, d.title, d.abstract,
> d.content_type_id, d.lang_id, d.author_id, d.create_date,
> d.modified_date,
> d.publish_date, d.expiry_date, d.is_syndicated from document d
> where references_id is null and d.status = 1 and d.publish_date <= now();
>
> Supports this object:
>
> class DocumentList(dbclass):
> tableName='v_published_docs'
> columns = {
> "id" : serial() ,
> # "references_id" : # since it references itself, has to
> be defined after class is defined, see below
> "title" : varchar() ,
> "abstract" : text() ,
> "content_type_id" : one2one(ContentType) ,
> "lang_id" : one2one(Lang) ,
> "author_id" : one2one(Person) ,
> "create_date" : timestamp() ,
> "modified_date" : timestamp() ,
> "publish_date" : timestamp() ,
> "expiry_date" : timestamp() ,
> "is_syndicated" : boolean()
> }
>
>
> At 10:43 PM 1/12/2003 -0800, you wrote:
>
>> Diedrich,
>> I guess that I can't work with PostgreSQL views as orm objects because
>> views don't have oid's(?). It seems orm is reliant on oid (at least
>> for PostgreSQL). It might be nice to be able to specify the primary
>> key in when creating the dbclass subclass and having it us the pk
>> instead of the oid. Just a thought.
>>
>> Best regards,
>>
>> Eric.
>>
>> --
>> _________________________
>>
>> Eric Walstad
>> 222 Winfield Street
>> San Francisco, CA 94110
>> 415-643-0812 voice & fax
>> eric@ericwalstad.com
>> _________________________
>>
>>
>>
>>
>> funds = self.ds.selectByClauses(funding_summary, where="fsid = %d" %
>> self.invoice.id).fetchall()
>>
>> ============================================================
>> SELECT funding_summary.oid,
>> funding_summary.time_start,funding_summary.name,funding_summary.funding_limit,funding_summary.days_remain,funding_summary.time_end,funding_summary.fsid,funding_summary.amt_remain
>> FROM funding_summary WHERE fsid = 318
>> ============================================================
>> Traceback (most recent call last):
>> File "ewwork.py", line 514, in OnLinkToFundingSources
>> funds = self.ds.selectByClauses(funding_summary, where="fsid = %d"
>> % self.invoice.id).fetchall()
>> File "/usr/lib/python2.2/site-packages/orm/datasource.py", line 302,
>> in selectByClauses
>> return self.runSelect(dbclass, query)
>> File
>> "/usr/lib/python2.2/site-packages/orm/adapters/pgsql/datasource.py",
>> line 286, in runSelect
>> return orm.datasource.datasource_base.runSelect(self, dbclass, query)
>> File "/usr/lib/python2.2/site-packages/orm/datasource.py", line 331,
>> in runSelect
>> cursor = self.execute(query)
>> File
>> "/usr/lib/python2.2/site-packages/orm/adapters/pgsql/datasource.py",
>> line 376, in execute
>> cursor.execute(query)
>> psycopg.ProgrammingError: ERROR: No such attribute or function 'oid'
>>
>> Eric Walstad wrote:
>>
>>> Diedrich,
>>> I forgot to mention that I have a PostgreSQL view with an "interval"
>>> data type:
>>> View "funding_summary"
>>> Column | Type | Modifiers
>>> ---------------+-----------------------------+-----------
>>> fsid | integer |
>>> ...
>>> days_remain | interval |
>>> Notice that days_remain is of type interval, which when rendered
>>> looks like:
>>> SELECT days_remain FROM funding_summary LIMIT 1;
>>> days_remain
>>> -------------
>>> 213 days
>>> (1 row)
>>> I'm just starting to play around with this view, but I'm assuming
>>> that I should have a dbclass definition like this:
>>> # Views
>>> class funding_summary(dbclass):
>>> columns = {"fsid" :integer(),
>>> ...
>>> "days_remain" :varchar()}
>>> That is, that the "interval" type should be a "varchar" orm column.
>>> Is it reasonable to request you add an alias for interval types?
>>> Thanks,
>>> Eric.