Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide support for PostgreSQL arrays #13

Open
gnusupport opened this issue Sep 11, 2019 · 2 comments
Open

Provide support for PostgreSQL arrays #13

gnusupport opened this issue Sep 11, 2019 · 2 comments

Comments

@gnusupport
Copy link

Table:

admin=# \d sal_emp
                   Table "public.sal_emp"
     Column     |   Type    | Collation | Nullable | Default 
----------------+-----------+-----------+----------+---------
 name           | text      |           |          | 
 pay_by_quarter | integer[] |           |          | 
 schedule       | text[]    |           |          | 

Result:

(rcd-sql "SELECT schedule from sal_emp;" *admin*)
("{{meeting,lunch},{training,presentation}}" "{{meeting,lunch},{training,presentation},{Assigned,Jean}}")

In my opinion that is poor for Emacs Lisp to receive just textual representation of PostgreSQL arrays. I was expecting to receive some better structure.

Is it feasible to support PostgreSQL arrays so that Emacs Lisp receives better structure out of it?

@gnusupport
Copy link
Author

gnusupport commented Sep 11, 2019

Then I must use something dirty like this:

(defun sql-array-to-list (array)
  "This is temporary function as emacs-libpq does not have
support for PostgreSQL arrays as of 2019-09-11. This function is
replacing all curly brackets with parenthesis, without regard if
parenthesis is contained within the field or values within
arrays. Comas are replaced with spaces. Thus user must be
careful."
  (let* ((array (replace-regexp-in-string "},{" "\"@@@\"" array))
	 (array (replace-regexp-in-string "{{" "((\"" array))
	 (array (replace-regexp-in-string "}}" "\"))" array))
	 (array (replace-regexp-in-string "," "\" \"" array))
	 (array (replace-regexp-in-string "}" ")" array))
	 (array (replace-regexp-in-string "}" ")" array))
	 (array (replace-regexp-in-string "@@@" ") (" array))w
	 (array (concat "'" array)))
    (condition-case nil
	(eval (car (read-from-string array)))
      (error ""))))

If you implement it in the module, then maybe proper arrays can be received instead.

@anse1
Copy link
Owner

anse1 commented Dec 30, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants