On Wed, Mar 14, 2018 at 11:50 AM, Colton Allen <[email protected]> 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]. > 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. <div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 14, 2018 at 11:50 AM, Colton Allen <span dir="ltr"><<a href="mailto:[email protected]" target="_blank">[email protected]</a>></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. 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"> </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> 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> 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> <br> <a href="http://www.sqlalchemy.org/" target="_blank" data-saferedirecturl="https://www.google.com/url?hl=en&q=http://www.sqlalchemy.org/&source=gmail&ust=1521129429269000&usg=AFQjCNHmvgsT_kDCoTqpNxlDfBETa_ObHg">http://www.sqlalchemy.org/</a><br> <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&q=http://stackoverflow.com/help/mcve&source=gmail&ust=1521129429270000&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]" target="_blank">sqlalchemy+unsubscribe@<wbr>googlegroups.com</a>.<br> To post to this group, send email to <a href="mailto:[email protected]" target="_blank">[email protected]</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&q=https://groups.google.com/group/sqlalchemy&source=gmail&ust=1521129429270000&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&q=https://groups.google.com/d/optout&source=gmail&ust=1521129429270000&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.
