{"id":6967,"date":"2014-05-16T01:14:42","date_gmt":"2014-05-16T01:14:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/16\/sqlite-table-constraint-unique-on-multiple-columns-collection-of-common-programming-errors\/"},"modified":"2014-05-16T01:14:42","modified_gmt":"2014-05-16T01:14:42","slug":"sqlite-table-constraint-unique-on-multiple-columns-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/16\/sqlite-table-constraint-unique-on-multiple-columns-collection-of-common-programming-errors\/","title":{"rendered":"Sqlite table constraint &#8211; unique on multiple columns-Collection of common programming errors"},"content":{"rendered":"<p>I can find syntax &#8220;charts&#8221; on this on the sqlite website, but no examples and my code is crashing. I have other tables with unique constraints on a single column, but I want to add a constraint to the table on two columns. This is what I have that is causing a SQLiteException with the message &#8220;syntax error&#8221;.<\/p>\n<p>CREATE TABLE name (column defs) UNIQUE (col_name1, col_name2) ON CONFLICT REPLACE<\/p>\n<p>I&#8217;m doing this based on the following:<\/p>\n<p>table-constraint<\/p>\n<p><strong>EDIT:<\/strong> To be clear, the documentation on the link I provided says that <code>CONTSTRAINT name<\/code> should come before my constraint definition.<\/p>\n<p>Something that may lead to the solution though is that whatever follows my parenthesized column definitions is what the debugger complains about.<\/p>\n<p>If I put<\/p>\n<pre><code>...last_column_name last_col_datatype) CONSTRAINT ...\n<\/code><\/pre>\n<p>the error is <strong>near &#8220;CONSTRAINT&#8221;: syntax error<\/strong><\/p>\n<p>If I put<\/p>\n<pre><code>...last_column_name last_col_datatype) UNIQUE ...\n<\/code><\/pre>\n<p>the error is <strong>near &#8220;UNIQUE&#8221;: syntax error<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I can find syntax &#8220;charts&#8221; on this on the sqlite website, but no examples and my code is crashing. I have other tables with unique constraints on a single column, but I want to add a constraint to the table on two columns. This is what I have that is causing a SQLiteException with the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6967","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6967"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6967\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}