php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34920 pg_update() fails
Submitted: 2005-10-19 21:44 UTC Modified: 2008-07-21 01:00 UTC
Votes:6
Avg. Score:4.8 ± 0.4
Reproduced:4 of 6 (66.7%)
Same Version:0 (0.0%)
Same OS:2 (50.0%)
From: n dot j dot saunders at gmail dot com Assigned:
Status: No Feedback Package: PostgreSQL related
PHP Version: 5CVS-2005-10-31 (cvs) OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-10-19 21:44 UTC] n dot j dot saunders at gmail dot com
Description:
------------
pg_update seems to fail when updating an columns of a user defined domain.

I have inherited table (advertisers) that contains, among others, the columns telephone_country (integer), telephone_area (area domain), telephone_number (number domain).

pg_update succeeds when VARCHAR fields are updated, but seems to fail without error when fields of user defined domains are updated from the array 

Reproduce code:
---------------
1. Define a Domain in an existing postgres database

e.g: area_code, domain with check

CREATE DOMAIN "public"."area_code" AS
  varchar(10) NULL;

ALTER DOMAIN "public"."area_code"
  ADD CONSTRAINT "ck_area_code" CHECK ((VALUE)::text ~ '^\\(?[0-9]\\)?[0-9]*$'::text);

2. Define a table in a postgres database that includes a column of the type you just created.

CREATE TABLE "public"."users" (
  "username" VARCHAR(20) NOT NULL, 
  "altphone_area" "public"."area_code);

3. Create a record in the table

INSERT INTO users (username, altphone_area) VALUES ('Neil',222);

3. Try and use pg_update to update this record

pg_update($db, "users", array('altphone_area'=>444), array('username'=>'Neil'));

Expected result:
----------------
The record you created is updated, setting the value of altphone_area=444

Actual result:
--------------
Nothing. No updates, no error messages.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-20 00:10 UTC] n dot j dot saunders at gmail dot com
Tried as requested - Still unable to perform update, but at least we now get an error:

Notice: pg_convert() [function.pg-convert]: Unknown or system data type 'area_code' for 'telephone_area' in c:\documents and settings\neil.saunders\workspace\tvc\www\testpg.php on line 7

Notice: pg_update() [function.pg-update]: Unknown or system data type 'area_code' for 'telephone_area' in c:\documents and settings\neil.saunders\workspace\tvc\www\testpg.php on line 10
ERROR

	$db_conn = pg_connect("host=localhost port=5432 dbname=TVC user=postgres password=xxx");

	$data = array('telephone_area'=>'701');

	pg_convert($db_conn, "advertisers", $data);

	
	$res = pg_update($db_conn, "advertisers", $data, array('id'=>'2'));

	if($res)
	{
		echo "OK";
	}
	else
	{
		echo "ERROR";
	}

Is there any way that pg_convert/pg_update can perform this? Postgres seems to handle the implied type conversion when the operation is performed via SQL? Maybe just a documented caveat required?

Thanks Guys.
 [2005-10-24 10:31 UTC] chriskl at familyhealth dot com dot au
As a pgsql developer, this is definitel a bug.  These are the possible fixes:

* Get rid of unknown and make the error message say 'this type is not supported'

* Query for the domain's base type and use that.  AFAIK, from postgresql 8.0 onwards the type of domain columns is always reported as the base type via libPQ.  Might want to check when that changed.  (Might be wrong tho.)

Check the PQftype function here: http://www.postgresql.org/docs/8.0/interactive/libpq-exec.html#LIBPQ-EXEC-SELECT-INFO
 [2008-07-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 20:01:29 2024 UTC