ERROR: syntax error at or near "SET" - postgresql

UPDATE m_price
SET pricelist=15.159, pricestd=14.3184
WHERE m_product_id = 1000332
ERROR: syntax error at or near "SET" i am getting this error in POSTGRESQL.
table structure
CREATE TABLE m_price (
m_pricelist_version_id numeric(10,0) NOT NULL,
m_product_id numeric(10,0) NOT NULL,
ad_client_id numeric(10,0) NOT NULL,
ad_org_id numeric(10,0) NOT NULL,
isactive character(1) DEFAULT 'Y'::bpchar NOT NULL,
created timestamp without time zone DEFAULT now() NOT NULL,
createdby numeric(10,0) NOT NULL,
updated timestamp without time zone DEFAULT now() NOT NULL,
updatedby numeric(10,0) NOT NULL,
pricelist numeric DEFAULT 0 NOT NULL,
pricestd numeric DEFAULT 0 NOT NULL,
pricelimit numeric DEFAULT 0 NOT NULL,
CONSTRAINT m_productprice_isactive_check CHECK ((isactive = ANY (ARRAY['Y'::bpchar, 'N'::bpchar])))
);

Try
UPDATE m_price
SET (pricelist,pricestd)=(15.159,14.3184)
WHERE m_product_id = 1000332

Related

Meaning of the character # in psql

I found the next psql command:
CREATE TABLE #cdmDatabaseSchema.PERSON (
person_id integer NOT NULL,
gender_concept_id integer NOT NULL,
year_of_birth integer NOT NULL,
month_of_birth integer NULL,
day_of_birth integer NULL,
birth_datetime TIMESTAMP NULL,
race_concept_id integer NOT NULL,
ethnicity_concept_id integer NOT NULL,
location_id integer NULL,
provider_id integer NULL,
care_site_id integer NULL,
person_source_value varchar(50) NULL,
gender_source_value varchar(50) NULL,
gender_source_concept_id integer NULL,
race_source_value varchar(50) NULL,
race_source_concept_id integer NULL,
ethnicity_source_value varchar(50) NULL,
ethnicity_source_concept_id integer NULL );
What is the symbol # located just after CREATE TABLE for? Is there any special meaning/advantage to its use?

Installation failed to create the core tables | Installing Revive Adserver 5.2.0

I am installing revive ad server on Ubuntu 20.4 which is having MySQL Version 8.0.23. The Log I got from file /var/debug.log is
[Last executed query: CREATE TABLE `bv_banners` (`bannerid` MEDIUMINT(9) AUTO_INCREMENT NOT NULL, `campaignid` MEDIUMINT(9) DEFAULT 0 NOT NULL, `contenttype` ENUM('gif','jpeg','png','html','swf','dcr','rpm','mov','txt') DEFAULT 'gif' NOT NULL, `pluginversion` MEDIUMINT(9) DEFAULT 0 NOT NULL, `storagetype` ENUM('sql','web','url','html','network','txt') DEFAULT 'sql' NOT NULL, `filename` VARCHAR(255) DEFAULT '' NOT NULL, `imageurl` VARCHAR(255) DEFAULT '' NOT NULL, `htmltemplate` MEDIUMTEXT NOT NULL, `htmlcache` MEDIUMTEXT NOT NULL, `width` SMALLINT(6) DEFAULT 0 NOT NULL, `height` SMALLINT(6) DEFAULT 0 NOT NULL, `weight` TINYINT(4) DEFAULT 1 NOT NULL, `seq` TINYINT(4) DEFAULT 0 NOT NULL, `target` VARCHAR(16) DEFAULT '' NOT NULL, `url` TEXT NOT NULL, `alt` VARCHAR(255) DEFAULT '' NOT NULL, `statustext` VARCHAR(255) DEFAULT '' NOT NULL, `bannertext` TEXT NOT NULL, `description` VARCHAR(255) DEFAULT '' NOT NULL, `adserver` VARCHAR(255) DEFAULT '' NOT NULL, `block` INT(11) DEFAULT 0 NOT NULL, `capping` INT(11) DEFAULT 0 NOT NULL, `session_capping` INT(11) DEFAULT 0 NOT NULL, `compiledlimitation` TEXT NOT NULL, `acl_plugins` TEXT DEFAULT NULL, `append` TEXT NOT NULL, `bannertype` TINYINT(4) DEFAULT 0 NOT NULL, `alt_filename` VARCHAR(255) DEFAULT '' NOT NULL, `alt_imageurl` VARCHAR(255) DEFAULT '' NOT NULL, `alt_contenttype` ENUM('gif','jpeg','png') DEFAULT 'gif' NOT NULL, `comments` TEXT DEFAULT NULL, `updated` DATETIME NOT NULL, `acls_updated` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL, `keyword` VARCHAR(255) DEFAULT '' NOT NULL, `transparent` TINYINT(1) DEFAULT 0 NOT NULL, `parameters` TEXT DEFAULT NULL, `status` INT(11) DEFAULT 0 NOT NULL, `ext_bannertype` VARCHAR(255) DEFAULT NULL, `prepend` TEXT NOT NULL, `iframe_friendly` TINYINT(1) DEFAULT 1 NOT NULL, PRIMARY KEY (bannerid)) ENGINE = INNODB]
[Native message: Invalid default value for 'acls_updated']
I got to know adserver is not officially supporting mysql version 8. But some people are able to run fine. I want to know how.
Here is the refrence I got
https://github.com/revive-adserver/revive-adserver/issues/1048
I want to run this.
Thanks in advance.
set sql_mode='40'' to sql_mode=''
in 5 files;
lib/OA/DB.php
lib/OA/DaL/Delivery/mysql.php
lib/OA/Dal/Delivery/mysqli.php
lib/OA/Upgrade/DB_Upgrade.php
lib/OA/Upgrade/Upgrade.php
and use table type INNODB
This trick works for me. I am calling this as a trick because it is not officially supported.
I got solution from github.
Here is the refrence
https://github.com/revive-adserver/revive-adserver/issues/1048

