From tsufiev at gmail.com Tue Aug 25 10:12:30 2009 From: tsufiev at gmail.com (Timur Sufiev) Date: Tue, 25 Aug 2009 14:12:30 +0400 Subject: [postmodern-devel] [S-SQL] Multiple rows in INSERT INTO clause Message-ID: <4a93b8f8.11355e0a.4ae3.2c89@mx.google.com> Is there some way in S-SQL to generate INSERT INTO clauses with multiple rows, e.g. "INSERT INTO \"table\" (a, b) VALUES (10, 20), (30, 40)" ? Desired sexp format is `(:insert-into table :set a (10 20) b (30 40)), transformation can work like a MAPCAR: stop processing values sequences as soon as the end of the shortest one is reached. The reason to have such a feature is a performance issue: having a sequence of rows to be inserted we want to minimize the overhead related with sending queries to db; one query inserting, say, 50 rows is certainly faster than 50 queries each inserting 1 row. I would prepare the patch myself, but the syntax of s-sql.lisp is a bit too tricky for me :(. -- Timur Sufiev -- Timur Sufiev From daniel at whitehouse.id.au Tue Aug 25 12:11:18 2009 From: daniel at whitehouse.id.au (Daniel White) Date: Tue, 25 Aug 2009 22:11:18 +1000 Subject: [postmodern-devel] [S-SQL] Multiple rows in INSERT INTO clause In-Reply-To: <4a93b8f8.11355e0a.4ae3.2c89@mx.google.com> References: <4a93b8f8.11355e0a.4ae3.2c89@mx.google.com> Message-ID: <20090825221118.6a436f61@whitehouse.id.au> On Tue, 25 Aug 2009 14:12:30 +0400 Timur Sufiev wrote: > Is there some way in S-SQL to generate INSERT INTO clauses with multiple > rows, e.g. "INSERT INTO \"table\" (a, b) VALUES (10, 20), (30, 40)" ? > Desired sexp format is `(:insert-into table :set a (10 20) b (30 40)), The functionality already exists, albeit undocumented. (:insert-rows-into 'table :columns 'a 'b :values '((10 20) (30 40))) -- Daniel White From tsufiev at gmail.com Tue Aug 25 12:31:18 2009 From: tsufiev at gmail.com (Timur Sufiev) Date: Tue, 25 Aug 2009 16:31:18 +0400 Subject: [postmodern-devel] [S-SQL] Multiple rows in INSERT INTO clause In-Reply-To: <20090825221118.6a436f61@whitehouse.id.au> References: <4a93b8f8.11355e0a.4ae3.2c89@mx.google.com> <20090825221118.6a436f61@whitehouse.id.au> Message-ID: <4a93d981.01145e0a.104e.53d1@mx.google.com> >> Is there some way in S-SQL to generate INSERT INTO clauses with multiple >> rows, e.g. "INSERT INTO \"table\" (a, b) VALUES (10, 20), (30, 40)" ? >> Desired sexp format is `(:insert-into table :set a (10 20) b (30 40)), > > The functionality already exists, albeit undocumented. > > (:insert-rows-into 'table > :columns 'a 'b > :values '((10 20) (30 40))) > > -- > Daniel White Thanks, Daniel! -- Timur Sufiev From daniel at whitehouse.id.au Tue Aug 25 12:48:48 2009 From: daniel at whitehouse.id.au (Daniel White) Date: Tue, 25 Aug 2009 22:48:48 +1000 Subject: [postmodern-devel] Add :add-column action to :alter-table Message-ID: <20090825224848.666530ef@whitehouse.id.au> Patch attached adds an :add-column action to :alter-table where the column should be the same form as a column in :create-table. For example: (:alter-table table :add-column col-name :type string :default "default")) -- Daniel White -------------- next part -------------- A non-text attachment was scrubbed... Name: add-column.patch Type: text/x-patch Size: 33397 bytes Desc: not available URL: From marijnh at gmail.com Tue Aug 25 16:13:23 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Tue, 25 Aug 2009 18:13:23 +0200 Subject: [postmodern-devel] Add :add-column action to :alter-table In-Reply-To: <20090825224848.666530ef@whitehouse.id.au> References: <20090825224848.666530ef@whitehouse.id.au> Message-ID: Wow, you even documented your change. Much thanks. I've pushed the patch to the repository. From sebyte at smolny.plus.com Thu Aug 27 19:19:30 2009 From: sebyte at smolny.plus.com (Sebastian Tennant) Date: Thu, 27 Aug 2009 19:19:30 +0000 Subject: [postmodern-devel] Authentication Message-ID: Hi all, It seems it is not possible to connect to a local postgres server using the 'ident sameuser' authentication method - the two functions 'connect' and 'connect-toplevel' both require user and password arguments. I thought perhaps passing empty strings as user and password arguments might be the way to say "use the ident sameuser method" but alas, it raises the error: "Database error 28000: no PostgreSQL user name specified in startup packet" Perhaps this is a feature that is lacking, or am I missing something? Regards, Sebastian P.S. Apologies if this is a FAQ. A Gmane search of this list for 'ident sameuser' returned no results. -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap From marijnh at gmail.com Thu Aug 27 21:24:43 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Thu, 27 Aug 2009 23:24:43 +0200 Subject: [postmodern-devel] Authentication In-Reply-To: References: Message-ID: Hi Sebastian, This is not a FAQ. Postmodern currently only implements MD5-password authentication. I never really looked into the other methods that Postgres supports. If you want to implement other methods, see cl-postgres/messages.lisp and http://www.postgresql.org/docs/current/interactive/protocol-flow.html#AEN79753 . It doesn't say anything about 'sameuser' there though, so I'm not sure what the mechanism for that is. Cheers, Marijn From attila.lendvai at gmail.com Thu Aug 27 22:35:19 2009 From: attila.lendvai at gmail.com (Attila Lendvai) Date: Fri, 28 Aug 2009 00:35:19 +0200 Subject: [postmodern-devel] Authentication In-Reply-To: References: Message-ID: > . It doesn't say anything about 'sameuser' there though, so I'm not > sure what the mechanism for that is. i think you cannot use that over the tcp connection cl-postgres supports, only through some C interface which probably goes through some unix sockets on the same machine. -- attila From sabra.crolleton at gmail.com Fri Aug 28 05:21:39 2009 From: sabra.crolleton at gmail.com (Sabra Crolleton) Date: Thu, 27 Aug 2009 22:21:39 -0700 Subject: [postmodern-devel] Using get-dao to somehow pull in foreign key linked fields? Message-ID: <200908272221.39752.sabra.crolleton@gmail.com> I was just going to display the fields in a record and my first thought was to use the relevant class and then just call get-dao and iterate over the slots, something like: (item (postmodern:get-dao 'countrynotes (parse-integer id)))) However, looking at the countrynotes definition, you quickly notice that it has a foreign key: ; shortened version of the countrynotes class (defclass countrynotes () ( (id :accessor id :col-type int4 :initarg :id ) (country-id :accessor country-id :col-type int4 :initarg :country-id :foreign-key (countries id)) (name :accessor name :col-type varchar :initarg :name ) (updated-at :accessor updated-at :col-type timestamp :initarg :updated-at )) (:metaclass postmodern:dao-class) (:table-name countrynotes)(:keys id)) In displaying the countrynote, I don't really want to show the country-id, I really want to display the name of the country instead, which is another table: (defclass countries () ( (id :accessor id :col-type int4 :initarg :id ) (name :accessor name :col-type varchar :initarg :name ) (updated-at :accessor updated-at :col-type timestamp :initarg :updated-at )) (:metaclass postmodern:dao-class) (:table-name countries)(:keys id)) I can easily write out the full required sql statement, but is there a simple way of just using the dao? Sabra From marijnh at gmail.com Fri Aug 28 06:34:19 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Fri, 28 Aug 2009 08:34:19 +0200 Subject: [postmodern-devel] Using get-dao to somehow pull in foreign key linked fields? In-Reply-To: <200908272221.39752.sabra.crolleton@gmail.com> References: <200908272221.39752.sabra.crolleton@gmail.com> Message-ID: Hi Sabra, There's no elegant provision for implicitly joining things onto DAO objects, but there is a hack. See http://common-lisp.net/project/postmodern/postmodern.html#with-column-writers . Here's the only that I ever made of it (as far as I know, it's the only use ever made of it at all), with some names replaced to protect all the trade secrets that are obviously present in such a thing: (defun get-foos-by (condition) (with-column-writers ('actives 'has-active-bars 'shape 'shape) (query-dao 'foo-desc (:select 'foo.* (:as 'shape.name 'shape) (:as (:exists (:select 1 :from 'bar :where (:and (:= 'foo-id 'foo.id) 'active))) 'actives) :from 'foo :left-join 'shape :on (:= 'shape.id 'foo.shape-id) :where (:raw condition))))) Hope that helps, Marijn From sebyte at smolny.plus.com Fri Aug 28 23:16:41 2009 From: sebyte at smolny.plus.com (Sebastian Tennant) Date: Fri, 28 Aug 2009 23:16:41 +0000 Subject: [postmodern-devel] Wildacrds in string patterns Message-ID: Hi all, What's the trick for using wildcards such as '%' in string patterns in queries? I can't find anything on it in the S-SQL reference and I've tried several different things - I either get a database error or the Emacs debugger kicks in complaining about an end of file, or some such problem. Regards, Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap From info at jensteich.de Sat Aug 29 06:58:19 2009 From: info at jensteich.de (Jens Teich) Date: Sat, 29 Aug 2009 08:58:19 +0200 Subject: [postmodern-devel] Wildacrds in string patterns In-Reply-To: References: Message-ID: <4A98D18B.3030200@jensteich.de> Sebastian Tennant schrieb: > Hi all, > > What's the trick for using wildcards such as '%' in string patterns in queries? > > I can't find anything on it in the S-SQL reference and I've tried several > different things - I either get a database error or the Emacs debugger kicks in > complaining about an end of file, or some such problem. (:where (:like 'field "String%")) Jens From sebyte at smolny.plus.com Sat Aug 29 08:47:32 2009 From: sebyte at smolny.plus.com (Sebastian Tennant) Date: Sat, 29 Aug 2009 08:47:32 +0000 Subject: [postmodern-devel] Wildacrds in string patterns References: <4A98D18B.3030200@jensteich.de> Message-ID: Quoth Jens Teich : > Sebastian Tennant schrieb: >> What's the trick for using wildcards such as '%' in string patterns in >> queries? > (:where (:like 'field "String%")) Thanks Jens. I tried the above. It turns out the problem I am having has to do with SLIME and non-ASCII characters in the results. Regards, Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap From khaelin at gmail.com Sun Aug 30 13:28:25 2009 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 30 Aug 2009 15:28:25 +0200 Subject: [postmodern-devel] Large objects support Message-ID: <20090830132824.GB1501@valhala.gaia.loc> Hi, Is there a large object? support in development, or do you intend to add one in the future? 1. http://www.postgresql.org/docs/8.4/static/largeobjects.html Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From marijnh at gmail.com Sun Aug 30 13:49:18 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 30 Aug 2009 15:49:18 +0200 Subject: [postmodern-devel] Large objects support In-Reply-To: <20090830132824.GB1501@valhala.gaia.loc> References: <20090830132824.GB1501@valhala.gaia.loc> Message-ID: Hi Nicolas, Postmodern does not currently support this. There isn't a single mention of large objects in documentation of the Postgres Frontend/Backend protocol, so I'm not even sure how they are implemented by the C client lib. They seem to be a hack on top of tables containing binary arrays (http://www.postgresql.org/docs/8.4/static/lo-implementation.html). If you have a need for this, you can have a shot at implementing it. Myself, I'm in 'maintenance' mode when it comes to Postgres -- I'm happy to fix bugs and answer questions, but I don't have time to add substantial new features. Best, Marijn From khaelin at gmail.com Sun Aug 30 15:22:22 2009 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 30 Aug 2009 17:22:22 +0200 Subject: [postmodern-devel] Large objects support In-Reply-To: References: <20090830132824.GB1501@valhala.gaia.loc> Message-ID: <20090830152222.GC1501@valhala.gaia.loc> On 09-08-30 15:49, Marijn Haverbeke wrote: > Hi Nicolas, > > Postmodern does not currently support this. There isn't a single > mention of large objects in documentation of the Postgres > Frontend/Backend protocol, so I'm not even sure how they are > implemented by the C client lib. They seem to be a hack on top of > tables containing binary arrays > (http://www.postgresql.org/docs/8.4/static/lo-implementation.html). > > If you have a need for this, you can have a shot at implementing it. > Myself, I'm in 'maintenance' mode when it comes to Postgres -- I'm > happy to fix bugs and answer questions, but I don't have time to add > substantial new features. No problem :) If I need them, I'll try to add the support to postmodern (excellent library by the way). Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From khaelin at gmail.com Sun Aug 30 17:26:36 2009 From: khaelin at gmail.com (khaelin at gmail.com) Date: Sun, 30 Aug 2009 10:26:36 -0700 (PDT) Subject: [postmodern-devel] darcs patch: add support for the currval() and lastval() functions Message-ID: <4a9ab64c.0508d00a.392c.ffffa3d6@mx.google.com> Sun Aug 30 19:25:12 CEST 2009 khaelin at gmail.com * add support for the currval() and lastval() functions -------------- next part -------------- A non-text attachment was scrubbed... Name: add-support-for-the-currval__-and-lastval__-functions.dpatch Type: text/x-darcs-patch Size: 29436 bytes Desc: A darcs patch for your repository! URL: From marijnh at gmail.com Sun Aug 30 17:39:19 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 30 Aug 2009 19:39:19 +0200 Subject: [postmodern-devel] darcs patch: add support for the currval() and lastval() functions In-Reply-To: <4a9ab64c.0508d00a.392c.ffffa3d6@mx.google.com> References: <4a9ab64c.0508d00a.392c.ffffa3d6@mx.google.com> Message-ID: Hi, You'll notice that, even without your patch, something like (:currval "foo") expands to currval('foo') -- it's just a function, and when no special syntax is defined for a keyword, S-SQL will expand it as a function. Given this, does the patch still serve a purpose? Best, Marijn From khaelin at gmail.com Sun Aug 30 17:55:28 2009 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Sun, 30 Aug 2009 19:55:28 +0200 Subject: [postmodern-devel] darcs patch: add support for the currval() and lastval() functions In-Reply-To: References: <4a9ab64c.0508d00a.392c.ffffa3d6@mx.google.com> Message-ID: <20090830175528.GD1501@valhala.gaia.loc> On 09-08-30 19:39, Marijn Haverbeke wrote: > Hi, > > You'll notice that, even without your patch, something like (:currval > "foo") expands to currval('foo') -- it's just a function, and when no > special syntax is defined for a keyword, S-SQL will expand it as a > function. Given this, does the patch still serve a purpose? I don't know if I do it correctly, but without my patch: * (s-sql:sql-compile '(:select (:currval players_id_seq))) "(SELECT currval(players_id_seq))" With my patch: * (s-sql:sql-compile '(:select (:currval players_id_seq))) "(SELECT currval(E'players_id_seq'))" It seems that the default function expansion doesn't escape object names. Since I'm here, note that there's also a setval() function, a bit more complex since it takes arguments (two or three), but I didn't figure how to add it (sorry, lisp beginner here). I'll try to add it... one day. Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From marijnh at gmail.com Sun Aug 30 18:03:34 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 30 Aug 2009 20:03:34 +0200 Subject: [postmodern-devel] darcs patch: add support for the currval() and lastval() functions In-Reply-To: <20090830175528.GD1501@valhala.gaia.loc> References: <4a9ab64c.0508d00a.392c.ffffa3d6@mx.google.com> <20090830175528.GD1501@valhala.gaia.loc> Message-ID: > ? ?* (s-sql:sql-compile '(:select (:currval players_id_seq))) > ? ?"(SELECT currval(players_id_seq))" > ? ?* (s-sql:sql-compile '(:select (:currval players_id_seq))) > ? ?"(SELECT currval(E'players_id_seq'))" > It seems that the default function expansion doesn't escape object names. The Postgresql currval/nextval functions take strings. Passing a symbol, in S-SQL means passing an identifier. If you are generating s-sql expressions, have a symbol where you need a string, you can just call to-sql-name on it. Doing it that way should also make calling setval easier. Best, Marijn From khaelin at gmail.com Mon Aug 31 08:10:52 2009 From: khaelin at gmail.com (Nicolas Martyanoff) Date: Mon, 31 Aug 2009 10:10:52 +0200 Subject: [postmodern-devel] darcs patch: add support for the currval() and lastval() functions In-Reply-To: References: <4a9ab64c.0508d00a.392c.ffffa3d6@mx.google.com> <20090830175528.GD1501@valhala.gaia.loc> Message-ID: <20090831081052.GA1724@valhala.gaia.loc> On 09-08-30 20:03, Marijn Haverbeke wrote: > > ? ?* (s-sql:sql-compile '(:select (:currval players_id_seq))) > > ? ?"(SELECT currval(players_id_seq))" > > > ? ?* (s-sql:sql-compile '(:select (:currval players_id_seq))) > > ? ?"(SELECT currval(E'players_id_seq'))" > > > It seems that the default function expansion doesn't escape object names. > > The Postgresql currval/nextval functions take strings. Passing a > symbol, in S-SQL means passing an identifier. If you are generating > s-sql expressions, have a symbol where you need a string, you can just > call to-sql-name on it. Doing it that way should also make calling > setval easier. You seem to be right :) Perhaps should nextval() be removed then, for consistency purpose. Regards, -- Nicolas Martyanoff http://codemore.org khaelin at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From marijnh at gmail.com Mon Aug 31 08:17:58 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Mon, 31 Aug 2009 10:17:58 +0200 Subject: [postmodern-devel] darcs patch: add support for the currval() and lastval() functions In-Reply-To: <20090831081052.GA1724@valhala.gaia.loc> References: <4a9ab64c.0508d00a.392c.ffffa3d6@mx.google.com> <20090830175528.GD1501@valhala.gaia.loc> <20090831081052.GA1724@valhala.gaia.loc> Message-ID: Ah, there's already a :nextval. Now I see your point. I guess someone (possibly me) thought that was a good idea at the time. My issue is, though, that there's so much built-in functions in Postgres that providing a convenience wrapper for all of them would make the library huge. I'd remove nextval, but that might break someone's code. The consistency isn't too bad, since the definition of :nextval also allows strings as input, people passing these functions strings (the logical thing to do) will never even notice this. Best, Marijn