473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Row values

Hello,
I am writing my first trigger in C for PostgreSQL. It compiles Ok, and
added it to the database using CREATE TRIGGER. But when I try to fire
it, psql simply says 'The connection was lost". What I don't know is how
to get the row values (not the name fields) from tg_trigger.
The code is:

....

TriggerData *trigdata = (TriggerData *) fcinfo->context;

....

strcpy(query, "INSERT INTO visita_log VALUES ('");
strcat(query, trigdata->tg_trigger->tgargs[0]);
strcat(query, "','");
strcat(query, trigdata->tg_trigger->tgargs[1]);
strcat(query, "','");
strcat(query, trigdata->tg_trigger->tgargs[2]);
strcat(query, "','");
strcat(query, trigdata->tg_trigger->tgargs[3]);
strcat(query, "',");
strcat(query, trigdata->tg_trigger->tgargs[4]);
strcat(query, ",'");
strcat(query, trigdata->tg_trigger->tgargs[5]);
strcat(query, "');");
SPI_exec(query, 0);

....

I don't know if tgargs[] return the row values or the field names.

Thanks.
Juan
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
4 1476
On Fri, Jul 02, 2004 at 07:36:50AM -0300, Juan Jose Costello Levien wrote:
I am writing my first trigger in C for PostgreSQL. It compiles Ok, and
added it to the database using CREATE TRIGGER. But when I try to fire
it, psql simply says 'The connection was lost".


Most likely the server process crashed. See the server log and the core
file for details to debug your function.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
La web junta la gente porque no importa que clase de mutante sexual seas,
tienes millones de posibles parejas. Pon "buscar gente que tengan sexo con
ciervos incendiánse", y el computador dirá "especifique el tipo de ciervo"
(Jason Alexander)
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #2
Alvaro,

Sorry, but, where are the log file and core you mentioned? I tried
/var/log/postgresql but is in 0 file size.

TIA

On Fri, Jul 02, 2004 at 07:36:50AM -0300, Juan Jose Costello Levien wrote:
I am writing my first trigger in C for PostgreSQL. It compiles Ok, and
added it to the database using CREATE TRIGGER. But when I try to fire
it, psql simply says 'The connection was lost".


Most likely the server process crashed. See the server log and the core
file for details to debug your function.

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

Nov 23 '05 #3
Juan Jose Costello Levien <jc*******@datafull.com> writes:
I don't know if tgargs[] return the row values or the field names.


Neither --- it's the (fixed) arguments you used in the CREATE TRIGGER
command. You'll need to do something involving extracting field values
from the tuple that is passed to the trigger, instead.

I'd suggest looking in the contrib/ modules for examples of triggers
written in C.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #4
On Fri, Jul 02, 2004 at 09:56:43AM -0300, Juan Jose Costello Levien wrote:
Alvaro,

Sorry, but, where are the log file and core you mentioned? I tried
/var/log/postgresql but is in 0 file size.


Your server may be misconfigured (most linux distros are). Make sure
your init script does not redirect postmaster's (or pg_ctl's)
stdout/stderr to /dev/null. Also make sure that if you are using
syslog, the syslog server is configured to save the messages somewhere
useful, by checking the facility Postgres uses (configurable) and where
does syslog save messages from this facility.

The core file, on the other hand, should be somewhere in
/var/lib/pgsql/data/base (if you haven't changed PGDATA), _unless_ the
server runs under a core 0-byte limit (under bash, ulimit -c will tell
you).

Hope this helps,

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Java is clearly an example of a money oriented programming" (A. Stepanov)
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5

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

Similar topics

5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
1
by: Sue Adams | last post by:
I have a form on an asp page and am trying to write the code to place the values of all checkboxes that have been selected, into an array. The checkbox values will be used in a dynamic sql statement...
5
by: James Baker | last post by:
I have a form that has a dropdown list that will cause a post to the same page when it's changed. The problem I'm running into is that all of the controls reset to their default values (obviously...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
4
by: Steve Hall | last post by:
Folks, My secnario involves two tables - ObservationRegister, and Person. ObservationRegister contains most of the "useful" fields, including the UserID of the person that raised the record, and...
6
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like...
2
by: Hennie | last post by:
I apologise if this is a stupid question, but I would appreciated any help on this subject. I want to create a view (VIEW_1 in example below) where I take numeric values from a field in one...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
13
by: Gregor =?UTF-8?B?S292YcSN?= | last post by:
Hi! With VALUES you can do something like: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER) which will give you: LETTER NUMBER ------ ------ A 1 B 2...
8
by: gigonomics | last post by:
Hi all, I hope someone can help me out. I need to return the best available seats subject to the constraint that the seats are side by side (or return X consecutive records from a table column...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.