Why can't I insert a null value into a notNull column which has a default value? [duplicate]

I just migrated my app from mysql to postgres but when I try to insert a record in a specific table I get violates not-null constraint error:
ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 1, 1, null, null, null, 2016-03-09 09:24:12.841891, 2012-12-31 23:00:00, 2012-12-31 23:00:00, null, null, f, null, f, XYZAssignment, null, null, null, null).
********** Error **********
ERROR: null value in column "id" violates not-null constraint
SQL state: 23502
Detail: Failing row contains (null, 1, 1, null, null, null, 2016-03-09 09:24:12.841891, 2012-12-31 23:00:00, 2012-12-31 23:00:00, null, null, f, null, f, XYZAssignment, null, null, null, null).
When I try to create the record using factory_girl:
#assignment = FactoryGirl.create(:assignment)
It builds this sql query:
INSERT INTO assignments(
id, account_id, l_id, viewed_at, accepted_at, declined_at,
expires_at, created_at, updated_at, decline_reason, decline_reason_text,
promotion, c_checked_at, forwardable, type, f_promo,
c_check_successful, c_check_api_result, c_check_human_result)
VALUES (null, 1, 1, null, null, null, '2016-03-09 09:24:12.841891', '2012-12-31 23:00:00', '2012-12-31 23:00:00', null, null, 'f', null, 'f', 'XYZAssignment', null, null, null, null);
This is the assignment factory:
FactoryGirl.define do
factory :assignment do
expires_at 24.hours.from_now
account
lead
end
end
this is the table description:
CREATE TABLE assignments(
id serial NOT NULL, account_id integer NOT NULL, l_id integer NOT NULL, viewed_at timestamp without time zone, accepted_at timestamp without time zone, declined_at timestamp without time zone, expires_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, decline_reason character varying(16), decline_reason_text character varying(256), promotion boolean NOT NULL DEFAULT false, c_checked_at timestamp without time zone, forwardable boolean DEFAULT true, type character varying(64), f_promo boolean, c_check_successful boolean, c_check_api_result character varying(32), c_check_human_result character varying(32), CONSTRAINT assignments_pkey PRIMARY KEY (id)
) WITH (
OIDS=FALSE
);
Looks its not able to auto increment the id, any idea?
You have to skip id in the INSERT operation:
INSERT INTO assignments(account_id, l_id, ...)
VALUES
(1, 1, ...)
The id will automatically get the next sequence number, since it is an auto-increment field.

Flyway: Relation does not exist

ERROR: relation "signature_level" does not exist
I'm having trouble figuring out what's the problem. Flyway is throwing me this error when migrating.
CREATE TABLE IF NOT EXISTS "user" (
id SERIAL NOT NULL PRIMARY KEY,
name text NOT NULL,
id_code numeric NOT NULL,
email text NOT NULL,
address text,
alt_contact_relation text NULL,
alt_contact_phone numeric NULL,
signature_level_id integer NULL,
username text NOT NULL,
password text NOT NULL,
create_time TIMESTAMP without TIME ZONE DEFAULT now() NOT NULL,
update_time TIMESTAMP without TIME ZONE DEFAULT now() NOT NULL,
status active_status NOT NULL DEFAULT 'active',
work_detail_id integer NULL,
CONSTRAINT FK_user_signature_level FOREIGN KEY (signature_level_id) REFERENCES signature_level (id)
ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_user_work_detail FOREIGN KEY (work_detail_id) REFERENCES work_detail (id)
ON DELETE NO ACTION ON UPDATE NO ACTION
);
This is the signature level table.
CREATE TABLE IF NOT EXISTS "signature_level" (
id SERIAL NOT NULL PRIMARY KEY,
name text NOT NULL,
create_time TIMESTAMP without TIME ZONE DEFAULT now() NOT NULL,
update_time TIMESTAMP without TIME ZONE DEFAULT now() NOT NULL
);

