473,902 Members | 6,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sql insert function

The documentation doesn't have any examples of using an sql language
function to do an insert, andI am at loss as to I am doing wrong here.
The error I get trying to create the function is: ERROR: syntax error at
or near "$1" at character 148

CREATE FUNCTION taxship(varchar ,integer,varcha r,float,float) returns integer
AS '
insert into taxship(s_oid,o rder_id,mer_id, tax,shipping) values
('$1',$2,'$3',$ 4,$5);
SELECT 1;
' LANGUAGE SQL;
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05
14 13036
On Tuesday 13 January 2004 00:35, Doug McNaught wrote:
"Chris Ochs" <ch***@paymento nline.com> writes:

CREATE FUNCTION taxship(varchar ,integer,varcha r,float,float) returns
integer AS '
insert into taxship(s_oid,o rder_id,mer_id, tax,shipping) values
('$1',$2,'$3',$ 4,$5);
SELECT 1;
' LANGUAGE SQL;


When you want to use single quotes inside a quoted string (which is
what a function body is) you need to escape them.


Can I point out that you don't need any quotes here - these are variables not
literals. Just do:

INSERT INTO (...) VALUES ($1,$2,$3...)

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 22 '05 #11
Please ignore my last post - threading got messed up and my point was already
noted.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #12

On Mon, 12 Jan 2004, Chris Ochs wrote:
LOG: statement: begin
LOG: statement: insert into...
LOG: statement:
insert into taxship(s_oid,o rder_id,mer_id, tax,shipping) values
('0000-10000000',10000 000,'0000',1,1) ;
END


Where is that END coming from? Did you accidentally put it in your
function?
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 22 '05 #13
Yes it was in my function. I thought the docs said that BEGIN and END had
no effect on transactions though? Plus wouldn't there have to be a
transaction active since I was not using autocommit and the inserts did in
fact commit?

I suspect it is the end statement doing this though, I'll take it out and
see what happens.

----- Original Message -----
From: "Stephan Szabo" <ss****@megazon e.bigpanda.com>
To: "Chris Ochs" <ch***@paymento nline.com>
Cc: <pg***********@ postgresql.org>
Sent: Tuesday, January 13, 2004 8:36 AM
Subject: Re: [GENERAL] sql insert function


On Mon, 12 Jan 2004, Chris Ochs wrote:
LOG: statement: begin
LOG: statement: insert into...
LOG: statement:
insert into taxship(s_oid,o rder_id,mer_id, tax,shipping) values
('0000-10000000',10000 000,'0000',1,1) ;
END


Where is that END coming from? Did you accidentally put it in your
function?

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #14
On Tuesday 13 January 2004 17:46, Chris Ochs wrote:
Yes it was in my function. I thought the docs said that BEGIN and END had
no effect on transactions though? Plus wouldn't there have to be a
transaction active since I was not using autocommit and the inserts did in
fact commit?

I suspect it is the end statement doing this though, I'll take it out and
see what happens.


I think you're right - I looked back at your earlier posts and you are mixing
up plpgsql and sql function syntax (easy enough to do).

BEGIN...END bracket the body of a plpgsql function, but control a transaction
in the SQL function. The BEGIN would have been ignored, the END would have
committed the current transaction.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 22 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13231
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses the screen and then using an UPDATE when he visits later. Model | Original Price | Reduced Price...
0
1107
by: le_mo_mo | last post by:
Hi, I am trying to insert some data using FormView which works fine but I do not know how to include hiddenfield and bind them in the construct so I can insert information like username, date, etc.. Any body has any suggestions? Thanks, mo
4
5035
by: neilcancer | last post by:
i wrote a function to insert an elem into a list, but it was wrong,wrong,wrong! and i have no idea about why it was wrong. If anyone know, leave your advice, thank you. #include<stdio.h> #include<stdlib.h> typedef struct lnode { int elem;
2
1221
by: riley.derrick | last post by:
Hello All I have been looking over the various forums and threads trying to learn as much as I can. Here is my issue. I am trying to do the following: Write a function that involves the following: Calculates the following. 2 user inputted dates. (Ex. Jan 1 2000 -- Jan 1 2004). Figures out the number of months between the 2 dates. That number is then multiplied by a user input price that outputs some number. Problem is I am new to SQL...
6
6437
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. Here is a description of the three functions: Insert: Accepts as input the array and the element you want to insert into the array. The function should insert the element at the end of the array and should call the function Sort to sort the...
6
20011
by: askmatlab | last post by:
Hello all: I would like to insert a number into a linked list in ascending order. Is the following function correct? void insert(Node **node, int v) { Node *tmp = (Node *)malloc(sizeof(Node)); while(*node && (*node)->value < v) node = &(*node)->next;
6
1684
by: choonmui | last post by:
hello.. i am new here and need some help in vb.net!! i need to do an insert function.. for example: there are some checkboxes. if the box is checked and a user clicks the button 'select', the item that had been checked will show up in other page. the problem is i don know how to retrive data from database once user click the button 'select' thats all, thank you!!
1
5023
by: Amit Bhatia | last post by:
Hi, I have defined something like the following in tree.h file: //everything else including using namespace __gnu_cxx; typedef hash_map<pair<int,int>, Qd_Node, Qd_Node_HasherLoc_Tree; vector<Loc_Treetree; //more stuff; Now when I try do something like this in tree.C file: #include "tree.h"
0
1177
by: subramanian100in | last post by:
Suppose I have a vector<Tor deque<Tfor some type T. Suppose vector<T>::iterator iter is an iterator. Then consider the operation vector<T>::iterator nit = container.insert(iter, T()); After the insertion, iter will be invalidated for both vector<T>, deque<T>. However for list<T>, the same operation under g++ 3.4.3, does not seem
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9675
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4307
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.