Re: [pgsql-tr-genel] Javadan Postgresql insert function içindeki smallint alana değer gönderemiyorum

From: Samed YILDIRIM <samed(at)reddoc(dot)net>
To: AZiZ CiZMECi <azizcizmeci(at)gmail(dot)com>, "pgsql-tr-genel(at)postgresql(dot)org" <pgsql-tr-genel(at)postgresql(dot)org>
Subject: Re: [pgsql-tr-genel] Javadan Postgresql insert function içindeki smallint alana değer gönderemiyorum
Date: 2016-12-13 18:31:20
Message-ID: 610551481653880@web16o.yandex.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-tr-genel

<div>Merhabalar Aziz Bey,</div><div> </div><div>Siz select sp_test('ali verli',14); şeklinde sorgu gönderdiğinizde aslında sp_test(character varying, integer) şeklinde bir fonksiyon arıyor. Yani siz 14 yazdığınızda bu smallint değil integer olduğu için postgres buna uygun bir fonksiyon arıyor, olmadığı için de bulamadım diye hata dönüyor. Bunu birkaç şekilde çözebilirsiniz.</div><div> </div><div>1. Fonksiyonu çağırırken gönderdiğiniz değeri smallint'e cast ederek gönderirsiniz.</div><div>select sp_test('ali veli',14::smallint);</div><div> </div><div>2. Fonksiyonu int ile oluşturursunuz ama smallint'e cast ederek insert yaparsınız.</div><div><div>CREATE OR REPLACE FUNCTION public.sp_test(_adsoyad character varying,_yas int)</div><div>  RETURNS integer AS</div><div>$$</div><div>insert into test_tbl (adsoyad,yas) values ($1,$2::smallint)</div><div>RETURNING id;</div><div>$$</div><div>  LANGUAGE sql VOLATILE</div></div><div> </div><div>3. Bir ara fonksiyon yazarsınız, bu fonksiyon int kabul eder ve sizin ana fonksiyonunuzu çağırır.</div><div><div>CREATE OR REPLACE FUNCTION public.sp_test(_adsoyad character varying,_yas int)</div><div>  RETURNS integer AS</div><div>$$</div><div>select sp_test($1,$2::smallint);</div><div>$$</div><div>  LANGUAGE sql VOLATILE</div><div> </div><div>4. Tablonuzdaki bu alanı integer'a dönüştürür, fonksiyonu da integer ile oluşturursunuz.</div><div> </div><div>İyi çalışmalar.</div></div><div><br /></div><div><br /></div><div>İyi çalışmalar.</div><div>Samed YILDIRIM</div><div><br /></div><div><br /></div><div><br /></div><div>13.12.2016, 19:55, "AZiZ CiZMECi" &lt;azizcizmeci(at)gmail(dot)com&gt;:</div><blockquote type="cite"><div dir="ltr">Merhaba.<div><br /></div><div>Pgadmin kullanarak aşağıdaki gibi bir function tanımladım;</div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">CREATE OR REPLACE FUNCTION public.sp_test(_adsoyad character varying,_yas smallint)</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">  RETURNS integer AS</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">$$</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">insert into test_tbl (adsoyad,yas) values ($1,$2)</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">RETURNING id;</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">$$</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">  LANGUAGE sql VOLATILE</blockquote></blockquote><div><br /></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"> </blockquote><div><br /></div><div>Bu functionu, pgadmin üzerinde select sp_test('ali veli',14) şeklinde çalıştırdığımda  </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">"No function matches the given name and argument types. You might need to add explicit type casts."<br /></blockquote><div>hatası aldım. Hatayı araştırdıktan sonra, her ne kadar mantıklı gelmese de, select sp_test('ali veli','14')  şeklinde integer değerin de  string tipinde gönderilmesi gerektiğini gördüm ve sorun çözüldü. (Sorunun çözümünün bu olup olmadığına emin değilim)</div><div><br /></div><div>Fakat bu functionu java tarafında aşağıdaki gibi </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">CallableStatement sp_test = vt.prepareCall("{call sp_test(?,?)}");</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">                sp_test.setString(1,"ali veli");</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">                sp_testads6.setInt(2,14);</blockquote></blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"> </blockquote><div>kullandığımda yine </div><div>"<span style="background-color:rgb(249,249,249);color:rgb(153,0,0);font-family:&quot;trebuchet ms&quot;,verdana,arial,sans-serif;font-size:medium;font-weight:bold;">ERROR: function sp_testads6(character varying, integer) does not exist İpucu: No function matches the given name and argument types. You might need to add explicit type casts."</span></div><div><br /></div><div>hatası aldım. int değeri Stringe çevirip göndermeye çalıştım yine olmadı.</div><div><br /></div><div>Bu hata konusunda  yardımcı olursanız memnun olurum. Bir de, postgresql function tanımlamaları konusunda püf noktalarını kısaca anlatabilirmisiniz?</div><div>İyi çalışmalar.</div></div>
</blockquote>

Attachment Content-Type Size
unknown_filename text/html 5.2 KB

In response to

Responses

Browse pgsql-tr-genel by date

  From Date Subject
Next Message AZiZ CiZMECi 2016-12-14 17:38:03 Re: [pgsql-tr-genel] Javadan Postgresql insert function içindeki smallint alana değer gönderemiyorum
Previous Message AZiZ CiZMECi 2016-12-13 17:54:30 Javadan Postgresql insert function içindeki smallint alana değer gönderemiyorum