#!/usr/bin/python
# -*- coding: UTF-8 -*-

def sql_insert_generate( table, fields, returning = None ):
    if isinstance( fields, ( str ) ):
        fields = [ fields ]
    
    if not isinstance( fields, ( list, tuple, ) ):
        raise Exception( "list or tuple needed as fields" )
    
    f = ",".join( fields )
    place_holder = ",".join( [ "%s" ] * len( fields ) )
    sql = "INSERT INTO {} ({}) VALUES ({})".format( table, f, place_holder )
    
    if returning != None:
        sql += " RETURNING {}".format( returning )
        
    return sql
