0

I have the following schema in django.

class function(models.Model):
    func_id = models.IntegerField(primary_key=True)
    func_name = models.CharField(max_length=30)
    func_args = JSONField()
    func_version = models.CharField(max_length=20)
    func_desc = models.CharField(max_length=500)
    user = models.ForeignKey(user_data,on_delete=models.CASCADE)
    container_path = models.CharField(max_length=200)
    class Meta:
        db_table = 'function'

When I am trying to run the following query in postgres shell

INSERT INTO
function(func_id,func_name,func_args,func_version,func_desc,user_id,container_path) 
VALUES (101,'Sum',{"input1":"a","input2":"b"},'1.7','blahblah',105,'/path');

I am getting below error:

ERROR:  syntax error at or near "{"
LINE 1: ...nc_desc,user_id,container_path) VALUES (101,'Sum',{"input1":...

Any clue where I am going wrong?

1
  • 1
    This needs to be inserted as a string, so VALUES (101, 'Sum', '{ ... }', ...); Commented Jul 18, 2020 at 20:02

1 Answer 1

2

Try enclosing your JSON in single quotes '{...}'. Even though JSONField supposedly works with python dictionaries, when doing raw SQL, postgresql won't understand that syntax.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.