From lisp.linux at gmail.com Sun Sep 4 07:12:22 2011 From: lisp.linux at gmail.com (Antony) Date: Sun, 04 Sep 2011 00:12:22 -0700 Subject: [postmodern-devel] setting default value for serial column in prepared insert statement execution Message-ID: <4E6324D6.1040500@gmail.com> Hi I was trying to find how to use the 'serial' (auto increment) type through cl-postgres prepared insert statement execution. According to http://www.postgresql.org/docs/9.0/interactive/datatype-numeric.html#DATATYPE-SERIAL I basically have two choices for defaulting a serial column value 1. pass the DEFAULT keyword for the column value 2. do not include the serial column in the insert statement The way my code is setup, it's more convoluted to do #2 I wanted to check if it's possible to do #1. That would really make a big difference to me. -Antony From lispnik at gmail.com Sun Sep 4 07:25:13 2011 From: lispnik at gmail.com (Ivan Boldyrev) Date: Sun, 4 Sep 2011 14:25:13 +0700 Subject: [postmodern-devel] setting default value for serial column in prepared insert statement execution In-Reply-To: <4E6324D6.1040500@gmail.com> References: <4E6324D6.1040500@gmail.com> Message-ID: On Sun, Sep 4, 2011 at 2:12 PM, Antony wrote: > Hi > > I was trying to find how to use the 'serial' (auto increment) type through > cl-postgres prepared insert statement execution. > > According to > http://www.postgresql.org/docs/9.0/interactive/datatype-numeric.html#DATATYPE-SERIAL > I basically have two choices for defaulting a serial column value > 1. pass the DEFAULT keyword for the column value CL-USER> (s-sql:sql (:insert-into 'table :set 'id (:raw "default") 'name "Antony")) "INSERT INTO \"table\" (id, name) VALUES (default, E'Antony')" -- Ivan Boldyrev From lisp.linux at gmail.com Sun Sep 4 10:23:59 2011 From: lisp.linux at gmail.com (Antony) Date: Sun, 04 Sep 2011 03:23:59 -0700 Subject: [postmodern-devel] setting default value for serial column in prepared insert statement execution In-Reply-To: References: <4E6324D6.1040500@gmail.com> Message-ID: <4E6351BF.3040807@gmail.com> On 9/4/2011 12:25 AM, Ivan Boldyrev wrote: > On Sun, Sep 4, 2011 at 2:12 PM, Antony wrote: >> Hi >> >> I was trying to find how to use the 'serial' (auto increment) type through >> cl-postgres prepared insert statement execution. >> >> According to >> http://www.postgresql.org/docs/9.0/interactive/datatype-numeric.html#DATATYPE-SERIAL >> I basically have two choices for defaulting a serial column value >> 1. pass the DEFAULT keyword for the column value > CL-USER> (s-sql:sql (:insert-into 'table :set 'id (:raw "default") > 'name "Antony")) > "INSERT INTO \"table\" (id, name) VALUES (default, E'Antony')" I am trying to do this using __prepared__ statements. I don't think the above helps for that. To be explicit I am talking about the calls to the method cl-postgres:exec-prepared in file postmodern/cl-postgres/public.lisp If I pass :null for the serial col parameter I get Database error 23502: null value in column "seq_id" violates not-null constraint [Condition of type CL-POSTGRES-ERROR:NOT-NULL-VIOLATION] (this is a pity since in most databases a null is considered the ticket to insert the auto increment value, but I understand why in postgres they have chosen this to be explicitly indicated by the use of reserved sql keyword 'default') If I pass the string "default" I get Database error 22P02: invalid input syntax for integer: "default" [Condition of type CL-POSTGRES-ERROR:DATA-EXCEPTION] If I pass the keyword :default I get Value :DEFAULT can not be converted to an SQL literal. [Condition of type SIMPLE-ERROR] in CL-POSTGRES:TO-SQL-STRING I wasn't expecting any of the above to work, just saying this is what I have tried. Basically the parameter serialization low level code needs to learn how to deal with ___DEFAULT___ keyword for postgres sql syntax and then provide a means of specifying that (may be through use of CL keyword :default). I am not sure where/how to do that. -Antony From lisp.linux at gmail.com Sun Sep 4 13:19:51 2011 From: lisp.linux at gmail.com (Antony) Date: Sun, 04 Sep 2011 06:19:51 -0700 Subject: [postmodern-devel] setting default value for serial column in prepared insert statement execution In-Reply-To: References: <4E6324D6.1040500@gmail.com> Message-ID: <4E637AF7.7040107@gmail.com> On Sun, Sep 4, 2011 at 2:12 PM, Antony wrote: >> Hi >> >> I was trying to find how to use the 'serial' (auto increment) type through >> cl-postgres prepared insert statement execution. >> I am working around by having separate insert statements one with and one without the auto increment column. Good enough for now :) -Antony From marijnh at gmail.com Sun Sep 4 19:27:32 2011 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 4 Sep 2011 21:27:32 +0200 Subject: [postmodern-devel] setting default value for serial column in prepared insert statement execution In-Reply-To: <4E637AF7.7040107@gmail.com> References: <4E6324D6.1040500@gmail.com> <4E637AF7.7040107@gmail.com> Message-ID: > I am working around by having separate insert statements one with and one without the auto increment column. I think this is your best bet, yes. I don't think postgres supports what you wanted to do. If you find a way (in raw sql) let me know. -------------- next part -------------- An HTML attachment was scrubbed... URL: From haragx at gmail.com Mon Sep 5 08:02:21 2011 From: haragx at gmail.com (Phil Marneweck) Date: Mon, 05 Sep 2011 10:02:21 +0200 Subject: [postmodern-devel] setting default value for serial column in prepared insert statement execution In-Reply-To: <4E6351BF.3040807@gmail.com> References: <4E6324D6.1040500@gmail.com> <4E6351BF.3040807@gmail.com> Message-ID: <1315209741.4661.23.camel@storm> Under certain circumstances (cant remember when it does not work, play around with col-type serial vs integer ) something like this in the class definition will work (id :initarg :id :initform nil :col-type serial :col-default (:nextval "reporting-period-id-seq")) or when you initialize a new dao-class use something like this :id (query (:select (:nextval "reporting-period-id-seq")) :single) -------------- next part -------------- An HTML attachment was scrubbed... URL: