honeysql

Gonzalo Rafael Acosta 2023-07-05T22:50:38.520649Z

Hello all, quick beginners question, how do you declare an array type in a create table statement?

CREATE TABLE table_name (attribute_name INT[])

seancorfield 2023-07-05T23:45:01.260439Z

You probably need to use [:raw "INT[]"] for that.

👍 1
Gonzalo Rafael Acosta 2023-07-06T00:36:52.776889Z

👌 thanks

Pragyan Tripathi 2023-07-06T07:08:28.037109Z

I registered a function to do extactly this

(hsql/register-fn! :array (fn [_ [type]]
                            (if type
                              [(str (hsql/sql-kw type) "[]")]
                              ["'[]'"])))

#_(hsql/format [:array :int])
  ;; => ["INT[]"]

#_(hsql/format {:create-table :table-name
                :with-columns [[:attribute-name [:array :int]]]})
  ;; => ["CREATE TABLE table_name (attribute_name INT[])"]

seancorfield 2023-07-06T16:28:24.332719Z

@pragyan474 That's probably not a good idea since there's a built-in for :array already https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.1045/doc/getting-started/sql-special-syntax-#array -- it just means something different.

Pragyan Tripathi 2023-07-07T00:56:48.728429Z

Oh. Thanks for pointing it out.