Postgresql RAISE EXCEPTION when operation get 0 or less in Update

I have three tables:
CREATE TABLE public.art_movimientos
(
cmovimiento bigint NOT NULL DEFAULT nextval('art_movimientos_cmovimiento_seq'::regclass),
tipo character varying(3) NOT NULL, -- Tipos de Valores:...
fecha_mov timestamp without time zone NOT NULL,
documento integer NOT NULL,
control integer,
fecha_doc timestamp without time zone NOT NULL,
corden integer NOT NULL DEFAULT 0,
calmacen integer NOT NULL,
calmacen2 integer,
status character varying(13) NOT NULL DEFAULT 'PENDIENTE'::bpchar, -- PENDIENTE...
donado integer NOT NULL DEFAULT 0,
monto_mov numeric(11,2) NOT NULL DEFAULT 0.00,
monto_desc numeric(11,2) NOT NULL DEFAULT 0.00,
monto_total numeric(11,2) NOT NULL DEFAULT 0.00,
observacion text,
casiento integer,
crea_user character varying(25),
crea_date timestamp without time zone,
mod_user character varying(25),
mod_date timestamp without time zone,
cproveedor integer NOT NULL DEFAULT 0
)
CREATE TABLE public.art_movimientos_det
(
cmovimiento_det bigint NOT NULL DEFAULT nextval('art_movimientos_det_cmovimiento_det_seq'::regclass),
cmovimiento integer NOT NULL,
cart_generico integer NOT NULL,
cunidad integer NOT NULL DEFAULT 1,
cant numeric(11,2) NOT NULL DEFAULT 0.00,
iva numeric(11,2) NOT NULL DEFAULT 0.00,
costou numeric(11,2) NOT NULL DEFAULT 0.00,
crea_user character varying(25),
crea_date timestamp without time zone,
mod_user character varying(25),
mod_date timestamp without time zone,
cart_comercial integer NOT NULL,
costot numeric(11,2) NOT NULL DEFAULT 0.00
)
CREATE TABLE public.ordencompra_det
(
corden_det bigint NOT NULL DEFAULT nextval('ordencompra_det_corden_det_seq'::regclass),
corden integer NOT NULL,
cart_comercial integer NOT NULL,
cunidad integer NOT NULL DEFAULT 1,
cant numeric(11,2) NOT NULL DEFAULT 0.00,
costou numeric(11,2) NOT NULL DEFAULT 0.00,
iva numeric(11,0) NOT NULL DEFAULT 0.00,
costot numeric(11,2) NOT NULL DEFAULT 0.00,
crea_user character varying(25),
crea_date timestamp without time zone,
mod_user character varying(25),
mod_date timestamp without time zone,
cant_restante numeric(11,2) NOT NULL DEFAULT 0
)
I have a procedure that reduce the cant_restante in ordencompra_det:
UPDATE ordencompra_det AS od
SET cant_restante = cant_restante - s.cant_real
FROM (SELECT am.corden, md.cart_comercial,(md.cant*u.multiplicador)cant_real FROM art_movimientos am INNER JOIN art_movimientos_det md ON am.cmovimiento=md.cmovimiento INNER JOIN art_und u ON md.cunidad=u.cunidad WHERE md.cmovimiento=cmov) AS s
WHERE od.corden=s.corden and od.cart_comercial=s.cart_comercial
But sometimes i get 0 or less in cant_restante, how i can do a check, if the update result below 0 ? i don't wanna have negative values "/, if i get negatives values, rollback the Update and raise a exception?
I'm using postgresql function (procedure) for it (because I'm doing a lot stuffs in the DB)
There are more possibilities:
use table constraint:
CREATE TABLE ordencompra_det(
...
cant_restante numeric(11,2) NOT NULL DEFAULT 0 CHECK(can_restante >= 0),
...
)
Use a check function:
CREATE OR REPLACE FUNCTION only_positive(numeric)
RETURNS numeric AS $$
BEGIN
IF $1 < 0 THEN
RAISE EXCEPTION '%s is not positive', $1;
END IF;
RETURN $1;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;
UPDATE ordencompra_det
SET cant_restante = only_positive(cant_restante - s.cant_real)
...
The first way should be preferred.