Casting raised this error:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) cannot cast 
type outcome_kind to trigger_event

This is what it looks like in the select:

cast(outcome.c.kind, trigger.c.on_event.type)

Outcome kind and trigger event are identical besides their name.

On Wednesday, March 14, 2018 at 8:58:21 AM UTC-7, Mike Bayer wrote:
>
> On Wed, Mar 14, 2018 at 11:50 AM, Colton Allen <[email protected] 
> <javascript:>> wrote: 
> > I'm trying to copy an enum of one type to an enum of another type.  The 
> > below is the query I'm using: 
> > 
> >     import sqlalchemy as sa 
> > 
> >     statement = sa.insert(table_a).from_select(['enum_a'], 
> > sa.select(table_b.c.enum_b)) 
> >     connection.execute(statement) 
> > 
> > Which raises this error in Postgres: 
> > 
> > Error: (psycopg2.ProgrammingError) column "enum_a" is of type enum_a but 
> > expression is of type enum_b 
> > 
> > Is there a way to parse the enum to its string-value and just insert 
> that? 
>
> did you try casting?  select([cast(table_b.c.enum_b, 
> table_a.c.enum_a.type)]) 
>
>
>
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "sqlalchemy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
> <div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 14, 
> 2018 at 11:50 AM, Colton Allen <span dir="ltr">&lt;<a 
> href="mailto:[email protected] <javascript:>" 
> target="_blank">[email protected] <javascript:></a>&gt;</span> 
> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 
> .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm 
> trying to copy an enum of one type to an enum of another type.&nbsp; 
> The below is the query I'm using:<br><br><div 
> style="background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px"
>  
>
> class="m_5346237645183833733prettyprint"><code 
> class="m_5346237645183833733prettyprint"><div 
> class="m_5346237645183833733subprettyprint"><span style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">&nbsp; &nbsp; 
> </span><span style="color:#008" 
> class="m_5346237645183833733styled-by-prettify">import</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> 
> sqlalchemy </span><span style="color:#008" 
> class="m_5346237645183833733styled-by-prettify">as</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> 
> sa<br><br>&nbsp; &nbsp; statement </span><span style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">=</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> 
> sa</span><span style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">.</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">insert</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">(</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">table_a</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">).</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">from_select</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify"><wbr>([</span><span 
> style="color:#080" 
> class="m_5346237645183833733styled-by-prettify">'enum_a'</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">],</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> 
> sa</span><span style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">.</span><span 
> style="color:#008" 
> class="m_5346237645183833733styled-by-prettify">select</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">(</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">table_b</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">.</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">c</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">.</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">enum_b</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">))</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify"><br>&nbsp; &nbsp; 
> connection</span><span style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">.</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">execute</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">(</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">statement</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">)</span></div></code></div><br>Which
>  
>
> raises this error in Postgres:<br><br><div 
> style="background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px"
>  
>
> class="m_5346237645183833733prettyprint"><code 
> class="m_5346237645183833733prettyprint"><div 
> class="m_5346237645183833733subprettyprint"><span style="color:#606" 
> class="m_5346237645183833733styled-by-prettify">Error</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">:</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> 
> </span><span style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">(</span><span 
> style="color:#000" 
> class="m_5346237645183833733styled-by-prettify">psycopg2</span><span 
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">.</span><span 
> style="color:#606" 
> class="m_5346237645183833733styled-by-prettify">ProgrammingError</span><span 
>
> style="color:#660" 
> class="m_5346237645183833733styled-by-prettify">)</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> 
> column </span><span style="color:#080" 
> class="m_5346237645183833733styled-by-prettify">"enum_a"</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> 
> </span><span style="color:#008" 
> class="m_5346237645183833733styled-by-prettify">is</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> of 
> type enum_a but expression </span><span style="color:#008" 
> class="m_5346237645183833733styled-by-prettify">is</span><span 
> style="color:#000" class="m_5346237645183833733styled-by-prettify"> of 
> type enum_b</span></div></code></div><br>Is there a way to parse the 
> enum to its string-value and just insert that?<br></div> 
>
> <p></p> 
>
> -- <br> 
> SQLAlchemy - <br> 
> The Python SQL Toolkit and Object Relational Mapper<br> 
> &nbsp;<br> 
> <a href="http://www.sqlalchemy.org/"; target="_blank" 
> data-saferedirecturl="
> https://www.google.com/url?hl=en&amp;q=http://www.sqlalchemy.org/&amp;source=gmail&amp;ust=1521129429269000&amp;usg=AFQjCNHmvgsT_kDCoTqpNxlDfBETa_ObHg
> ">http://www.sqlalchemy.org/</a><br> 
> &nbsp;<br> 
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example.  See  <a href="http://stackoverflow.com/help/mcve"; 
> target="_blank" 
> data-saferedirecturl="
> https://www.google.com/url?hl=en&amp;q=http://stackoverflow.com/help/mcve&amp;source=gmail&amp;ust=1521129429270000&amp;usg=AFQjCNHGKzBS14DGg_cFrRN-n-IzpJfk1g
> ">http://stackoverflow.com/help/<wbr>mcve</a> 
> for a full description.<br> 
> --- <br> 
> You received this message because you are subscribed to the Google 
> Groups "sqlalchemy" group.<br> 
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to <a href="mailto:[email protected] 
> <javascript:>" 
> target="_blank">sqlalchemy+unsubscribe@<wbr>googlegroups.com</a>.<br> 
> To post to this group, send email to <a 
> href="mailto:[email protected] <javascript:>" 
> target="_blank">[email protected] <javascript:></a>.<br> 
> Visit this group at <a 
> href="https://groups.google.com/group/sqlalchemy"; target="_blank" 
> data-saferedirecturl="
> https://www.google.com/url?hl=en&amp;q=https://groups.google.com/group/sqlalchemy&amp;source=gmail&amp;ust=1521129429270000&amp;usg=AFQjCNEOgO9C-lc66rrcMzLixdGjRtIxcw
> ">https://groups.google.com/<wbr>group/sqlalchemy</a>.<br> 
> For more options, visit <a href="https://groups.google.com/d/optout"; 
> target="_blank" 
> data-saferedirecturl="
> https://www.google.com/url?hl=en&amp;q=https://groups.google.com/d/optout&amp;source=gmail&amp;ust=1521129429270000&amp;usg=AFQjCNEOAw5y_nxPN5IevQQswx7IVim_0Q
> ">https://groups.google.com/d/<wbr>optout</a>.<br> 
> </blockquote></div><br></div> 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to