On Tue, Apr 14, 2020, at 10:41 AM, Nicolas Caniart wrote:
> Hi !
> 
> I've been looking into the documentation but could not find it.
> What is the proper way to insert a DEFAULT keywork in the tuples of the 
> VALUES clause in an INSERT statement ? As in
> 
> CREATE TABLE number (
>  i INTEGER,
>  letters STRING,
>  roman STRING DEFAULT '',
> ) ;
> 
> INSERT INTO number (c1, c2, c3) VALUES (1, 'one', 'I'), (1000000, 'one 
> million', DEFAULT) ; -- NOTE THE DEFAULT HERE

I'm not familiar with this keyword but to my knowledge there is no need for it 
on any backend I'm familiar with, you instead omit the "roman" column from the 
insert construct itself by only specifying values for the "i" and "letters" 
columns. The "roman" column will not be present and the SQL side default will 
fire off.

If you can share the reason that this special DEFAULT keyword is otherwise 
needed as well as what kind of database this is feel free, literal_column() 
would be the only way to go.

> 
> (yes this example is silly)
> 
> The best I came up with, is using the `literal_column('DEFAULT', type_=...)` 
> construct.
> 
> I wondered if there is a better way, cause I was worried about the keyword 
> possibly getting quoted at some point, though I am not 100% sure that could 
> happen.
> 
> Thanks in advance !
> 
> Regards,
> Nicolas.
> 

> --
>  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 sqlalchemy+unsubscr...@googlegroups.com.
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/9c133c97-a5c6-4863-8f40-d8174949f4d7%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/9c133c97-a5c6-4863-8f40-d8174949f4d7%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/aed920e2-9b42-4791-9d38-52bc6c2287b2%40www.fastmail.com.

Reply via email to