From marijnh at gmail.com Wed Feb 2 11:37:18 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Wed, 2 Feb 2011 12:37:18 +0100 Subject: [postmodern-devel] Release 1.17 Message-ID: Most users are probably already using the git HEAD (which is pretty safe, since I don't push many wild experimental patches), but I just released a new version. The important changes are: * Fixes day-of-week in simple-date. * Makes the :plist query format actually work. * Adds sql-escape as an exported symbol for client code that needs to escape stuff. * Adds support for multi-dimensional arrays. * Adds the *ignore-unknown-columns* configuration variable. Cheers, Marijn From fbogdanovic at xnet.hr Sat Feb 5 14:41:54 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sat, 5 Feb 2011 15:41:54 +0100 Subject: [postmodern-devel] :set arguments Message-ID: <338CE9C98591479C8E51904BB323C44A@komp> (sql (:insert-into 'kupci :set (:raw (if (/= (length (parameter "ime")) 0) (sql ('ime (parameter "ime"))))))) For this I get an error: Invalid amount of :set arguments passed to insert-into sql operator Why is that ? Thanks From fbogdanovic at xnet.hr Sat Feb 5 20:30:35 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sat, 5 Feb 2011 21:30:35 +0100 Subject: [postmodern-devel] :set arguments References: <338CE9C98591479C8E51904BB323C44A@komp> Message-ID: <455334D73AD844829D089C8ABA74861F@komp> I simplified the example: (sql (:insert-into 'kupci :set (:raw (if t (sql ('ime "a")))))) and still getting the same error message. Why I can't combine insert-into and :set with (:raw ...) ? From marijnh at gmail.com Sun Feb 6 07:59:24 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 6 Feb 2011 08:59:24 +0100 Subject: [postmodern-devel] :set arguments In-Reply-To: <455334D73AD844829D089C8ABA74861F@komp> References: <338CE9C98591479C8E51904BB323C44A@komp> <455334D73AD844829D089C8ABA74861F@komp> Message-ID: > (sql (:insert-into 'kupci :set (:raw (if t (sql ('ime "a")))))) The :insert-into clause expects the arguments to :set to be a multiple of two. You'll need to use sql-compile to do this. (sql-compile `(:insert-into 'kupci :set ,@(when t (list 'ime "a")))) From fbogdanovic at xnet.hr Sun Feb 6 19:10:26 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sun, 6 Feb 2011 20:10:26 +0100 Subject: [postmodern-devel] :set arguments References: <338CE9C98591479C8E51904BB323C44A@komp><455334D73AD844829D089C8ABA74861F@komp> Message-ID: <6025579EBF0D4C4DBCBFE810400228EE@komp> >> (sql (:insert-into 'kupci :set (:raw (if t (sql ('ime "a")))))) > > The :insert-into clause expects the arguments to :set to be a multiple > of two. You'll need to use sql-compile to do this. > > (sql-compile `(:insert-into 'kupci :set ,@(when t (list 'ime "a")))) How do I do it if I have multiple IFs like: (sql-compile `(:insert-into 'kupci :set ,@((if TEST (list 'ime "a") (if TEST2 (list 'prezime "b"))))) or how ? For every field in a database I want to test is even something entered and add that pair of field name and a value to the list. How do I do that ? From marijnh at gmail.com Sun Feb 6 20:31:44 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 6 Feb 2011 21:31:44 +0100 Subject: [postmodern-devel] :set arguments In-Reply-To: <6025579EBF0D4C4DBCBFE810400228EE@komp> References: <338CE9C98591479C8E51904BB323C44A@komp> <455334D73AD844829D089C8ABA74861F@komp> <6025579EBF0D4C4DBCBFE810400228EE@komp> Message-ID: > How do I do it if I have multiple IFs like: > > (sql-compile `(:insert-into 'kupci :set ,@((if TEST (list 'ime "a") > (if TEST2 (list 'prezime "b"))))) The first step would be understanding how quasiquoting works. This is not a Postmodern question, but a basic Common Lisp one. There are other channels for that. From khaelin at gmail.com Sun Feb 13 19:49:44 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 13 Feb 2011 20:49:44 +0100 Subject: [postmodern-devel] encoding problem Message-ID: <8762snr9yf.fsf@gmail.com> I have a query which inserts text containing the '?' character (unicode U+2019). Postmodern seems to generate a correct SQL query, but I get a postgresql error: Database error 08P01: invalid message format The database was created with and UTF-8 encoding. I'm not sure where the problem is, perhaps postmodern doesn't correctly encode multibyte characters. Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From lispnik at gmail.com Sun Feb 13 19:53:32 2011 From: lispnik at gmail.com (Ivan Boldyrev) Date: Mon, 14 Feb 2011 01:53:32 +0600 Subject: [postmodern-devel] encoding problem In-Reply-To: <8762snr9yf.fsf@gmail.com> References: <8762snr9yf.fsf@gmail.com> Message-ID: On Mon, Feb 14, 2011 at 1:49 AM, Nicolas Martyanoff wrote: > > I have a query which inserts text containing the '?' character (unicode > U+2019). Postmodern seems to generate a correct SQL query, but I get a > postgresql error: > Database error 08P01: invalid message format > > Is your Lisp implementation Unicode-aware? Does it work with other Unicode chars? -- Ivan Boldyrev -------------- next part -------------- An HTML attachment was scrubbed... URL: From khaelin at gmail.com Sun Feb 13 19:57:42 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 13 Feb 2011 20:57:42 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: (Ivan Boldyrev's message of "Mon, 14 Feb 2011 01:53:32 +0600") References: <8762snr9yf.fsf@gmail.com> Message-ID: <871v3br9l5.fsf@gmail.com> Ivan Boldyrev writes: > On Mon, Feb 14, 2011 at 1:49 AM, Nicolas Martyanoff < > khaelin at gmail.com> wrote: > > > I have a query which inserts text containing the '?' character > (unicode > U+2019). Postmodern seems to generate a correct SQL query, but I > get a > postgresql error: > ? > > Database error 08P01: invalid message format > > > > Is your Lisp implementation Unicode-aware? ?Does it work with other > Unicode chars? I use sbcl, which has full unicode support. I have a different error message with some characters, for example with '?', I have: Database error 08P01: insufficient data left in message Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From marijnh at gmail.com Sun Feb 13 19:58:39 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 13 Feb 2011 20:58:39 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: <8762snr9yf.fsf@gmail.com> References: <8762snr9yf.fsf@gmail.com> Message-ID: After loading the system, check the value of cl-postgres-system::*unicode* . Is it T? From khaelin at gmail.com Sun Feb 13 20:00:04 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 13 Feb 2011 21:00:04 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: (Marijn Haverbeke's message of "Sun, 13 Feb 2011 20:58:39 +0100") References: <8762snr9yf.fsf@gmail.com> Message-ID: <87tyg7puwr.fsf@gmail.com> Marijn Haverbeke writes: > After loading the system, check the value of > cl-postgres-system::*unicode* . Is it T? Yes it is. -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From marijnh at gmail.com Sun Feb 13 20:22:28 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 13 Feb 2011 21:22:28 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: <87tyg7puwr.fsf@gmail.com> References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> Message-ID: Hm. Then, this would suggest a bug somewhere. Do simpler non-ascii things work? (For example, walk through the quickstart.) Can you give me your Postgres version, and the exact query that goes wrong? Best, Marijn From khaelin at gmail.com Sun Feb 13 20:42:02 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 13 Feb 2011 21:42:02 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: (Marijn Haverbeke's message of "Sun, 13 Feb 2011 21:22:28 +0100") References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> Message-ID: <87pqqvpsyt.fsf@gmail.com> Marijn Haverbeke writes: > Hm. Then, this would suggest a bug somewhere. Do simpler non-ascii > things work? (For example, walk through the quickstart.) Can you give > me your Postgres version, and the exact query that goes wrong? Yep, no problem with ascii. I attached the test file I used: -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- The query is: (postmodern:execute (:update 'posts :set 'title title 'content content 'content-html content-html 'creation-date (date-format-iso-8601 creation-date) 'visible visible-p :where (:= 'id id))) Where content-html contains the string read from the html file. I then get the following error: Database error 08P01: invalid message format Query: UPDATE posts SET title = E'Test', content = E'- Some ascii. - Some UTF-8 (exists in latin 1): ? - Some UTF-8 (does not exist in latin 1): ?', content_html = E'
  • Some ascii.
  • Some UTF?8 (exists in latin 1): ?
  • Some UTF?8 (does not exist in latin 1): ?
', creation_date = E'2011-02-03 08:13:43+01:00', visible = true WHERE (id = E'1') [Condition of type CL-POSTGRES:DATABASE-ERROR] Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From marijnh at gmail.com Sun Feb 13 20:48:18 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 13 Feb 2011 21:48:18 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: <87pqqvpsyt.fsf@gmail.com> References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> <87pqqvpsyt.fsf@gmail.com> Message-ID: > Yep, no problem with ascii. Sure, but that's not what I asked. Does this query from the quickstart work? (query "select 22, 'Folie et d?raison', 4.5") Also, again, which version of Postgres are you using? From khaelin at gmail.com Sun Feb 13 20:54:19 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 13 Feb 2011 21:54:19 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: (Marijn Haverbeke's message of "Sun, 13 Feb 2011 21:48:18 +0100") References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> <87pqqvpsyt.fsf@gmail.com> Message-ID: <87lj1jpsec.fsf@gmail.com> Marijn Haverbeke writes: >> Yep, no problem with ascii. > > Sure, but that's not what I asked. Does this query from the quickstart > work? (query "select 22, 'Folie et d?raison', 4.5") This one works. > Also, again, which version of Postgres are you using? Ooops :) I use the git version, 5fe54bd. Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From marijnh at gmail.com Sun Feb 13 20:57:33 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 13 Feb 2011 21:57:33 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: <87lj1jpsec.fsf@gmail.com> References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> <87pqqvpsyt.fsf@gmail.com> <87lj1jpsec.fsf@gmail.com> Message-ID: >> Also, again, which version of Postgres are you using? > Ooops :) I use the git version, 5fe54bd. I meant PosgreSQL, not Postmodern. From khaelin at gmail.com Sun Feb 13 20:59:49 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 13 Feb 2011 21:59:49 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: (Marijn Haverbeke's message of "Sun, 13 Feb 2011 21:57:33 +0100") References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> <87pqqvpsyt.fsf@gmail.com> <87lj1jpsec.fsf@gmail.com> Message-ID: <87hbc7ps56.fsf@gmail.com> Marijn Haverbeke writes: >>> Also, again, which version of Postgres are you using? > >> Ooops :) I use the git version, 5fe54bd. > > I meant PosgreSQL, not Postmodern. Postgresql 9.0.3 -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From marijnh at gmail.com Mon Feb 14 08:51:36 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Mon, 14 Feb 2011 09:51:36 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: <87hbc7ps56.fsf@gmail.com> References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> <87pqqvpsyt.fsf@gmail.com> <87lj1jpsec.fsf@gmail.com> <87hbc7ps56.fsf@gmail.com> Message-ID: Hi Nicolas, Still no luck reproducing this. Does this simple query fail too? (query "select '?'") If not, you might want to double-check your database encodings. Best, Marijn From stassats at gmail.com Tue Feb 15 02:26:53 2011 From: stassats at gmail.com (Stas Boukarev) Date: Tue, 15 Feb 2011 05:26:53 +0300 Subject: [postmodern-devel] Patch: {} syntax for arrays should be inside '' Message-ID: <87mxlyyqvm.fsf@gmail.com> According to http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-INPUT arrays should look like '{ val1 delim val2 delim ... }', but cl-postgres sends them as {val1 ...}, the attached patch corrects this. -- With Best Regards, Stas. From stassats at gmail.com Tue Feb 15 02:29:05 2011 From: stassats at gmail.com (Stas Boukarev) Date: Tue, 15 Feb 2011 05:29:05 +0300 Subject: [postmodern-devel] Patch: {} syntax for arrays should be inside '' In-Reply-To: <87mxlyyqvm.fsf@gmail.com> (Stas Boukarev's message of "Tue, 15 Feb 2011 05:26:53 +0300") References: <87mxlyyqvm.fsf@gmail.com> Message-ID: <87ipwmyqry.fsf@gmail.com> Stas Boukarev writes: > According to > http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-INPUT > arrays should look like '{ val1 delim val2 delim ... }', but cl-postgres > sends them as {val1 ...}, the attached patch corrects this. Well, that was too soon, I forgot to attach the patch itself: -------------- next part -------------- A non-text attachment was scrubbed... Name: arrays.diff Type: text/x-patch Size: 279 bytes Desc: not available URL: -------------- next part -------------- -- With Best Regards, Stas. From stassats at gmail.com Tue Feb 15 02:32:54 2011 From: stassats at gmail.com (Stas Boukarev) Date: Tue, 15 Feb 2011 05:32:54 +0300 Subject: [postmodern-devel] Patch: {} syntax for arrays should be inside '' In-Reply-To: <87ipwmyqry.fsf@gmail.com> (Stas Boukarev's message of "Tue, 15 Feb 2011 05:29:05 +0300") References: <87mxlyyqvm.fsf@gmail.com> <87ipwmyqry.fsf@gmail.com> Message-ID: <87ei7ayqll.fsf@gmail.com> Stas Boukarev writes: > Stas Boukarev writes: > >> According to >> http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-INPUT >> arrays should look like '{ val1 delim val2 delim ... }', but cl-postgres >> sends them as {val1 ...}, the attached patch corrects this. Aw, now I hit C-x C-w in the wrong buffer, that's what you get for being in a hurry. Sorry for the noise, here's the patch for real. -------------- next part -------------- A non-text attachment was scrubbed... Name: arrays.diff Type: text/x-patch Size: 1423 bytes Desc: not available URL: -------------- next part -------------- -- With Best Regards, Stas. From marijnh at gmail.com Tue Feb 15 06:48:03 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Tue, 15 Feb 2011 07:48:03 +0100 Subject: [postmodern-devel] Patch: {} syntax for arrays should be inside '' In-Reply-To: <87ei7ayqll.fsf@gmail.com> References: <87mxlyyqvm.fsf@gmail.com> <87ipwmyqry.fsf@gmail.com> <87ei7ayqll.fsf@gmail.com> Message-ID: Hi Stas, What happens when, with your patch, you try to pass an array as a query parameter? ($1, etc) I suspect the correct thing to do would be to return T as a second value from to-sql-string (which indicates that the string should be escaped when put into a query), rather than putting quotes into the returned string. Also, do you know what the correct syntax is when the array contains a string containing a single quote? I suspect it should be escaped, which will also be handled by returning a second t value. If you could test this for me, I'd be thankful. Cheers, Marijn From khaelin at gmail.com Tue Feb 15 07:38:24 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Tue, 15 Feb 2011 08:38:24 +0100 Subject: [postmodern-devel] table name problem Message-ID: <87fwrpoihb.fsf@gmail.com> Hi, When trying to reproduce my encoding bug, I found a problem when a field is named "t". CREATE TABLE test (t TEXT NOT NULL); (postmodern:execute (:insert-into 'test :set 't "utf8 ?")) Database error 42601: syntax error at or near "true" Query: INSERT INTO test (true) VALUES (E'utf8 ?') [Condition of type CL-POSTGRES-ERROR:SYNTAX-ERROR-OR-ACCESS-VIOLATION] Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From marijnh at gmail.com Tue Feb 15 07:44:56 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Tue, 15 Feb 2011 08:44:56 +0100 Subject: [postmodern-devel] table name problem In-Reply-To: <87fwrpoihb.fsf@gmail.com> References: <87fwrpoihb.fsf@gmail.com> Message-ID: cl:t, cl:nil, and :null have a special meaning in s-sql. In this case, you can work around it by using :t or '#:t instead of 't in your query. From khaelin at gmail.com Tue Feb 15 07:52:02 2011 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Tue, 15 Feb 2011 08:52:02 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: (Marijn Haverbeke's message of "Mon, 14 Feb 2011 09:51:36 +0100") References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> <87pqqvpsyt.fsf@gmail.com> <87lj1jpsec.fsf@gmail.com> <87hbc7ps56.fsf@gmail.com> Message-ID: <87bp2dohul.fsf@gmail.com> Marijn Haverbeke writes: > Hi Nicolas, > > Still no luck reproducing this. Does this simple query fail too? > (query "select '?'") All right, I finally figured out the problem. The string came from a file, which was loaded with: (defun file-read (filename) (with-open-file (stream filename) (let ((content (make-string (file-length stream)))) (read-sequence content stream) content))) This didn't correctly handle multibyte characters, and yielded a string containg null bytes at the end. This triggered the error. Using the following works perfectly: (defun file-read (filename) (with-open-file (stream filename :element-type '(unsigned-byte 8)) (let ((content (make-array (file-length stream) :element-type '(unsigned-byte 8)))) (read-sequence content stream) (babel:octets-to-string content)))) Sorry for the noise, and thank you for trying to help me. Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com From marijnh at gmail.com Tue Feb 15 08:02:57 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Tue, 15 Feb 2011 09:02:57 +0100 Subject: [postmodern-devel] encoding problem In-Reply-To: <87bp2dohul.fsf@gmail.com> References: <8762snr9yf.fsf@gmail.com> <87tyg7puwr.fsf@gmail.com> <87pqqvpsyt.fsf@gmail.com> <87lj1jpsec.fsf@gmail.com> <87hbc7ps56.fsf@gmail.com> <87bp2dohul.fsf@gmail.com> Message-ID: > Sorry for the noise, and thank you for trying to help me. No problem, glad to see you figured it out. Cheers, Marijn From stassats at gmail.com Tue Feb 15 15:16:59 2011 From: stassats at gmail.com (Stas Boukarev) Date: Tue, 15 Feb 2011 18:16:59 +0300 Subject: [postmodern-devel] Patch: {} syntax for arrays should be inside '' In-Reply-To: (Marijn Haverbeke's message of "Tue, 15 Feb 2011 07:48:03 +0100") References: <87mxlyyqvm.fsf@gmail.com> <87ipwmyqry.fsf@gmail.com> <87ei7ayqll.fsf@gmail.com> Message-ID: <878vxhz5sk.fsf@gmail.com> Marijn Haverbeke writes: > Hi Stas, > > What happens when, with your patch, you try to pass an array as a > query parameter? ($1, etc) I suspect the correct thing to do would be > to return T as a second value from to-sql-string (which indicates that > the string should be escaped when put into a query), rather than > putting quotes into the returned string. Also, do you know what the > correct syntax is when the array contains a string containing a single > quote? I suspect it should be escaped, which will also be handled by > returning a second t value. If you could test this for me, I'd be > thankful. Indeed, returning T works in all cases you described. I've attached a corrected patch. -------------- next part -------------- A non-text attachment was scrubbed... Name: arrays-2.diff Type: text/x-patch Size: 2898 bytes Desc: not available URL: -------------- next part -------------- -- With Best Regards, Stas. From marijnh at gmail.com Tue Feb 15 15:47:16 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Tue, 15 Feb 2011 16:47:16 +0100 Subject: [postmodern-devel] Patch: {} syntax for arrays should be inside '' In-Reply-To: <878vxhz5sk.fsf@gmail.com> References: <87mxlyyqvm.fsf@gmail.com> <87ipwmyqry.fsf@gmail.com> <87ei7ayqll.fsf@gmail.com> <878vxhz5sk.fsf@gmail.com> Message-ID: Thanks! Pushed to the repository. Best, Marijn From fbogdanovic at xnet.hr Thu Feb 17 10:16:15 2011 From: fbogdanovic at xnet.hr (Haris) Date: Thu, 17 Feb 2011 11:16:15 +0100 Subject: [postmodern-devel] update example Message-ID: Hi. Can you just give me an update example with :where statement ? Thanks From marijnh at gmail.com Thu Feb 17 10:30:16 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Thu, 17 Feb 2011 11:30:16 +0100 Subject: [postmodern-devel] update example In-Reply-To: References: Message-ID: Hi Haris, The docs are a bit unclear on this one. I've updated them. Here's an example (s-sql:sql (:update 'foo :set 'a 10 'b 20 :where (:= 'c 30))) Best, Marijn From fbogdanovic at xnet.hr Sat Feb 19 13:37:39 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sat, 19 Feb 2011 14:37:39 +0100 Subject: [postmodern-devel] date Message-ID: Hi. I know this may not be the right place to ask such a question, can you give me a link to some postgresql mailing list, I found them many, I don't know which one to choose ? How to enter date and time in a date field ? Is there a default value for date field like current date and time ? Thanks From lucas.r.hope at gmail.com Sun Feb 20 02:22:27 2011 From: lucas.r.hope at gmail.com (Lucas Hope) Date: Sun, 20 Feb 2011 13:22:27 +1100 Subject: [postmodern-devel] date In-Reply-To: References: Message-ID: PostgreSQL itself has excellent documentation, with examples. This is what I use normally - Google: "postgresql 9 documentation" http://www.postgresql.org/docs/current/static/ Google again: "postgresql 9 date time". http://www.postgresql.org/docs/9.0/static/datatype-datetime.html Peace, and thanks for understanding that this is support for postmodern and not a general tutorial for SQL. -Luke On Sun, Feb 20, 2011 at 12:37 AM, Haris wrote: > Hi. > > I know this may not be the right place to ask such a question, > can you give me a link to some postgresql mailing list, > I found them many, I don't know which one to choose ? > How to enter date and time in a date field ? > Is there a default value for date field like current > date and time ? > > Thanks > > > _______________________________________________ > postmodern-devel mailing list > postmodern-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel > -- --------------------------------------------------- Dr Lucas Hope - lucas.r.hope at skype Machine Learning and Software Engineering Consultant Melbourne, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: From fbogdanovic at xnet.hr Sun Feb 20 16:47:18 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sun, 20 Feb 2011 17:47:18 +0100 Subject: [postmodern-devel] date References: Message-ID: I found out that there is a timestamp type, that's what I really need. How do I do insert-into then with timestamp field: (:insert-into 'table :set 'ts :now) This doesn't work. How do I insert current date/time then ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From marijnh at gmail.com Sun Feb 20 21:10:44 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 20 Feb 2011 22:10:44 +0100 Subject: [postmodern-devel] date In-Reply-To: References: Message-ID: > (:insert-into 'table :set 'ts :now) > > This doesn't work. > How do I insert current date/time then ? Try (:insert-into 'table :set 'ts (:now)) . From fbogdanovic at xnet.hr Tue Feb 22 19:26:06 2011 From: fbogdanovic at xnet.hr (Haris) Date: Tue, 22 Feb 2011 20:26:06 +0100 Subject: [postmodern-devel] :order-by Message-ID: Hi. How to use :order-by (or :desc): (:select '* :from 'table :order-by 'column) doesn't work ? Thanks From marijnh at gmail.com Tue Feb 22 19:29:26 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Tue, 22 Feb 2011 20:29:26 +0100 Subject: [postmodern-devel] :order-by In-Reply-To: References: Message-ID: (:order-by (:select '* :from 'table) (:desc 'column)) From fbogdanovic at xnet.hr Fri Feb 25 19:58:26 2011 From: fbogdanovic at xnet.hr (Haris) Date: Fri, 25 Feb 2011 20:58:26 +0100 Subject: [postmodern-devel] strange Message-ID: <33FE51846D254145B2639868077D0169@komp> I have a query like: (query (sql-compile `(:insert-into 'kupci :set ,@(list 'vrijemeunosa (:now))))) If I try to execute it from repl it works but when called within function I get Undefined function :NOW called with arguments () ? From marijnh at gmail.com Fri Feb 25 20:35:43 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Fri, 25 Feb 2011 21:35:43 +0100 Subject: [postmodern-devel] strange In-Reply-To: <33FE51846D254145B2639868077D0169@komp> References: <33FE51846D254145B2639868077D0169@komp> Message-ID: > (query (sql-compile `(:insert-into 'kupci :set > ,@(list 'vrijemeunosa (:now))))) > > If I try to execute it from repl it works > but when called within function I get This does not work from the repl either. You forgot a quote. From jpl at thoughtcrime.us Sat Feb 26 02:29:42 2011 From: jpl at thoughtcrime.us (J.P. Larocque) Date: Fri, 25 Feb 2011 18:29:42 -0800 Subject: [postmodern-devel] :IN/:NOT-IN on an empty :SET always results in :NULL Message-ID: <20110226022941.GA21080@planetarium.thoughtcrime.us> Hi, I'd like to be able to write a query similar to: (let ((set ...)) (postmodern:sql (:select ... :from ... :where (:not-in ... (:set set))))) But SET could be empty. This results in the query: (SELECT ... FROM ... WHERE (... NOT IN (NULL))) (The same happens when simply (:SET) is given.) S-SQL compiles an empty set to "(NULL)", whether the empty set is expressed statically with no arguments, or with a single argument evaluating to the empty list. The problem is that "(NULL)" does not express the empty set. The PostgreSQL IN and NOT IN operators (at least for explicit sets on the right-hand side) are defined[1] to evaluate to NULL whenever: * NULL is a member of the literal set on the right-hand side, and * The left-hand side value is not a member of the set. (Or of course the left-hand side is NULL.) [1] http://www.postgresql.org/docs/8.3/static/functions-comparisons.html#AEN15459 This means that (:IN x (:SET)) and (:IN x (:SET y)), for any value of x and for y being the empty list, both always result in :NULL. The same goes for :NOT-IN. (postmodern:query (:select (:in 42 (:set))) :single) => :NULL ...where the result should be NIL (is 42 is a member of the empty set? no). (postmodern:query (:select (:not-in 42 (:set))) :single) == (postmodern:query (:select (:not (:in 42 (:set)))) :single) => :NULL ...where the result should be T (is 42 not a member of the empty set? yes). This is probably going to be tricky to solve. The above part of the PostgreSQL manual doesn't say anything about expressing an empty set on the RHS of IN/NOT IN. I tried looking through the grammar[2], but it's rather unwieldy and hard for me to follow. [2] http://git.postgresql.org/gitweb?p=postgresql.git;a=blob;f=src/backend/parser/gram.y;hb=HEAD Some people[3] suggest expressing the empty set as e.g. (SELECT 1 WHERE FALSE): > select 42 in (select 1 where false); ?column? ---------- f (1 row) [3] http://groups.google.com/group/pgsql.general/msg/736022e9c06affac?hl=en But the problem with this is that this empty set is typed: > select 'foo' in (select 1 where false); ERROR: invalid input syntax for integer: "foo" So, the tricky problem is: how does one correctly compile an empty :SET S-SQL expression to an expression of an empty set, that works in any context (that is, no matter what the data type of the LHS is)? Instead, maybe some trickery can be done in the definition for :IN. It could check to see whether the RHS is an S-SQL expression for the empty set and, if so, result in "false" (or "true" for :NOT-IN). This would be ugly, but closer to correct. (Caveat: when the LHS is null at query time, the result has to be NULL. So, when the RHS of :IN is the empty set, the expander would have to return an expression which checks to see whether the compiled LHS expression is null, and if so, result in "null" instead of "false".) Any thoughts on better ways? -- J.P. Larocque From fbogdanovic at xnet.hr Sat Feb 26 10:02:30 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sat, 26 Feb 2011 11:02:30 +0100 Subject: [postmodern-devel] strange References: <33FE51846D254145B2639868077D0169@komp> Message-ID: >> (query (sql-compile `(:insert-into 'kupci :set >> ,@(list 'vrijemeunosa (:now))))) > This does not work from the repl either. You forgot a quote. It works in repl. What quote do you mean ? From fbogdanovic at xnet.hr Sat Feb 26 12:07:24 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sat, 26 Feb 2011 13:07:24 +0100 Subject: [postmodern-devel] strange References: <33FE51846D254145B2639868077D0169@komp> Message-ID: >> (query (sql-compile `(:insert-into 'kupci :set >> ,@(list 'vrijemeunosa (:now))))) I put a quote before (:now) and it works now. Thanks From fbogdanovic at xnet.hr Sun Feb 27 00:33:13 2011 From: fbogdanovic at xnet.hr (Haris) Date: Sun, 27 Feb 2011 01:33:13 +0100 Subject: [postmodern-devel] sql-compile Message-ID: <2434726638B4495FA674815EE16D076F@komp> What am I doing wrong here: (query (sql-compile `(:update 'kupci :set ,@(list 'ime (parameter "ime")) :where (:= 'id (parameter "id"))))) I get from hunchentoot log: Database error 42883: function parameter(unknown) does not exist No function matches the given name and argument types. You might need to add explicit type casts. Query: UPDATE kupci SET ime = E'a' WHERE (id = parameter(E'id')) From stassats at gmail.com Sun Feb 27 05:18:21 2011 From: stassats at gmail.com (Stas Boukarev) Date: Sun, 27 Feb 2011 08:18:21 +0300 Subject: [postmodern-devel] sql-compile In-Reply-To: <2434726638B4495FA674815EE16D076F@komp> (Haris's message of "Sun, 27 Feb 2011 01:33:13 +0100") References: <2434726638B4495FA674815EE16D076F@komp> Message-ID: <87ipw63vj6.fsf@gmail.com> "Haris" writes: > What am I doing wrong here: > > (query (sql-compile `(:update 'kupci :set > ,@(list 'ime (parameter "ime")) > :where (:= 'id (parameter "id"))))) > > I get from hunchentoot log: > > Database error 42883: function parameter(unknown) does not exist > No function matches the given name and argument types. You might need to add > explicit type casts. > Query: UPDATE kupci SET ime = E'a' WHERE (id = parameter(E'id')) Try (query (sql-compile `(:update 'kupci :set ,@(list 'ime (parameter "ime")) :where (:= 'id ,(parameter "id"))))) -- With Best Regards, Stas. From marijnh at gmail.com Sun Feb 27 21:13:19 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 27 Feb 2011 22:13:19 +0100 Subject: [postmodern-devel] :IN/:NOT-IN on an empty :SET always results in :NULL In-Reply-To: <20110226022941.GA21080@planetarium.thoughtcrime.us> References: <20110226022941.GA21080@planetarium.thoughtcrime.us> Message-ID: Hi J.P., The (NULL) thing is a bit of a cop-out on my part since I, too, couldn't figure out how to properly represent the empty set. I'd be okay with just rigging :in and :not-in to check their rhs for nil and expand to a boolean ? people who do :null in {} are just asking for it ? but if you come up with a better approach let me know. Have you investigated how do other SQL-generation engines deal with this icky corner case? Best, Marijn From slobodan.milnovic at gmail.com Mon Feb 28 13:20:23 2011 From: slobodan.milnovic at gmail.com (=?UTF-8?Q?Slobodan_Milnovi=C4=87?=) Date: Mon, 28 Feb 2011 14:20:23 +0100 Subject: [postmodern-devel] How to remove trailing spaces? Message-ID: Hi, I have some fixed length text fields, that are for now only partially filled. For these, when I select them, I get a lot of empty space after the text, and it remains so in variables. Is there a way to "prune" the empty space, for example before the DAO is instantiated, or before the result is returned in "non-DAO" selects? BTW, my reasoning in creating fixed length text fields is that postmodern should be faster than with the fields with variable length. I can still change that. From marijnh at gmail.com Mon Feb 28 14:37:51 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Mon, 28 Feb 2011 15:37:51 +0100 Subject: [postmodern-devel] How to remove trailing spaces? In-Reply-To: References: Message-ID: Hi Slobodan, Firstly, I very much doubt Postmodern will be faster for fixed-length fields. I doesn't special-case them at all, so they are sent in the exact same way as other strings. And even if they were, there is no reason they'd be faster -- the Postgres protocol null-terminates every string. But if you need fixed-width fields, you can probably add a initialize-instance :after method to your DAO class that sanitizes the strings. Best, Marijn From slobodan.milnovic at gmail.com Mon Feb 28 14:44:15 2011 From: slobodan.milnovic at gmail.com (=?UTF-8?Q?Slobodan_Milnovi=C4=87?=) Date: Mon, 28 Feb 2011 15:44:15 +0100 Subject: [postmodern-devel] How to remove trailing spaces? In-Reply-To: References: Message-ID: 2011/2/28 Marijn Haverbeke : > Hi Slobodan, > > Firstly, I very much doubt Postmodern will be faster for fixed-length > fields. I doesn't special-case them at all, so they are sent in the > exact same way as other strings. And even if they were, there is no > reason they'd be faster -- the Postgres protocol null-terminates every > string. I meant that I thougth that postgresql could be faster with fixed lenght fields, not postmodern, sorry... :-D > But if you need fixed-width fields, you can probably add a > initialize-instance :after method to your DAO class that sanitizes the > strings. Yes, I understand. And for "regular" select, I can cleanup vars by myself anyway. Thanks! From marijnh at gmail.com Mon Feb 28 14:51:25 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Mon, 28 Feb 2011 15:51:25 +0100 Subject: [postmodern-devel] How to remove trailing spaces? In-Reply-To: References: Message-ID: > I meant that I thougth that postgresql could be faster with fixed > lenght fields, not postmodern, sorry... :-D Benchmark this, before you make life hard for yourself. I seem to remember an expert telling me that fixed char columns are rarely useful anymore. From slobodan.milnovic at gmail.com Mon Feb 28 14:55:24 2011 From: slobodan.milnovic at gmail.com (=?UTF-8?Q?Slobodan_Milnovi=C4=87?=) Date: Mon, 28 Feb 2011 15:55:24 +0100 Subject: [postmodern-devel] How to remove trailing spaces? In-Reply-To: References: Message-ID: 2011/2/28 Marijn Haverbeke : >> I meant that I thougth that postgresql could be faster with fixed >> lenght fields, not postmodern, sorry... :-D > > Benchmark this, before you make life hard for yourself. I seem to > remember an expert telling me that fixed char columns are rarely > useful anymore. Well, I guess I'm not up to date with the latest DB development. :-) I can still change columns to varchar, so I think I'll do just that, which will simplify things for me. Thanks again for the advice! From fbogdanovic at xnet.hr Mon Feb 28 20:29:24 2011 From: fbogdanovic at xnet.hr (Haris) Date: Mon, 28 Feb 2011 21:29:24 +0100 Subject: [postmodern-devel] set Message-ID: I have a query like this: (query (sql (:update 'kupci :set 'ime (parameter "ime") 'prezime (parameter "prezime") 'adresa (parameter "adresa") and I want now for the next parameter to check if something is passed, I tried (:raw (if (/= (length (parameter "sobnost")) 0) (sql (:set 'sobnost (parameter "sobnost"))))) but it doesn't work. Do I have to use sql-compile maybe ?