-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [Postgre] updateBatch() breaks char
type data
#8524
fix: [Postgre] updateBatch() breaks char
type data
#8524
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good.
One other option - though I don' t know that it would be any better would be to change CHARACTER into CHARACTER VARYING in the cast method. The only reason is that it would keep the getFieldType() method more 'pure' in a sense. But I'm not sure this would be any better.
You could change to CHARACTER | CHAR TO VARCHAR in the cast() method. This should cover the other DBMS too. https://onecompiler.com/postgresql/423ynm2e2 CREATE TABLE test_table
(
id integer,
char char(10),
varchar varchar(10)
);
INSERT INTO test_table (id, char, varchar) VALUES (1, 'foo', 'foo');
INSERT INTO test_table (id, char, varchar) VALUES (2, 'bar', 'bar');
INSERT INTO test_table (id, char, varchar) VALUES (3, 'baz', 'baz');
UPDATE "test_table"
SET "char" = CAST(_u."char" AS VARCHAR),
"varchar" = CAST(_u."varchar" AS CHARACTER VARYING)
FROM (SELECT 'Foo' "char", 1 "id", 'Foo' "varchar"
UNION ALL
SELECT 'Bar' "char", 2 "id", 'Bar' "varchar"
UNION ALL
SELECT 'Baz' "char", 3 "id", 'Baz' "varchar") _u
WHERE "test_table"."id" = CAST(_u."id" AS INTEGER);
SELECT * FROM test_table; private function cast($expression, ?string $type): string
{
if (strtoupper($type) === 'CHAR' || strtoupper($type) === 'CHARACTER') {
$type = 'VARCHAR';
}
return ($type === null) ? $expression : 'CAST(' . $expression . ' AS ' . strtoupper($type) . ')';
} |
@sclubricants Thank you for the review! If Anyway, the method is only for Postgre, and it will override even if the parent class has the method. |
CHAR = CHARACTER Anyways, looks good |
SELECT CAST('STRING' AS VARCHAR) AS TEST; This runs on postgre but not on mysql |
Description
Follow-up #8439
From https://forum.codeigniter.com/showthread.php?tid=89336
Checklist: