Reputation: 3497
I have a postgresql function
CREATE OR REPLACE FUNCTION fixMissingFiles() RETURNS VOID AS $$
DECLARE
deletedContactId integer;
BEGIN
SELECT INTO deletedContactId contact_id FROM myContacts WHERE id=206351;
-- print the value of deletedContactId variable to the console
END;
$$ LANGUAGE plpgsql;
How can I print the value of the deletedContactId to the console?
Upvotes: 198
Views: 360929
Reputation: 78443
You can raise a notice in Postgres
as follows:
RAISE NOTICE 'Value: %', deletedContactId;
Read here for more details.
Upvotes: 421
Reputation: 31
Also, the SELECT INTO you're using looks like PostgreSQL for copying rows into a table. See, for example, the SELECT INTO doc page which state: "SELECT INTO -- define a new table from the results of a query"
In pgplSQL I'm used to seeing it in this order: SELECT INTO ... so your first line should probably be:
SELECT contact_id INTO deletedContactId FROM myContacts WHERE id=206351;
As described in Executing a Query with a Single-Row Result.
Upvotes: 3