Revision 3061
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
572 | 572 |
|
573 | 573 |
row_count = CustomCode('count(*)') |
574 | 574 |
|
575 |
coalesce = InternalFunction('COALESCE') |
|
575 |
class Coalesce(FunctionCall): |
|
576 |
def __init__(self, *args): |
|
577 |
FunctionCall.__init__(self, InternalFunction('COALESCE'), *args) |
|
576 | 578 |
|
577 | 579 |
# See <http://www.postgresql.org/docs/8.3/static/datatype-numeric.html> |
578 | 580 |
null_sentinels = { |
... | ... | |
583 | 585 |
'timestamp with time zone': 'infinity' |
584 | 586 |
} |
585 | 587 |
|
586 |
class EnsureNotNull(FunctionCall):
|
|
588 |
class EnsureNotNull(Coalesce):
|
|
587 | 589 |
def __init__(self, value, type_): |
588 |
FunctionCall.__init__(self, coalesce, as_Col(value),
|
|
590 |
Coalesce.__init__(self, as_Col(value),
|
|
589 | 591 |
Cast(type_, null_sentinels[type_])) |
590 | 592 |
|
591 | 593 |
self.type = type_ |
... | ... | |
594 | 596 |
col = self.args[0] |
595 | 597 |
index_col_ = index_col(col) |
596 | 598 |
if index_col_ != None: return index_col_.to_str(db) |
597 |
return FunctionCall.to_str(self, db)
|
|
599 |
return Coalesce.to_str(self, db)
|
|
598 | 600 |
|
599 | 601 |
##### Table exprs |
600 | 602 |
|
Also available in: Unified diff
sql_gen.py: Added Coalesce class and use it in EnsureNotNull